forked from wso2/msf4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcecute-tests.sh
executable file
·248 lines (219 loc) · 6.64 KB
/
excecute-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
baseDir=$(dirname "$0")
concLevels="1 25 50 100 200 400 800 1600 3200"
perTestTime=30
testLoops=1000000
warmUpConc=200
warmUpLoop=50000
tmpDir="$baseDir/tmpData"
vendorsLoc="$baseDir/Samples"
payload="$baseDir/1kb_rand_data.txt"
timeStmp=$(date +%s)
types=()
declare -A MAP
function printResultStructures(){
echo "Printing types.."
for type in ${types[@]}
do
echo "$type"
done
echo ""
echo "Printing results map.."
for key in ${!MAP[@]}
do
echo "$key -> ${MAP[$key]}"
done
}
function hash(){
echo -n $1 | md5sum | awk '{print $1}'
}
function addNewType(){
local newType=$1
local isNew=true
local type=""
for type in ${types[@]}
do
if [ "$type" = "$newType" ]
then
isNew=false
break
fi
done
if "$isNew"
then
types+=($newType)
fi
}
function addNewVendor(){
local type=$1
local vendor=$2
if [ ${MAP["$type-vendor-n"]} ]
then
local vendorN=${MAP["$type-vendor-n"]}
MAP["$type-vendor-$vendorN"]="$vendor"
MAP["$type-vendor-n"]=$((vendorN+1))
else
MAP["$type-vendor-0"]="$vendor"
MAP["$type-vendor-n"]=1
fi
}
function processResults(){
local metric=$1
local resultsFile=$2
local type=""
local vendorI=0
local conc=""
rm -f "$resultsFile"
for type in "${types[@]}"
do
echo "Test: $type," >> "$resultsFile"
local isPrintH=true
for conc in $concLevels
do
local header=""
if "$isPrintH"
then
header="Concurrency"
fi
local line="$conc"
for vendorI in $(seq 0 $((MAP["$type-vendor-n"]-1)))
do
local vendor=${MAP["$type-vendor-$vendorI"]}
if "$isPrintH"
then
header+=", $vendor"
fi
local tps=${MAP["$type-$vendor-$conc-$metric"]}
line+=", $tps"
done
if "$isPrintH"
then
echo "$header" >> "$resultsFile"
isPrintH=false
fi
echo "$line" >> "$resultsFile"
done
echo "" >> "$resultsFile"
done
echo "==========================================="
echo " Results ($metric) "
echo "==========================================="
cat "$resultsFile"
}
function processPercentiles(){
local resultsFile=$1
local type=""
local vendorI=0
local conc=""
rm -f "$resultsFile"
local header="Vendor, Concurrency"
for hVal in $(seq 0 100)
do
header+=", $hVal"
done
for type in "${types[@]}"
do
echo "Test: $type," >> "$resultsFile"
for conc in $concLevels
do
local isPrintH=true
for vendorI in $(seq 0 $((MAP["$type-vendor-n"]-1)))
do
local vendor=${MAP["$type-vendor-$vendorI"]}
local percents=${MAP["$type-$vendor-$conc-percents"]}
if "$isPrintH"
then
echo "$header" >> "$resultsFile"
isPrintH=false
fi
echo "$percents" >> "$resultsFile"
done
echo "" >> "$resultsFile"
done
done
echo "==========================================="
echo " Results (Percentiles) "
echo "==========================================="
cat "$resultsFile"
}
function warmUp(){
local service=$1
echo "Warm up service $service"
ab -k -p "$payload" -c $warmUpConc -n $warmUpLoop -H "Accept:text/plain" "$service" > /dev/null
}
function testConcLevel(){
local service=$1
local concLevel=$2
local type=$3
local vendor=$4
local resOut="$tmpDir/result-$type-$vendor-conc$concLevel-rep$loopRep-loops$testLoops-time$timeStmp-$(uuidgen)"
local percentOut="$tmpDir/percentile-$type-$vendor-conc$concLevel-rep$loopRep-loops$testLoops-time$timeStmp-$(uuidgen)"
echo "Testing service: $service"
echo "Testing concurrency $concLevel at $resOut"
ab -t "$perTestTime" -n "$testLoops" -c "$concLevel" -H "Accept:text/plain" -p "$payload" -k -e "$percentOut" "$service" > "$resOut"
local tps=$(cat "$resOut" | grep -Eo "Requests per second.*" | grep -Eo "[0-9]+" | head -1)
local meanLat=$(cat "$resOut" | grep -Eo "Time per request.*\(mean\)" | grep -Eo "[0-9]+(\.[0-9]+)?")
local percents=$(cat "$percentOut" | grep -Eo ",.*" | grep -Eo "[0-9]+(\.[0-9]+)?" | tr '\n' ',')
percents="$vendor, $concLevel, $percents"
echo "For $service at concurrency $concLevel"
MAP["$type-$vendor-$concLevel-tps"]=$tps
echo -e "\tThroughput $tps"
MAP["$type-$vendor-$concLevel-meanLat"]=$meanLat
echo -e "\tMean latency is $meanLat"
MAP["$type-$vendor-$concLevel-percents"]=$percents
echo -e "\tPercentiles are $percents"
}
function iterateConcLevels(){
local vendorDir=$1
local type=$2
local vendor=$3
local service=$4
echo "Testing concurrency levels in $vendorDir"
warmUp "$service" # Warm up the service before getting results
local concLevel=""
for concLevel in $concLevels
do
testConcLevel "$service" "$concLevel" "$type" "$vendor"
done
}
function iterateVendors(){
local vendors=$(ls "$1")
local type=""
local vendor=""
for vendor in $vendors
do
local vendorDir="$1/$vendor"
if [ -f "$vendorDir/run.sh" ]
then
local startState=$($vendorDir/run.sh "start")
if [[ "$startState" = *"Server started"* ]]
then
echo "Server started in $vendorDir"
local endpoints=$($vendorDir/run.sh "endpoints")
endpoints=${endpoints//","/" "}
for endpoint in $endpoints
do
endpoint=(${endpoint//"->"/" "})
local type=${endpoint[0]}
local service=${endpoint[1]}
addNewType "$type"
addNewVendor "$type" "$vendor"
iterateConcLevels "$vendorDir" "$type" "$vendor" "$service"
done
$vendorDir/run.sh "stop"
else
echo "Server not started in $vendorDir"
fi
fi
done
processResults "tps" "$baseDir/results-tps.csv"
echo ""
processResults "meanLat" "$baseDir/results-latency.csv"
echo ""
processPercentiles "$baseDir/results-percentiles.csv"
echo ""
#printResultStructures
}
mkdir -p "$tmpDir"
base64 /dev/urandom | head -c 1024 > "$payload"
iterateVendors "$vendorsLoc"