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