43. Elasticsearch custom script to complete performance test

1. ES performance test

Requirements: 
1) Complete 100 ES concurrent performance tests; 
2) Statistically obtain the access time result value.

2. Script implementation

#!/bin/sh

KEYWORDS_TXT="./keywords.txt"
cat /dev/null > ./rst.txt

echo "beginTime=`date`"

cat $KEYWORDS_TXT | while read line
do
echo "line=$line"
echo "curl -XGET http://100.10.11.130:9200/shx_info_index/shx_info_type/_search -d'
{
  \"query\" : {
  \"query_string\" : {
  \"default_field\" : \"company_name\",
  \"query\" : \"$line\"
  }
  }
}' >> ./rst.txt 2>&1 & " >> ./sql.txt

icnt=$((icnt+1));
echo "icnt ="$icnt;
done;

Interpretation: 
1) The above script implements the query operation for all fields; 
2) Each operation is read configuration; 
3) If the time to read the configuration is not avoided, the entire post request operation can be stored in another script first, Execute again.

2. Summary of technical core points

Core point one:

The purpose of &: to achieve concurrent testing, otherwise it is to execute tasks serially. 
The result can be exported and then executed.

Core point two:

The time difference is calculated as follows: 
1) Start time:

current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
beginTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #将current转换为时间戳,精确到毫秒
#echo "beginTime=$currentTimeStamp"
echo "beginTime=`date`"

2) End time and time difference (duration time):

wait
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
endTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #将current转换为时间戳,精确到毫秒
#echo "endTime=$currentTimeStamp"
echo "endTime=`date`"
timeSpan=`expr $endTimeStamp - $beginTimeStamp` #时间戳求差值。
echo "100次并发测试总耗时=$timeSpan 毫秒"

Core point three:

wait [job indication or process number]

1. Wait for the process specified by the job number or process number to exit, and return the exit status of the last job or process. If no argument is specified, waits for the exit of all child processes with an exit status of 0.

2. If wait is used in the shell, it will not wait for the subtask of the calling function. Using wait in the function will only wait for the background subtasks started in the function.

3. Using the wait command in the shell is equivalent to multi-thread synchronization in high-level languages.

May 15, 2017 23:48 at home in front of bed

Author: Mingyi Tianxia 
reproduced please indicate the source, the original address: 
http://blog.csdn.net/laoyang360/article/details/72231924 
If you feel that this article is helpful to you, please click 'top' to support, your support is I stick to the biggest motivation for writing, thank you!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325492926&siteId=291194637