Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 101 lines (81 sloc) 3.268 kb
3090e7e benchmark test is added
Michael Lagutko authored
1 #!/bin/sh
2 echo '{"name":"Sherlock","email":"sherlock@email.com","country":"UK","city":"London","address":"Baker Street, 221B"}' > contact.txt
3
4 if [ -z $2 ]; then
5 echo "Usage: concurrency requests [expected rate]"
6 exit 1
7 fi
8
9 CONCURRENCY=$1
10 REQUESTS=$2
11 RATE=$3
12
13 if [ -z $RATE ]; then RATE=1000; fi;
14
15
16 function benchmark {
17 init
18 command=$1
19
20 echo -e '\E[37;44m'"\033[1mSTART BENCHMARK\033[0m"
21 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
22 echo -e '\E[37;44m'"\033[1m"$command"\033[0m"
23 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
24 eval $command
25
26 checkRate ab.txt
27 cleanUp
28 }
29
30 function cleanUp {
31 curl -X DELETE http://localhost:8585/contacts/Sherlock
32 }
33
34 function init {
35 ab -c 1 -n 1 -p contact.txt http://localhost:8585/contacts > tmp.txt
36 }
37
38 function checkRate {
39 tail -n 200 $1
40 rateLine=`grep "Requests" $1`
41 currentRate=`echo $rateLine|sed 's/.* \([[:digit:]]\{1,\}\).*/\1/'`
42 if [ $RATE -ge $currentRate ]; then
43
44 echo -e '\E[47;31m'"\033[1m*******************************************\033[0m"
4ce215f benchmark test is added
Michael Lagutko authored
45 echo -e '\E[47;31m'"\033[1mFAILED \033[0m"
3090e7e benchmark test is added
Michael Lagutko authored
46 echo -e '\E[47;31m'"\033[1mEXPECTED REQUESTS = "$RATE" \033[0m"
47 echo -e '\E[47;31m'"\033[1mACTUAL REQUESTS = "$currentRate" \033[0m"
48 echo -e '\E[47;31m'"\033[1m*******************************************\033[0m"
49 else
50 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
51 echo -e '\E[37;44m'"\033[1mSUCCESSFUL\033[0m"
52 echo -e '\E[37;44m'"\033[1mEXPECTED REQUESTS = "$RATE"\033[0m"
53 echo -e '\E[37;44m'"\033[1mACTUAL REQUESTS = "$currentRate"\033[0m"
54 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
55 fi
56 }
57
4ce215f benchmark test is added
Michael Lagutko authored
58 function checkMemory {
59 start=$(($1+1000))
60 end=$2
61 if [ $end -gt $start ]; then
62
63 echo -e '\E[47;31m'"\033[1m*******************************************\033[0m"
64 echo -e '\E[47;31m'"\033[1mMEMORY LEAK \033[0m"
65 echo -e '\E[47;31m'"\033[1mSTART MEMORY = "$1" \033[0m"
66 echo -e '\E[47;31m'"\033[1mEND MEMORY = "$end" \033[0m"
67 echo -e '\E[47;31m'"\033[1m*******************************************\033[0m"
68 else
69 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
70 echo -e '\E[37;44m'"\033[1mMEMORY IS OK\033[0m"
71 echo -e '\E[37;44m'"\033[1mSTART MEMORY = "$1"\033[0m"
72 echo -e '\E[37;44m'"\033[1mEND MEMORY = "$end"\033[0m"
73 echo -e '\E[37;44m'"\033[1m*******************************************\033[0m"
74 fi
75 }
76
77 function memoryUsage {
78 curl -X GET http://localhost:8585/blueeyes/server/health > health.txt
79 memoryLine=`grep "used" health.txt`
80 memory=`echo $memoryLine|sed 's/.*"used":\([[:digit:]]\{1,\}\).*/\1/'`
81 eval $1=$memory
82 }
83
84 startMemory=0
85 endMemory=0
86 memoryUsage startMemory
87
3090e7e benchmark test is added
Michael Lagutko authored
88 benchmark "ab -c $CONCURRENCY -n $REQUESTS -p contact.txt http://localhost:8585/contacts > ab.txt"
89 echo ""
90 echo ""
91 benchmark "ab -c $CONCURRENCY -n $REQUESTS http://localhost:8585/contacts > ab.txt"
92
4ce215f benchmark test is added
Michael Lagutko authored
93 memoryUsage endMemory
94 checkMemory $startMemory $endMemory
95
3090e7e benchmark test is added
Michael Lagutko authored
96 rm ab.txt
97 rm contact.txt
98 rm tmp.txt
4ce215f benchmark test is added
Michael Lagutko authored
99 rm health.txt
3090e7e benchmark test is added
Michael Lagutko authored
100
Something went wrong with that request. Please try again.