Whamcloud - gitweb
ac967debcd76e77d9b64a36c73f9d3dbdc442364
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / obdfilter-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # specify obd instances to exercise
7 # these can be either...
8 # obdfilter instances (set 'ost_names')
9 # ...or...
10 # echo_client instances (set 'client_names')
11 # ... use 'host:name' for obd instances on other nodes.
12
13 # allow these to be passed in via string...
14 ost_names_str=${ost_names_str:-""}
15 if [ -n "$ost_names_str" ]; then
16     declare -a ost_names
17     count=0
18     for name in $ost_names_str; do
19         ost_names[$count]=$name
20         count=$((count+1))
21     done
22 else
23     ost_names=(ost{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16})
24 fi
25
26 #client_names=(ns8:ECHO_ns8 ns9:ECHO_ns9)
27 client_names_str=${client_names_str:-""}
28 if [ -n "$client_names_str" ]; then
29     # make sure we unset ost_names so that our client_names get noticed... 
30     unset ost_names
31     declare -a client_names
32     count=0
33     for name in $client_names_str; do
34         client_names[$count]=$name
35         count=$((count+1))
36     done
37 fi
38
39 # result file prefix (date/time + hostname makes unique)
40 # NB ensure path to it exists
41 rslt=${rslt:-"/home_nfs/eeb/obdfilter_survey_`date +%F@%R`_`uname -n`"}
42
43 # lustre root (if running with own source tree)
44 lustre_root=${lustre_root:-"/home_nfs/eeb/lustre"}
45
46 # what tests to run (first must be write)
47 tests_str=${tests_str:-""}
48 if [ -n "$tests_str" ]; then
49     declare -a tests
50     count=0
51     for name in $tests_str; do
52         tests[$count]=$name
53         count=$((count+1))
54     done
55 else
56     #tests=(write rewrite read reread rewrite_again)
57     tests=(write rewrite read)
58 fi
59
60 # total size (MBytes) per obd instance
61 # large enough to avoid cache effects 
62 # and to make test startup/shutdown overhead insignificant
63 size=${size:-16384}
64
65 # record size (KBytes)
66 rszlo=${rszlo:-1024}
67 rszhi=${rszhi:-1024}
68
69 # number of objects per OST
70 nobjlo=${nobjlo:-1}
71 nobjhi=${nobjhi:-512}
72
73 # threads per OST (1024 max)
74 thrlo=${thrlo:-1}
75 thrhi=${thrhi:-64}
76
77 # restart from here iff all are defined
78 restart_rsz=
79 restart_thr=1
80 restart_nobj=1
81
82 # machine's page size (K)
83 PAGE_SIZE=${PAGE_SIZE:-16}
84
85 # max buffer_mem (total_threads * buffer size)
86 # (to avoid lctl ENOMEM problems)
87 max_buffer_mem=$((1024*1024))
88
89 # how to run commands on other nodes
90 # You need to make this work on your cluster if you have specified
91 # non-local obd instances above
92 custom_remote_shell () {
93     host=$1
94     shift
95     cmds="$*"
96     here=`pwd`
97     # Hop on to the remote node, chdir to 'here' and run the given
98     # commands. One of the following will probably work.
99     #ssh $host "cd $here; $cmds"
100     #rsh $host "cd $here; $cmds"
101     # we have to remove the leading `uname -n`: from pdsh output lines
102     pdsh -w $host "cd $here; $cmds" | sed 's/^[^:]*://'
103 }
104
105 #####################################################################
106 # leave the rest of this alone unless you know what you're doing...
107
108 # binaries
109 lsmod="/sbin/lsmod"
110 modprobe="/sbin/modprobe"
111 insmod="/sbin/insmod"
112 rmmod="/sbin/rmmod"
113
114 # lctl::test_brw bandwidth snapshot interval (seconds)
115 snap=1
116 # check file contents?
117 verify=1
118
119 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
120     echo "tests: ${tests[@]}"
121     echo "First test must be 'write'" 1>&2
122     exit 1
123 fi
124
125 rsltf="${rslt}.summary"
126 workf="${rslt}.detail"
127 cmdsf="${rslt}.script"
128 vmstatf="${rslt}.vmstat"
129 echo -n > $rsltf
130 echo -n > $workf
131
132 declare -a vmstatpids
133
134 # hide a little trick to unset this from the command line
135 if [ "$lustre_root" == " " ]; then
136     unset lustre_root
137 fi
138
139 if [ -z "$lustre_root" ]; then
140     lctl=$(which lctl)
141 else
142     lctl=${lustre_root}/utils/lctl
143 fi
144
145 remote_shell () {
146     host=$1
147     shift
148     cmds="$*"
149     if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
150         eval "$cmds"
151     else
152         custom_remote_shell $host "$cmds"
153     fi
154 }
155
156 obdecho_loaded() {
157     local host=$1
158     remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
159 }
160
161 load_obdecho () {
162     local host=$1
163     if [ -z "$lustre_root" ]; then
164         remote_shell $host $modprobe obdecho
165     elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
166         remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
167     else
168         remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
169     fi
170 }
171
172 unload_obdecho () {
173     local host=$1
174     remote_shell $host $rmmod obdecho
175 }
176
177 get_devno () {
178     local host=$1
179     local type=$2
180     local name=$3
181     remote_shell $host $lctl device_list | \
182         awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
183                   print \$1; exit}}"
184 }
185
186 get_ec_devno () {
187     local host=$1
188     local client_name="$2"
189     local ost_name="$3"
190     if [ -z "$client_name" ]; then
191         if [ -z "$ost_name" ]; then
192             echo "client and ost name both null" 1>&2
193             return
194         fi
195         client_name=${ost_name}_echo_client
196     fi
197     ec=`get_devno $host echo_client $client_name`
198     if [ -n "$ec" ]; then
199         echo $ec $client_name 0
200         return
201     fi
202     if [ -z "$ost_name" ]; then
203         echo "no echo client and ost_name not set" 1>&2
204         return
205     fi
206     ost=`get_devno $host obdfilter $ost_name`
207     if [ -z "$ost" ]; then
208         echo "OST $ost_name not setup" 1>&2
209         return
210     fi
211     remote_shell $host "$lctl <<EOF
212         attach echo_client $client_name ${client_name}_UUID
213 setup $ost_name
214 EOF"
215     ec=`get_devno $host echo_client $client_name`
216     if [ -z "$ec" ]; then
217         echo "Can't setup echo client" 1>&2
218         return
219     fi
220     echo $ec $client_name 1
221 }
222
223 teardown_ec_devno () {
224     local host=$1
225     local client_name=$2
226     remote_shell $host "$lctl <<EOF
227 cfg $client_name
228 cleanup
229 detach
230 EOF"
231 }
232
233 create_objects () {
234     # create a set of objects, check there are 'n' contiguous ones and
235     # return the first or 'ERROR'
236     local host=$1
237     local devno=$2
238     local nobj=$3
239     local rfile=$4
240     remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
241     first=0
242     prev=0
243     count=0
244     error=0
245     while read line; do
246         echo "$line" | grep -q 'is object id'
247         if [ $?  -ne 0 ]; then
248             continue
249         fi
250         if [ $first -eq 0 ]; then
251             first=$(echo $line | awk '{print $6}')
252             first=$(printf "%d" $first)
253             prev=$first
254             count=1
255         else
256             obj=$(echo $line | awk '{print $6}') 
257             obj=$(printf "%d" $obj) 
258             diff=$((obj - (prev+1))) 
259             if [ $diff -ne 0 ]; then 
260                 error=1 
261             fi 
262             prev=$obj 
263             count=$((count+1)) 
264         fi 
265     done < $rfile 
266     if [ $nobj -ne $count ]; then 
267         echo "ERROR: $nobj != $count" >&2 
268         cat $rfile >&2 
269         echo "ERROR" 
270     elif [ $error -ne 0 ]; then 
271         echo "ERROR: non contiguous objs found" >&2 
272         echo "ERROR" 
273     else 
274         echo $first 
275     fi
276 }
277
278 destroy_objects () {
279     local host=$1
280     local devno=$2
281     local obj0=$3
282     local nobj=$4
283     local rfile=$5
284     remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
285 }
286
287 get_stats () {
288     local rfile=$1
289     awk < $rfile \
290         '/^Selected device [0-9]+$/ {n = 0; next}\
291         /error/ {n = -1; exit}\
292         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {n++; v=strtonum($3); \
293                                                           if (n == 1 || v < min) min = v;\
294                                                           if (n == 1 || v > max) max = v;\
295                                                           next}\
296         {if (n != 0) {n = -1; exit}}\
297         END {printf "%d %f %f\n", n, min, max}'
298 }
299
300 get_global_stats () {
301     local rfile=$1
302     awk < $rfile 'BEGIN {n = 0;}\
303                   {n++; if (n == 1) {err = $1; min = $2; max = $3} else\
304                                     {if ($1 < err) err = $1;\
305                                      if ($2 < min) min = $2;\
306                                      if ($3 > max) max = $3}}\
307                   END {if (n == 0) err = 0;\
308                        printf "%d %f %f\n", err, min, max}'
309 }
310
311 testname2type () {
312     # 'x' disables data check
313     if ((verify)); then
314         x=""
315     else
316         x="x"
317     fi
318     case $1 in
319         *write*)  echo "w$x";;
320         *)        echo "r$x";;
321     esac
322 }
323
324 print_summary () {
325     if [ "$1" = "-n" ]; then
326         minusn=$1; shift
327     else
328         minusn=""
329     fi
330     echo $minusn "$*" >> $rsltf
331     echo $minusn "$*"
332 }
333
334 unique () {
335     echo "$@" | xargs -n1 echo | sort -u
336 }
337
338 split_hostname () {
339     local name=$1
340     case $name in
341     *:*) host=`echo $name | sed 's/:.*$//'`
342          name=`echo $name | sed 's/[^:]*://'`
343          ;;
344     *)   host=localhost
345          ;;
346     esac
347     echo "$host $name"
348 }
349
350 # split out hostnames from client/ost names
351 ndevs=${#client_names[@]}
352 if ((ndevs != 0)); then
353     if ((${#ost_names[@]} != 0)); then
354         echo "Please specify client_names or ost_names, but not both" 1>&2
355         exit 1
356     fi
357     for ((i=0; i<ndevs;i++)); do
358         str=(`split_hostname ${client_names[$i]}`)
359         host_names[$i]=${str[0]}
360         client_names[$i]=${str[1]}
361     done
362 else
363     ndevs=${#ost_names[@]}
364     if ((ndevs == 0)); then
365         echo "Please specify either client_names or ost_names" 1>&2
366         exit 1
367     fi
368     for ((i=0; i<ndevs;i++)); do
369         str=(`split_hostname ${ost_names[$i]}`)
370         host_names[$i]=${str[0]}
371         ost_names[$i]=${str[1]}
372     done
373 fi
374
375 # get vmstat started
376 # disable portals debug and get obdecho loaded on all relevant hosts
377 unique_hosts=(`unique ${host_names[@]}`)
378 pidcount=0
379 for host in ${unique_hosts[@]}; do
380     remote_shell $host "echo 0 > /proc/sys/portals/debug"
381     host_vmstatf=${vmstatf}_${host}
382     echo -n > $host_vmstatf
383     remote_shell $host "vmstat 5 >> $host_vmstatf" &
384     pid=$!
385     vmstatpids[$pidcount]=$pid
386     pidcount=$((pidcount+1))
387     do_unload_obdecho[$host]=0
388     if obdecho_loaded $host; then
389         continue
390     fi
391     load_obdecho $host
392     if obdecho_loaded $host; then
393         do_unload_obdecho[$host]=1
394         continue
395         fi
396     echo "Can't load obdecho on $host" 1>&2
397     exit 1
398 done
399
400 # get all the echo_client device numbers and names
401 for ((i=0; i<ndevs; i++)); do
402     host=${host_names[$i]}
403     devno=(`get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"`)
404     if ((${#devno[@]} != 3)); then
405         exit 1
406     fi
407     devnos[$i]=${devno[0]}
408     client_names[$i]=${devno[1]}
409     do_teardown_ec[$i]=${devno[2]}
410 done
411
412 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
413     for ((nobj=$nobjlo;nobj<=$nobjhi;nobj*=2)); do 
414         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
415             if ((thr < nobj)); then
416                 continue
417             fi
418             # restart?
419             if [ -n "$restart_rsz" -a\
420              -n "$restart_nobj" -a\
421              -n "$restart_thr" ]; then
422                 if ((rsz < restart_rsz ||\
423                      (rsz == restart_rsz &&\
424                       (nobj < restart_nobj ||\
425                        (nobj == restart_nobj &&\
426                     thr < restart_thr))))); then
427                     continue;
428                 fi
429             fi
430             # compute parameters
431             total_thr=$((ndevs*thr))
432             total_nobj=$((ndevs*nobj))
433             pages=$((rsz/PAGE_SIZE))
434             actual_rsz=$((pages*PAGE_SIZE))
435             count=$((size*1024/(actual_rsz*thr)))
436             actual_size=$((actual_rsz*count*thr))
437                 total_size=$((actual_size*ndevs))
438             # show computed parameters
439             str=`printf 'ost %2d sz %8dK rsz %4d obj %4d thr %4d ' \
440                  $ndevs $total_size $actual_rsz $total_nobj $total_thr`
441             echo "=======================> $str" >> $workf
442             print_summary -n "$str"
443             if ((total_thr * actual_rsz > max_buffer_mem)); then
444                 print_summary "Too much buffer space"
445                 continue
446             fi
447             # create the objects
448             tmpf="${workf}_tmp"
449             for ((idx=0; idx < ndevs; idx++)); do
450                 host=${host_names[$idx]}
451                 devno=${devnos[$idx]}
452                 client_name="${host}:${client_names[$idx]}"
453                 echo "=============> Create $nobj on $client_name" >> $workf
454                 first_obj=`create_objects $host $devno $nobj $tmpf`
455                 cat $tmpf >> $workf
456                 rm $tmpf
457                 if [ $first_obj = "ERROR" ]; then
458                     print_summary "created object #s on $client_name not contiguous"
459                     exit 1
460                 fi
461                 first_objs[$idx]=$first_obj
462             done
463             # run tests
464             for test in ${tests[@]}; do
465                 declare -a pidarray
466                 for host in ${unique_hosts[@]}; do
467                     echo "starting run for test: $test rsz: $rsz threads: $thr objects: $nobj" >> ${vmstatf}_${host}
468                 done
469                 print_summary -n "$test "
470                 # create per-host script files
471                 for host in ${unique_hosts[@]}; do
472                     echo -n > ${cmdsf}_${host}
473                 done
474                 for ((idx=0; idx < ndevs; idx++)); do
475                     host=${host_names[$idx]}
476                     devno=${devnos[$idx]}
477                     tmpfi="${tmpf}_$idx"
478                     first_obj=${first_objs[$idx]}
479                     echo >> ${cmdsf}_${host} \
480                         "$lctl > $tmpfi 2>&1 \\
481                                  --threads $thr -$snap $devno \\
482                      test_brw $count `testname2type $test` q $pages ${thr}t${first_obj} &"
483                     
484                 done
485                 pidcount=0
486                 for host in ${unique_hosts[@]}; do
487                     echo "wait" >> ${cmdsf}_${host}
488                     pidarray[$pidcount]=0
489                     pidcount=$((pidcount+1))
490                 done
491                 # timed run of all the per-host script files
492                 t0=`date +%s.%N`
493                 pidcount=0
494                 for host in ${unique_hosts[@]}; do
495                     remote_shell $host bash ${cmdsf}_${host} &
496                     pidarray[$pidcount]=$!
497                     pidcount=$((pidcount+1))
498                 done
499                 pidcount=0
500                 for host in ${unique_hosts[@]}; do
501                     wait ${pidarray[$pidcount]}
502                     pidcount=$((pidcount+1))
503                 done
504                 #wait
505                 t1=`date +%s.%N`
506                 # clean up per-host script files
507                 for host in ${unique_hosts[@]}; do
508                     rm ${cmdsf}_${host}
509                 done
510                 # compute bandwidth from total data / elapsed time
511                 str=`awk "BEGIN {printf \"%7.2f \",\
512                          $total_size / (( $t1 - $t0 ) * 1024)}"`
513                 print_summary -n "$str"
514                 # collect/check individual OST stats
515                 echo -n > $tmpf
516                 for ((idx=0; idx < ndevs; idx++)); do
517                     client_name="${host_names[$idx]}:${client_names[$idx]}"
518                     tmpfi="${tmpf}_$idx"
519                     echo "=============> $test $client_name" >> $workf
520                     cat $tmpfi >> $workf
521                     get_stats $tmpfi >> $tmpf
522                     rm $tmpfi
523                 done
524                 # compute/display global min/max stats
525                 echo "=============> $test global" >> $workf
526                 cat $tmpf >> $workf
527                 stats=(`get_global_stats $tmpf`)
528                 rm $tmpf
529                 if ((stats[0] <= 0)); then
530                     if ((stats[0] < 0)); then
531                     str=`printf "%17s " ERROR`
532                     else
533                     str=`printf "%17s " SHORT`
534                     fi
535                 else
536                     str=`awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
537                          (${stats[1]} * $actual_rsz)/1024,\
538                          (${stats[2]} * $actual_rsz)/1024; exit}"`
539                 fi
540                 print_summary -n "$str"
541             done
542             print_summary ""
543             # destroy objects we created
544             for ((idx=0; idx < ndevs; idx++)); do
545                 host=${host_names[$idx]}
546                 devno=${devnos[$idx]}
547                 client_name="${host}:${client_names[$idx]}"
548                 first_obj=${first_objs[$idx]}
549                 echo "=============> Destroy $nobj on $client_name" >> $workf
550                 destroy_objects $host $devno $first_obj $nobj $tmpf
551                 cat $tmpf >> $workf
552                 rm $tmpf
553             done
554         done
555     done
556 done
557
558 # tear down any echo clients we created
559 for ((i=0; i<ndevs; i++)); do
560     host=${host_names[$i]}
561     if ((${do_teardown_ec[$i]})); then
562         teardown_ec_devno $host ${client_names[$i]}
563     fi
564 done
565
566 # unload any obdecho modules we loaded
567 pidcount=0
568 for host in ${unique_hosts[@]}; do
569     remote_shell $host "killall vmstat" &
570     pid=$!
571     kill -term ${vmstatpids[$pidcount]}
572     kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
573     wait $pid
574     pidcount=$((pidcount+1))
575     if ((${do_unload_obdecho[$host]})); then
576         unload_obdecho $host
577     fi
578 done
579
580 exit 0