Whamcloud - gitweb
Update based on lustre-iokit-20051107.tar.gz from the customer download area.
[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     n=(`awk < $rfile \
199         '/is object id/ {obj=strtonum($6);\
200                          first=!not_first; not_first=1;\
201                          if (first) first_obj=obj;
202                          else if (obj != prev + 1) exit;\
203                          prev=obj; n++}\
204             END {printf "%d %d\n", first_obj, n}'`)
205     if ((n[1] != nobj)); then
206         echo "ERROR"
207     else
208         echo ${n[0]}
209     fi
210 }
211
212 destroy_objects () {
213     local host=$1
214     local devno=$2
215     local obj0=$3
216     local nobj=$4
217     local rfile=$5
218     remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
219 }
220
221 get_stats () {
222     local rfile=$1
223     awk < $rfile \
224         '/^Selected device [0-9]+$/ {n = 0; next}\
225         /error/ {n = -1; exit}\
226         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {n++; v=strtonum($3); \
227                                                           if (n == 1 || v < min) min = v;\
228                                                           if (n == 1 || v > max) max = v;\
229                                                           next}\
230         {if (n != 0) {n = -1; exit}}\
231         END {printf "%d %f %f\n", n, min, max}'
232 }
233
234 get_global_stats () {
235     local rfile=$1
236     awk < $rfile 'BEGIN {n = 0;}\
237                   {n++; if (n == 1) {err = $1; min = $2; max = $3} else\
238                                     {if ($1 < err) err = $1;\
239                                      if ($2 < min) min = $2;\
240                                      if ($3 > max) max = $3}}\
241                   END {if (n == 0) err = 0;\
242                        printf "%d %f %f\n", err, min, max}'
243 }
244
245 testname2type () {
246     # 'x' disables data check
247     if ((verify)); then
248         x=""
249     else
250         x="x"
251     fi
252     case $1 in
253         *write*)  echo "w$x";;
254         *)        echo "r$x";;
255     esac
256 }
257
258 print_summary () {
259     if [ "$1" = "-n" ]; then
260         minusn=$1; shift
261     else
262         minusn=""
263     fi
264     echo $minusn "$*" >> $rsltf
265     echo $minusn "$*"
266 }
267
268 unique () {
269     echo "$@" | xargs -n1 echo | sort -u
270 }
271
272 split_hostname () {
273     local name=$1
274     case $name in
275     *:*) host=`echo $name | sed 's/:.*$//'`
276          name=`echo $name | sed 's/[^:]*://'`
277          ;;
278     *)   host=localhost
279          ;;
280     esac
281     echo "$host $name"
282 }
283
284 # split out hostnames from client/ost names
285 ndevs=${#client_names[@]}
286 if ((ndevs != 0)); then
287     if ((${#ost_names[@]} != 0)); then
288         echo "Please specify client_names or ost_names, but not both" 1>&2
289         exit 1
290     fi
291     for ((i=0; i<ndevs;i++)); do
292         str=(`split_hostname ${client_names[$i]}`)
293         host_names[$i]=${str[0]}
294         client_names[$i]=${str[1]}
295     done
296 else
297     ndevs=${#ost_names[@]}
298     if ((ndevs == 0)); then
299         echo "Please specify either client_names or ost_names" 1>&2
300         exit 1
301     fi
302     for ((i=0; i<ndevs;i++)); do
303         str=(`split_hostname ${ost_names[$i]}`)
304         host_names[$i]=${str[0]}
305         ost_names[$i]=${str[1]}
306     done
307 fi
308
309 # disable portals debug and get obdecho loaded on all relevant hosts
310 unique_hosts=(`unique ${host_names[@]}`)
311 for host in ${unique_hosts[@]}; do
312     remote_shell $host "echo 0 > /proc/sys/portals/debug"
313     do_unload_obdecho[$host]=0
314     if obdecho_loaded $host; then
315         continue
316     fi
317     load_obdecho $host
318     if obdecho_loaded $host; then
319         do_unload_obdecho[$host]=1
320         continue
321     fi
322     echo "Can't load obdecho on $host" 1>&2
323     exit 1
324 done
325
326 # get all the echo_client device numbers and names
327 for ((i=0; i<ndevs; i++)); do
328     host=${host_names[$i]}
329     devno=(`get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"`)
330     if ((${#devno[@]} != 3)); then
331         exit 1
332     fi
333     devnos[$i]=${devno[0]}
334     client_names[$i]=${devno[1]}
335     do_teardown_ec[$i]=${devno[2]}
336 done
337
338 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
339     for ((nobj=$nobjlo;nobj<=$nobjhi;nobj*=2)); do 
340         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
341             if ((thr < nobj)); then
342                 continue
343             fi
344             # restart?
345             if [ -n "$restart_rsz" -a\
346                  -n "$restart_nobj" -a\
347                  -n "$restart_thr" ]; then
348                 if ((rsz < restart_rsz ||\
349                      (rsz == restart_rsz &&\
350                       (nobj < restart_nobj ||\
351                        (nobj == restart_nobj &&\
352                         thr < restart_thr))))); then
353                     continue;
354                 fi
355             fi
356             # compute parameters
357             total_thr=$((ndevs*thr))
358             total_nobj=$((ndevs*nobj))
359             pages=$((rsz/PAGE_SIZE))
360             actual_rsz=$((pages*PAGE_SIZE))
361             count=$((size*1024/(actual_rsz*thr)))
362             actual_size=$((actual_rsz*count*thr))
363             total_size=$((actual_size*ndevs))
364             # show computed parameters
365             str=`printf 'ost %2d sz %8dK rsz %4d obj %4d thr %4d ' \
366                      $ndevs $total_size $actual_rsz $total_nobj $total_thr`
367             echo "=======================> $str" >> $workf
368             print_summary -n "$str"
369             if ((total_thr * actual_rsz > max_buffer_mem)); then
370                 print_summary "Too much buffer space"
371                 continue
372             fi
373             # create the objects
374             tmpf="${workf}_tmp"
375             for ((idx=0; idx < ndevs; idx++)); do
376                 host=${host_names[$idx]}
377                 devno=${devnos[$idx]}
378                 client_name="${host}:${client_names[$idx]}"
379                 echo "=============> Create $nobj on $client_name" >> $workf
380                 first_obj=`create_objects $host $devno $nobj $tmpf`
381                 cat $tmpf >> $workf
382                 rm $tmpf
383                 if [ $first_obj = "ERROR" ]; then
384                     print_summary "created object #s on $client_name not contiguous"
385                     exit 1
386                 fi
387                 first_objs[$idx]=$first_obj
388             done
389             # run tests
390             for test in ${tests[@]}; do
391                 print_summary -n "$test "
392                 # create per-host script files
393                 for host in ${unique_hosts[@]}; do
394                     echo -n > ${cmdsf}_${host}
395                 done
396                 for ((idx=0; idx < ndevs; idx++)); do
397                     host=${host_names[$idx]}
398                     devno=${devnos[$idx]}
399                     tmpfi="${tmpf}_$idx"
400                     first_obj=${first_objs[$idx]}
401                     echo >> ${cmdsf}_${host} \
402                         "$lctl > $tmpfi 2>&1 \\
403                          --threads $thr -$snap $devno \\
404                          test_brw $count `testname2type $test` q $pages ${thr}t${first_obj} &"
405                 done
406                 for host in ${unique_hosts[@]}; do
407                     echo "wait" >> ${cmdsf}_${host}
408                 done
409                 # timed run of all the per-host script files
410                 t0=`date +%s.%N`
411                 for host in ${unique_hosts[@]}; do
412                     remote_shell $host bash ${cmdsf}_${host}&
413                 done
414                 wait
415                 t1=`date +%s.%N`
416                 # clean up per-host script files
417                 for host in ${unique_hosts[@]}; do
418                     rm ${cmdsf}_${host}
419                 done
420                 # compute bandwidth from total data / elapsed time
421                 str=`awk "BEGIN {printf \"%7.2f \",\
422                          $total_size / (( $t1 - $t0 ) * 1024)}"`
423                 print_summary -n "$str"
424                 # collect/check individual OST stats
425                 echo -n > $tmpf
426                 for ((idx=0; idx < ndevs; idx++)); do
427                     client_name="${host_names[$idx]}:${client_names[$idx]}"
428                     tmpfi="${tmpf}_$idx"
429                     echo "=============> $test $client_name" >> $workf
430                     cat $tmpfi >> $workf
431                     get_stats $tmpfi >> $tmpf
432                     rm $tmpfi
433                 done
434                 # compute/display global min/max stats
435                 echo "=============> $test global" >> $workf
436                 cat $tmpf >> $workf
437                 stats=(`get_global_stats $tmpf`)
438                 rm $tmpf
439                 if ((stats[0] <= 0)); then
440                     if ((stats[0] < 0)); then
441                         str=`printf "%17s " ERROR`
442                     else
443                         str=`printf "%17s " SHORT`
444                     fi
445                 else
446                     str=`awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
447                              (${stats[1]} * $actual_rsz)/1024,\
448                              (${stats[2]} * $actual_rsz)/1024; exit}"`
449                 fi
450                 print_summary -n "$str"
451             done
452             print_summary ""
453             # destroy objects we created
454             for ((idx=0; idx < ndevs; idx++)); do
455                 host=${host_names[$idx]}
456                 devno=${devnos[$idx]}
457                 client_name="${host}:${client_names[$idx]}"
458                 first_obj=${first_objs[$idx]}
459                 echo "=============> Destroy $nobj on $client_name" >> $workf
460                 destroy_objects $host $devno $first_obj $nobj $tmpf
461                 cat $tmpf >> $workf
462                 rm $tmpf
463             done
464         done
465     done
466 done
467
468 # tear down any echo clients we created
469 for ((i=0; i<ndevs; i++)); do
470     host=${host_names[$i]}
471     if ((${do_teardown_ec[$i]})); then
472         teardown_ec_devno $host ${client_names[$i]}
473     fi
474 done
475
476 # unload any obdecho modules we loaded
477 for host in ${unique_hosts[@]}; do
478     if ((${do_unload_obdecho[$host]})); then
479         unload_obdecho $host
480     fi
481 done