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