This repository has been archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
run_acmeair.sh
executable file
·303 lines (257 loc) · 8.92 KB
/
run_acmeair.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
#shopt -s -o nounset
start=`date +%s`
#set locations so we don't end up with lots of hard coded bits throughout script
RESOURCE_DIR=$1
REL_DIR=$(dirname $0)
ROOT_DIR=`cd "${REL_DIR}/.."; pwd`
echo "ROOT_DIR=${ROOT_DIR}"
SCRIPT_DIR=${ROOT_DIR}/acmeair
ACMEAIR_DIR=${RESOURCE_DIR}/acmeair-nodejs
MONGO_DIR=${RESOURCE_DIR}/mongo3
#these may need changing when we find out more about the machine we're running on
NODE_AFFINITY="numactl --physcpubind=0,4"
MONGO_AFFINITY="numactl --physcpubind=1,5"
JMETER_AFFINITY="numactl --physcpubind=2,6"
function usage() {
echo "USAGE:"
echo "Currently this script will run acmeair, including mongodb and JMeter, with the affinities as follows:"
echo "Node : $(echo ${node_affinity})"
echo "Mongodb : $(echo ${mongo_affinity})"
echo "JMeter : $(echo ${jmeter_affinity})"
}
function mandatory() {
if [ -z "${!1}" ]; then
echo "${1} not set"
usage
exit
fi
}
function optional() {
if [ -z "${!1}" ]; then
echo -n "${1} not set (ok)"
if [ -n "${2}" ]; then
echo -n ", default is: ${2}"
export ${1}="${2}"
fi
echo ""
fi
}
function remove(){
if [ -f $1 ]; then
rm $1
fi
}
function archive_files() {
# archive files
echo -e "\n##BEGIN $TEST_NAME Archiving $(date)\n"
mv $LOGDIR_TEMP/$LOGDIR_PREFIX $RESULTSDIR
echo -e "Perf logs stored in $RESULTSDIR/$LOGDIR_PREFIX"
echo -e "\nCleaning up"
rm -r $LOGDIR_TEMP
echo -e "\n## END $TEST_NAME Archiving $(date)\n"
}
function kill_bkg_processes() # kill processes started in background
{
echo "Killing due to : $@"
$MONGODB_COMMAND "stop"
pkill node
pkill mongod
JAVA_PID="`ps -ef|grep java|grep -v grep|grep -v slave|awk {'print $2'}`"
kill -9 $JAVA_PID || true
pids=$(ps -eo pid,pgid | awk -v pid=$$ '$2==pid && $1!=pid {print $1}') # get list of all child/grandchild pids - this doesnt seem to work on nodejs benchmark machine....
echo "Killing background processes"
echo $pids
kill -9 $OTHERPID_LIST $pids || true # avoid failing if there is nothing to kill
}
function on_exit()
{
echo "Caught kill"
kill_bkg_processes "caught kill"
kill -9 $PID_LIST $OTHERPID_LIST
archive_files
exit 1
}
function timestamp()
{
date +"%Y%m%d-%H%M%S"
}
trap on_exit SIGINT SIGQUIT SIGTERM
# VARIABLE SECTION
# define variables
declare -rx SCRIPT=${0##*/}
TEST_NAME=acmeair
echo -e "\n## TEST: $TEST_NAME ##\n"
echo -e "## OPTIONS ##\n"
optional RESULTSDIR ${ROOT_DIR}/results
optional TIMEOUT 600
RESULTSLOG=$TEST_NAME.log
SUMLOG=score_summary.txt
optional DRIVERHOST
optional NODE_FILE app.js
optional CLUSTER_MODE false
optional PORT 4000
optional DRIVERCMD ${RESOURCE_DIR}/Jmeter/bin/jmeter
optional DRIVERNO 25
ACMEAIR_DRIVER_PATH=${SCRIPT_DIR}/jmeter_scripts
NODE_SERVER=$(hostname -s)
echo -e "RESULTSDIR: $RESULTSDIR"
echo -e "RESULTSLOG: $RESULTSLOG"
echo -e "TIMEOUT: $TIMEOUT"
echo -e "NODE_SERVER: $NODE_SERVER"
echo -e "PORT: $PORT"
echo -e "NETWORKTYPE: $NETWORKTYPE"
echo -e "DRIVERCMD: $DRIVERCMD"
echo -e "DRIVERNO: $DRIVERNO\n"
JMETER_LOGFILE=$ACMEAIR_DRIVER_PATH/jmeter.log
DRIVER_COMMAND="$JMETER_AFFINITY $DRIVERCMD -Jduration=240 -Jdrivers=$DRIVERNO -Jhost=$NODE_SERVER -Jport=$PORT -DusePureIDs=true -n -t $ACMEAIR_DRIVER_PATH/AcmeAir.jmx -p $ACMEAIR_DRIVER_PATH/acmeair.properties -l $JMETER_LOGFILE"
# END VARIABLE SECTION
# Date stamp for result files generated by this run
CUR_DATE=$(timestamp)
PLATFORM=`/bin/uname | cut -f1 -d_`
echo -e "Platform identified as: ${PLATFORM}\n"
case ${PLATFORM} in
Linux)
bash ${SCRIPT_DIR}/kill_node_linux
;;
esac
if [ -z $NODE ]; then
NODE=`which node`
fi
if [ -z "$NODE" ]; then
echo "ERROR: Could not find a 'node' executable. Please set the NODE environment variable or update the PATH."
echo "node is not here: $NODE"
exit 1
fi
echo -e "NODE VERSION:"
$NODE --version
# build command
CMD="$NODE_AFFINITY ${NODE} ${NODE_FILE}"
export LOGDIR_TEMP=$RESULTSDIR/temp
. ${SCRIPT_DIR}/fp.sh
case ${PLATFORM} in
Linux)
HPPRETOTAL=`cat /proc/meminfo | grep HugePages_Total | sed 's/HugePages.*: *//g' | head -n 1`
HPPREFREE=`cat /proc/meminfo | grep HugePages_Free | sed 's/HugePages.*: *//g' | head -n 2|tail -n 1`
let HPPREINUSE=$HPPRETOTAL-$HPPREFREE
echo "HP IN USE : " ${HPPREINUSE}
;;
esac
mkdir -p $LOGDIR_TEMP
DONEFILE_TEMP=$LOGDIR_TEMP/donefile.tmp
echo -e "\nDONE file: $DONEFILE_TEMP"
echo -n > $DONEFILE_TEMP
# start checking files in case things fall over before we get going
(while ! grep done $DONEFILE_TEMP &>/dev/null ; do
sleep 3
# Abort the run if an instance fails or if we time out
if grep fail $DONEFILE_TEMP &>/dev/null ; then
on_exit
fi
done
)&
LOOKFORDONE_PID=$!
# start time clock
( sleep $TIMEOUT; echo "TIMEOUT (${TIMEOUT}s)"; echo "fail" >> $DONEFILE_TEMP; ) &
TIMEOUT_PID=$!
TIMEOUT_CHILD=`pgrep -P $TIMEOUT_PID`
export OTHERPID_LIST="$OTHERPID_LIST $TIMEOUT_CHILD $TIMEOUT_PID $LOOKFORDONE_PID"
LOGDIR_PREFIX=$PRODUCT/$DATE/$CUR_DATE
SUMFILE=$LOGDIR_TEMP/$LOGDIR_PREFIX/$SUMLOG
STDOUT_SERVER=$LOGDIR_TEMP/$LOGDIR_PREFIX/server.out
STDOUT_CLIENT=$LOGDIR_TEMP/$LOGDIR_PREFIX/client.out
STDOUT_RESULTS=$LOGDIR_TEMP/$LOGDIR_PREFIX/jmeter.log
STDOUT_DB=$LOGDIR_TEMP/$LOGDIR_PREFIX/db.out
OUT_LIST="$OUT_LIST $LOGDIR_PREFIX/$SUMLOG $LOGDIR_PREFIX/server.out $LOGDIR_PREFIX/client.out $LOGDIR_PREFIX/db.out $LOGDIR_PREFIX/jmeter.log"
echo -e "\n*** SUMMARY FILE $SUMFILE ***\n"
echo -e "\n##START TEST INSTANCES $(date)\n"
echo
echo "*** BEGIN RUN ***"
LOGDIR_SHORT=$LOGDIR_PREFIX/$INSTANCES
LOGDIR_LONG=$LOGDIR_TEMP/$LOGDIR_SHORT
mkdir -p $LOGDIR_LONG
LOGFILE=$LOGDIR_LONG/$RESULTSLOG
rm -f $LOGFILE
OUT_LIST="$OUT_LIST $LOGDIR_SHORT/$RESULTSLOG"
echo "*** LOGFILE $LOGFILE ***"
# Start MongoDB
MONGODB_COMMAND="${MONGO_DIR}/mongodb.sh"
echo -e "\n## STARTING MONGODB ##" 2>&1 | tee -a $LOGFILE
echo -e " $MONGODB_COMMANDi start" | tee -a $LOGFILE
$MONGO_AFFINITY $MONGODB_COMMAND start
sleep 5 # give it a chance to start up
# Start the server(s)
echo -e "\n## SERVER COMMAND ##" 2>&1 | tee -a $LOGFILE
echo -e " $CPUAFFINITY $CMD" 2>&1 | tee -a $LOGFILE
echo -e "## BEGIN TEST ##\n" 2>&1 | tee -a $LOGFILE
(
pushd $ACMEAIR_DIR
$CPUAFFINITY $CMD > $STDOUT_SERVER 2>&1
echo -e "\n## Server no longer running ##"
echo "fail" >> $DONEFILE_TEMP
popd
) &
sleep 10 # give server some time to start up
echo "${SCRIPT_DIR}/loaddb.sh localhost ${PORT}"
${SCRIPT_DIR}/loaddb.sh localhost ${PORT}
sleep 5
pre=`getFootprint`
echo -n "Pre run Footprint in kb : $pre"
# Start the driver(s)
echo -e "\n## DRIVER COMMAND ##" 2>&1 | tee -a $LOGFILE
echo -e "$DRIVER_COMMAND"|tee -a $LOGFILE
(
if (exec $DRIVER_COMMAND > jmeter.log 2>&1 ) ; then
echo "Drivers have finished running" 2>&1 | tee -a $LOGFILE
echo "done" >> $DONEFILE_TEMP
echo "done" >> server_cpu.txt
else
echo "ERROR: driver failed or killed" 2>&1 | tee -a $LOGFILE
echo "fail" >> $DONEFILE_TEMP
fi
) &
sleep 2 #sometimes java takes a little longer to get going, so we miss cpu profile
remove server_cpu.txt
PIDS="`ps -ef|grep java|grep -v grep|grep -v slave|awk {'print $2'}`"
PIDS="$PIDS `ps -ef|grep mongod|grep -v grep|awk {'print $2'}`"
PIDS="$PIDS `ps -ef|grep node|grep -v grep|awk {'print $2'}`"
PIDS_COMMA=`echo $PIDS|sed 's/ /,/g'`
#print top output every 5 seconds 47 times = 48*5 - minus 1 measure so we don't end up with a low last number= 240 = length of jmeter run
SERVER_CPU_COMMAND="top -b -d 5 -n 47 -p $PIDS_COMMA"
$SERVER_CPU_COMMAND >> server_cpu.txt &
CPU_PID=$!
export OTHERPID_LIST="$OTHERPID_LIST $CPU_PID"
while ! grep done $DONEFILE_TEMP &>/dev/null ; do
sleep 3
# Abort the run if an instance fails or if we time out
if grep fail $DONEFILE_TEMP &>/dev/null ; then
on_exit
fi
done
post=`getFootprint`
echo -n "Runtime Footprint in kb : $post"
let difference=$post-pre
kill_bkg_processes "Should be finished"
echo -e "\n## END RUN ##"
for log in server
do
echo "sh $SCRIPT_DIR/cpuParse.sh ${log}_cpu.txt $log"
sh ${SCRIPT_DIR}/cpuParse.sh ${log}_cpu.txt $log
mv ${log}_cpu.txt $LOGDIR_TEMP/$LOGDIR_PREFIX
export OUT_LIST="$OUT_LIST $LOGDIR_PREFIX/${log}_cpu.txt"
done
# print output
echo -e "\n##BEGIN $TEST_NAME OUTPUT $(date)\n" 2>&1 | tee -a $SUMFILE
echo metric throughput $(cat $JMETER_LOGFILE | awk -f ${SCRIPT_DIR}/acmeair_score.awk) 2>&1 | tee -a $SUMFILE
echo metric latency $(cat $JMETER_LOGFILE | awk -f ${SCRIPT_DIR}/acmeair_latency.awk) 2>&1 | tee -a $SUMFILE
mv $JMETER_LOGFILE $LOGDIR_TEMP/$LOGDIR_PREFIX
export OUT_LIST="$OUT_LIST $LOGDIR_PREFIX/jmeter.log"
echo "metric pre footprint $pre"
echo "metric post footprint $post"
echo "metric footprint increase $difference"
echo -e "\n## TEST COMPLETE ##\n" 2>&1 | tee -a $SUMFILE
echo -e "\n## END $TEST_NAME OUTPUT $(date)\n\n" 2>&1 | tee -a $SUMFILE
end=`date +%s`
let elapsed=$end-$start
echo "Elapsed time : $elapsed"
archive_files