Add a http performance test script based on wrk
[iec.git] / src / tools / wrk_test.sh
1 #!/bin/bash
2
3 set -e
4
5 accessNum=$((aNum + 0))
6 START=1
7 END=5
8
9 urlIP=${1:-172.26.12.101}
10 urlPort=${2:-30942}
11  
12
13 IFS_OLD=$IFS
14 IFS=$'\n'
15
16
17 runCmd(){
18
19 for (( c=$START; c<=$END; c++))
20 do
21     
22     #curl -w "%{time_total}\n" -o /dev/null -s http://$svcIP
23     cmd=$1
24     echo "Round:"$c"--"$cmd
25     output=$(eval $cmd)
26     #echo $output
27     for line in  $output
28     do
29       #echo "${line}"
30       result=$(echo ${line} | grep "Latency") || true
31       #echo $result
32       if [ "aaa${result}" != "aaa" ]; then
33          latency[$c]=$(echo $result | awk '{print $2}')
34       fi
35       sleep 0.1
36       result=$(echo ${line} | grep "Requests/sec") || true
37       if [ "aaa${result}" != "aaa" ]; then
38          requests[$c]=$(echo $result | awk '{print $2}')
39       fi
40       sleep 0.1
41       result=$(echo ${line} | grep "Transfer/sec") || true
42       if [ "aaa${result}" != "aaa" ]; then
43          transfer[$c]=$(echo $result | awk '{print $2}')
44       fi
45       sleep 0.1
46     done
47
48 done 
49
50 echo "Latency:"
51 for (( c=$START; c<=$END; c++))
52 do
53    echo ${latency[$c]}
54 done
55
56
57 echo "requests/sec:"
58 for (( c=$START; c<=$END; c++))
59 do
60    echo ${requests[$c]}
61 done
62
63
64 echo "Transfer/sec:"
65 for (( c=$START; c<=$END; c++))
66 do
67    echo ${transfer[$c]}
68 done
69
70 }
71
72 runCmd "/usr/bin/wrk -t12 -c400 -d30s http://${urlIP}:${urlPort}"
73 runCmd "/usr/bin/wrk -t12 -c400 -d30s http://${urlIP}:${urlPort}/files/file-100K"
74 runCmd "/usr/bin/wrk -t12 -c400 -d30s http://${urlIP}:${urlPort}/files/file-1M"
75
76 IFS=$IFS_OLD