forked from gobindadas/rhhi-perf-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_workload.sh
executable file
·287 lines (230 loc) · 5.82 KB
/
run_workload.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
#!/usr/bin/bash
# Requires
# nmap-ncat
# Assumptions for the run;
# 1) all vm's are started
# default filenames used by the script
FIO_TEMPFILE=$(mktemp)
FIO_PORT=8765
declare -a CLIENT
declare -a HOST
# run modes
MODES[0]="stepped"
MODES[1]="immediate"
function timestamp {
now=$(date +%H:%M:%S)
echo $now
}
function fio_OK {
# 0 .. OK
# 1 .. Not OK
local rc=0
local client
local port_open=0
echo -e "\n$(timestamp) Checking fio daemon is accessible on each client"
# Process the client list, and check FIO_PORT is open on each one
for client in "${CLIENT[@]}"; do
port_open=$(nc $client $FIO_PORT < /dev/null &> /dev/null; echo $?)
if [ $port_open -gt 0 ]; then
echo "- fio daemon on '${client}' is not accessible"
rc=1
else
echo "- fio daemon on '${client}' is OK"
fi
done
return $rc
}
function drop_page_cache {
:
local delay_secs=10
echo "$(timestamp) flushing page cache across each gluster node"
for host in "${HOST[@]}"; do
$CMD_PFX ssh -n root@$host 'echo 3 > /proc/sys/vm/drop_caches && sync'
done
echo "$(timestamp) waiting ${delay_secs} secs"
$CMD_PFX sleep ${delay_secs}
}
function run_fio {
local -a vm_names=("${!1}")
local num_vms=${#vm_names[@]}
local num_vms_fmtd=$(printf "%03d" $num_vms)
local output_file=${JOBNAME}_${TARGET}_${num_vms_fmtd}_json.out
local client_string=""
for vm in "${vm_names[@]}"; do
client_string="$client_string --client=${vm}"
done
echo "$(timestamp) running fio stream for ${num_vms} concurrent clients"
$CMD_PFX fio ${client_string} --output=${output_file} --output-format=json ${OUTDIR}/fio.job
echo "$(timestamp) output written to ${output_file}"
if [ "$GETSTATS" ]; then
:
get_vol_profile $num_vms_fmtd $JOBNAME
vol_profile clear
fi
}
function process_clients {
echo -e "\n$(timestamp) Execution starting;"
local client
case $FIO_CLIENT_MODE in
stepped)
declare -a client_list
for client in ${CLIENT[@]}; do
client_list+=($client)
drop_page_cache
run_fio client_list[@]
done
;;
immediate)
drop_page_cache
run_fio CLIENT[@]
;;
esac
}
function build_clients {
:
read -a CLIENT <<< $(cat $CFG_FILE | python -c "import yaml,sys; cfg=yaml.load(sys.stdin); print ' '.join(cfg['clients'])")
}
function build_hosts {
:
read -a HOST <<< $(cat $CFG_FILE | python -c "import yaml,sys; cfg=yaml.load(sys.stdin); print ' '.join(cfg['hosts'])")
}
function update_fio_job {
# passed variable to update, and the value
case "$1" in
iodepth|numjobs|runtime)
if grep -q ${1} "$FIO_TEMPFILE" ; then
sed -i "s/${1}=.*/${1}=${2}/" $FIO_TEMPFILE
echo " - ${1} override applied (changed to ${2})"
fi
;;
*)
echo "Unknown update option for fio job file"
exit 16
;;
esac
}
function main {
:
# build list of the hosts in the cluster from control file
build_hosts
# populate the CLIENTS array from the 'job_sequence' file
build_clients
# fio daemon on every client specified MUST be accessible - if not abort
if ! fio_OK ; then
echo -e "Run aborted, unable to continue.\n"
exit 16
fi
cp -f ${JOBNAME} ${FIO_TEMPFILE}
echo -e "\nSettings for this run;"
echo " - configuration file used is '${CFG_FILE}'"
echo " - ${#CLIENT[@]} client(s) listed"
echo " - ${#HOST[@]} host(s) listed"
echo " - gluster commands routed through ${HOST[0]}"
echo " - fio jobfile called ${JOBNAME}"
echo " - gluster volume '${TARGET}'"
echo " - run mode is '${FIO_CLIENT_MODE}'"
echo " - output files will be written to '${OUTDIR}'"
if [ "${QDEPTH}" ]; then
update_fio_job 'iodepth' ${QDEPTH}
fi
if [ "${NUMJOBS}" ]; then
update_fio_job 'numjobs' ${NUMJOBS}
fi
if [ "${RUNTIME}" ]; then
update_fio_job 'runtime' ${RUNTIME}
fi
cp -f ${FIO_TEMPFILE} ${OUTDIR}/fio.job
if [ "$GETSTATS" ]; then
vol_profile on
else
echo " - gluster stats NOT being captured for this run"
fi
process_clients
echo -e "\nremoving temporary fio job file"
rm -f $FIO_TEMPFILE
echo "moving output files to ${OUTDIR}"
mv ${JOBNAME}_${TARGET}_*_json.out ${OUTDIR}/.
echo "$(timestamp) Run sequence complete"
}
while getopts ":j:dst:m:f:q:n:r:o:h" opt; do
case $opt in
j)
JOBNAME=$OPTARG
;;
s)
GETSTATS=true
;;
h)
usage
exit 0
;;
f)
CFG_FILE=$OPTARG
;;
m)
FIO_CLIENT_MODE=$OPTARG
# confirm the mode is valid
if ! [[ ${MODES[@]} =~ "$FIO_CLIENT_MODE" ]]; then
echo "-> Error, invalid run mode (-m), choose one of the following: ${MODES[@]}"
exit 16
fi
;;
t)
TARGET=$OPTARG
;;
q)
QDEPTH=$OPTARG
;;
r)
RUNTIME=$OPTARG
;;
n)
NUMJOBS=$OPTARG
;;
o)
OUTDIR=$OPTARG
;;
d)
DEBUG=true
;;
\?)
echo "Invalid option"
exit 16
;;
esac
done
if ! [ -e "$CFG_FILE" ]; then
echo "-> Error, config filename provided not found (specify full path?)"
exit 16
fi
if [ -z "${OUTDIR}" ]; then
OUTDIR=$(pwd)/output
echo "-> using default output directory of '${OUTDIR}'"
if ! [ -d "$OUTDIR" ]; then
echo " - creating new dir '${OUTDIR}'"
mkdir ${OUTDIR}
fi
else
if ! [ -d "$OUTDIR" ]; then
echo "-> Error, output directory must exist prior to the run"
exit 16
fi
fi
if [ -z "${JOBNAME}" ] || [ -z "${TARGET}" ]; then
echo "job name and target volume must be supplied"
exit 12
#else
# if [ ! -e "$JOBNAME" ]; then
# echo "Job name given but file does not exist"
# exit 12
# fi
fi
if [ -z "${FIO_CLIENT_MODE}" ]; then
FIO_CLIENT_MODE=${MODES[0]}
fi
if [ "$DEBUG" ]; then
CMD_PFX="echo DEBUG -->"
else
CMD_PFX=""
fi
main