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