-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunit.sh
executable file
·383 lines (306 loc) · 8.58 KB
/
runit.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
# DISCLAIMER OF WARRANTIES AND LIMITATION OF LIABILITY
# The software is supplied "as is" and all use is at your own risk. Peak Performance Systems disclaims
# all warranties of any kind, either express or implied, as to the software, including, but not limited to,
# implied warranties of fitness for a particular purpose, merchantability or non - infringement of proprietary
# rights. Neither this agreement nor any documentation furnished under it is intended to express or imply
# any warranty that the operation of the software will be uninterrupted, timely, or error - free. Under no
# circumstances shall Peak Performance Systems be liable to any user for direct, indirect, incidental,
# consequential, special, or exemplary damages, arising from or relating to this agreement, the software, or
# user#s use or misuse of the softwares. Such limitation of liability shall apply whether the damages arise
# from the use or misuse of the software (including such damages incurred by third parties), or errors of
# the software.
function msg() {
local type="$1"
local msg="$2"
local now=$(date +"%Y.%m.%d-%H:%M:%S")
echo "${type} : ${now} : ${msg}"
}
function test_conn() {
local constring="$*"
local ret=""
local outfile=/tmp/.${$}.${RANDOM}
mysql $constring -e 'SELECT version();' > $outfile 2>&1
ret=$?
if [ $ret -ne 0 ]
then
msg FATAL "Instance connectivity check failed. mysql output:"
cat $outfile
fi
rm -f $outfile
return $ret
}
function count_pids() {
local pidfile=$1
local numpids=0
ps -p `cat $pidfile` | wc -l
return 0
}
function wait_pids() {
local sessions=$1
local run_time=$2
local wl="$3"
local pids="$4"
local sleeptm=$(( run_time - 3 ))
local cnt=0
local monitor_limit=0
local x=0
local tmp=""
local pid_file="/tmp/${RANDOM}_slob.pids.out"
echo "$pids" > $pid_file 2>&1
if [ "$wl" -eq 0 ]
then
msg NOTIFY "List of monitored mysql PIDs written to $pid_file"
monitor_limit=300
sleep 5
tmp=`count_pids $pid_file`
if [ $tmp -lt $sessions ]
then
msg FATAL "SLOB process monitoring discovered $(( sessions - tmp )) mysql processes have aborted."
msg FATAL "Consider export SLOB_DEBUG=TRUE, re-running the test and then examine slob_debug.out"
rm -f $pid_file
return 1
fi
msg NOTIFY "Waiting for $(( sleeptm - 5 )) seconds before monitoring running processes (for exit)."
sleep $(( sleeptm - 5 ))
else
msg NOTIFY "This is a fixed-iteration run (see slob.conf->WORK_LOOP). "
monitor_limit=0
fi
msg NOTIFY "Entering process monitoring loop."
while ( ps -p $pids > /dev/null 2>&1 )
do
if [ "$monitor_limit" -ne 0 ]
then
if [ "$cnt" -gt $monitor_limit ]
then
msg FATAL "The following mysql processes have not exited after $monitor_limit seconds."
ps -fp $pids
return 1
fi
fi
(( cnt = $cnt + 1 ))
(( x = $cnt % 10 ))
if [ $x = 0 ]
then
tmp=`count_pids $pid_file`
msg NOTIFY "There are $tmp mysql processes remaining."
fi
sleep 1
done
rm -f $pid_file
return 0
}
function check_bom() {
local file=""
if [ ! -f ./misc/BOM ]
then
#echo "FATAL: ${0}: ${FUNCNAME}: No BOM file in ./misc. Incorrect SLOB file contents or wrong PWD."
msg FATAL "No BOM file in ./misc. Incorrect SLOB file contents or wrong PWD."
return 1
fi
for file in `cat ./misc/BOM | xargs echo`
do
if [ ! -f "$file" ]
then
#echo "FATAL: ${0}: ${FUNCNAME}: Missing ${file}. Incorrect SLOB file contents."
msg FATAL "Missing ${file}. Incorrect SLOB directory contents."
return 1
fi
done
return 0
}
#---------- Main body
if [[ "$#" != 1 || "$1" < 1 ]]
then
msg FATAL
msg FATAL "${0}: Usage : ${0} <number of sessions to execute>"
msg FATAL "SLOB abnormal end."
exit 1
else
sessions=$1
fi
SLOB_DEBUG=TRUE
if [ "$SLOB_DEBUG" = "TRUE" ]
then
export debug_outfile="slob_debug.out"
msg NOTIFY "Debug info being sent to $debug_outfile "
else
export debug_outfile="/dev/null"
fi
if ( ! check_bom )
then
msg FATAL "PWD does not have correct SLOB kit contents."
msg FATAL "SLOB abnormal end."
exit 1
fi
if [ ! -x ./mywait ]
then
msg FATAL " "
msg FATAL "./mywait executable not found or wrong permissions."
msg FATAL "Please change directories to ./wait_kit and run make(1)."
msg FATAL " "
msg FATAL "SLOB abnormal end."
exit 1
fi
if ( ! type mysql >> $debug_outfile 2>&1 )
then
msg FATAL "mysql is not executable in $PATH"
msg FATAL "SLOB abnormal end."
exit 1
fi
rm -f iostat.out vmstat.out mpstat.out slob_debug.out mystat.out *_slob.pids.out
# Just in case user deleted lines in slob.conf:
UPDATE_PCT=${UPDATE_PCT:=25}
RUN_TIME=${RUN_TIME:=300}
WORK_LOOP=${WORK_LOOP:=0}
SCALE=${SCALE:=10000}
WORK_UNIT=${WORK_UNIT:=256}
REDO_STRESS=${REDO_STRESS:=LITE}
SHARED_DATA_MODULUS=${SHARED_DATA_MODULUS:=0}
DO_UPDATE_HOTSPOT=${DO_UPDATE_HOTSPOT:=FALSE}
HOTSPOT_PCT=${HOTSPOT_PCT:=10}
THINK_TM_MODULUS=${THINK_TM_MODULUS:=0}
THINK_TM_MIN=${THINK_TM_MIN:=.1}
THINK_TM_MAX=${THINK_TM_MAX:=.5}
MYSQL_ROOT_PWD=${MYSQL_ROOT_PWD:=""}
MYSQL_HOST=${MYSQL_HOST:=""}
MYSQL_PORT=${MYSQL_PORT:=""}
source ./slob.conf
mysql_pids=""
misc_pids=""
before=""
tm=""
cmd=""
nt=0
slobargs=""
sleep_secs=""
cnt=1
x=0
instance=1
sessions_per_instance=0
conn_string=""
if [ ! -z "${MYSQL_HOST}" ]
then
conn_string="-h ${MYSQL_HOST}"
fi
if [ ! -z "${MYSQL_PORT}" ]
then
conn_string="${conn_string} -P ${MYSQL_PORT}"
fi
export admin_connect_string="-uroot -p${MYSQL_ROOT_PWD} ${conn_string}"
export non_admin_connect_string="${conn_string}"
if [ ! -f ./misc/mystat_slob.pl ]
then
msg WARNING "No mystat_slob.pl file in ./misc."
MYSTAT_SLOB=FALSE
return 1
else
MYSTAT_SLOB=TRUE
fi
# The following is the first screen output
msg NOTIFY " "
msg NOTIFY "Conducting SLOB pre-test checks."
echo "NOTIFY:
UPDATE_PCT == $UPDATE_PCT
RUN_TIME == $RUN_TIME
WORK_LOOP == $WORK_LOOP
SCALE == $SCALE
WORK_UNIT == $WORK_UNIT
REDO_STRESS == $REDO_STRESS
admin_connect_string == \"$admin_connect_string\"
non_admin_connect_string == \"$non_admin_connect_string\"
"
msg NOTIFY "Verifying connectivity."
msg NOTIFY "Testing mysql connectivity to validate slob.conf settings."
if ( ! test_conn ${admin_connect_string} )
then
msg FATAL "${0}: cannot connect to mysql."
msg FATAL "Connect string: mysql \"${admin_connect_string}\""
msg FATAL "Please verify the root password in slob.conf are correct for your connectivity model."
msg FATAL "SLOB abnormal end."
exit 1
fi
for U in 1 ${sessions}
do
msg NOTIFY "Testing connectivity for user${U}"
if ( ! test_conn "-uuser${U} -puser${U} ${non_admin_connect_string}" )
then
msg FATAL "Connect failure mysql -uuser${U} -puser${U}"
msg FATAL "SLOB abnormal end."
exit 1
fi
done
msg NOTIFY "Connectivity verified."
msg NOTIFY "Setting up trigger mechanism."
./create_sem > /dev/null 2>&1
if [ ! -n "$NO_OS_PERF_DATA" ]
then
msg NOTIFY "Running iostat, vmstat and mpstat on current host--in background."
( iostat -xm 3 > iostat.out 2>&1 ) &
misc_pids="${misc_pids} $!"
( vmstat 3 > vmstat.out 2>&1 ) &
misc_pids="${misc_pids} $!"
( mpstat -P ALL 3 > mpstat.out 2>&1) &
misc_pids="${misc_pids} $!"
fi
msg NOTIFY "Connecting ${sessions} sessions ..."
#
# Launch the sessions
#
cnt=1 ; x=0 ; instance=1 ; sessions_per_instance=0
until [ $cnt -gt $sessions ]
do
cmd="mysql -uuser${cnt} -puser${cnt} ${non_admin_connect_string}"
slobargs="system ./mywait; use user${cnt}; call slob($UPDATE_PCT, $WORK_LOOP, $RUN_TIME, $SCALE, $WORK_UNIT, '$REDO_STRESS', $SHARED_DATA_MODULUS, $DO_UPDATE_HOTSPOT, $HOTSPOT_PCT, $THINK_TM_MODULUS, $THINK_TM_MIN, $THINK_TM_MAX)"
( $cmd -e "$slobargs" >> $debug_outfile 2>&1 ) &
mysql_pids="${mysql_pids} $!"
(( cnt = $cnt + 1 ))
(( x = $cnt % 17 ))
[[ $x -eq 0 ]] && sleep 1
done
if [ "$MYSTAT_SLOB" = "TRUE" ]
then
cd misc
./create_sem > /dev/null 2>&1
perl ./mystat_slob.pl -i 60 -n all -h 127.0.0.1 -u user1 -p user1 > ../mystat.out 2>/tmp/mystat_debug.out &
cd ..
fi
msg NOTIFY " "
if [[ $(( cnt / 6 )) -gt 5 ]]
then
sleep_secs=5
else
(( sleep_secs = $cnt / 6 ))
fi
if [ "$sleep_secs" -gt 1 ]
then
msg NOTIFY "Pausing for $sleep_secs seconds before triggering the test."
sleep $sleep_secs
else
sleep 1
fi
# Switch output to fd2 so $misc_pids shell kill feedback falls in line
msg NOTIFY " "
msg NOTIFY "Triggering the test." >&2
before=$SECONDS
./trigger > /dev/null 2>&1
if ( ! wait_pids "$sessions" "$RUN_TIME" "$WORK_LOOP" "$mysql_pids" )
then
msg FATAL "This is not a successful SLOB test." >&2
exit 1
fi
(( tm = $SECONDS - $before ))
msg NOTIFY "Run time in seconds was: $tm" >&2
echo "Tm $tm" > tm.out
if [ "$MYSTAT_SLOB" = "TRUE" ]
then
cd misc
./trigger > /dev/null 2>&1
cd ..
fi
sleep 1
msg NOTIFY "Terminating background data collectors." >&2
/bin/kill -9 $misc_pids > /dev/null 2>&1
wait
exit 0