Whamcloud - gitweb
2d85b8fbc2954155843a8e046bdd1589cb785ec1
[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     awk < $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=${rslt:-"/tmp/obdfilter_survey_`date +%F@%R`_`uname -n`"}
179
180 # what tests to run (first must be write)
181 tests_str=${tests_str:-""}
182 if [ -n "$tests_str" ]; then
183     declare -a tests
184     count=0
185     for name in $tests_str; do
186         tests[$count]=$name
187         count=$((count+1))
188     done
189 else
190     #tests=(write rewrite read reread rewrite_again)
191     tests=(write rewrite read)
192 fi
193
194 # Set this true to check file contents
195 verify=0
196
197 # total size (MBytes) per obd instance
198 # large enough to avoid cache effects 
199 # and to make test startup/shutdown overhead insignificant
200 size=${size:-16384}
201
202 # record size (KBytes)
203 rszlo=${rszlo:-1024}
204 rszhi=${rszhi:-1024}
205
206 # number of objects per OST
207 nobjlo=${nobjlo:-1}
208 #was nobjhi=${nobjhi:-512}
209 nobjhi=${nobjhi:-16}
210
211 # threads per OST (1024 max)
212 thrlo=${thrlo:-1}
213 thrhi=${thrhi:-16}
214
215 # restart from here iff all are defined
216 restart_rsz=
217 restart_thr=1
218 restart_nobj=1
219
220 # machine's page size (K)
221 if [ -z "$PAGE_SIZE" ]; then
222     if which python >/dev/null; then
223         PAGE_SIZE=`echo 'import resource; print resource.getpagesize()/1024;' |python`
224     fi
225 fi
226 PAGE_SIZE=${PAGE_SIZE:-4}
227
228 # max buffer_mem (total_threads * buffer size)
229 # (to avoid lctl ENOMEM problems)
230 max_buffer_mem=$((1024 * 1024))
231 snap=1
232
233 # Customisation variables ends here. 
234 #####################################################################
235 # leave the rest of this alone unless you know what you're doing...
236
237 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
238     echo "tests: ${tests[@]}"
239     echo "First test must be 'write'" 1>&2
240     exit 1
241 fi
242
243 rsltf="${rslt}.summary"
244 workf="${rslt}.detail"
245 cmdsf="${rslt}.script"
246 vmstatf="${rslt}.vmstat"
247 echo -n > $rsltf
248 echo -n > $workf
249
250 # hide a little trick to unset this from the command line
251 if [ "$lustre_root" == " " ]; then
252     unset lustre_root
253 fi
254
255 if [ -z "$lustre_root" ]; then
256     lctl=lctl
257 else
258     lctl=${lustre_root}/utils/lctl
259 fi
260
261 if [ $case == "network" ]; then
262     if [ -z "$server_nid" ]; then
263         echo "Specify the server NID"
264         exit 1;
265     fi
266     osc_names_string=`ssh root@"$server_nid" lctl dl`
267     count=0;
268     for name in $osc_names_str; do
269         count=$((count+1))
270     done
271
272     if [ $count != 0 ]; then
273         echo "The existing setup must be cleaned";
274         exit 0;
275     fi
276     # Now do the server setup
277     setup_srv_obd $server_nid "ost_testfs"
278     op_string=`ssh root@"$server_nid" lctl dl`
279     
280     obdecho=0
281     ost=0 
282     for name in $op_string; do
283         if [ "$name" = "obdecho" ]; then
284             obdecho=1
285         fi
286         if [ "$name" = "ost" ]; then
287             ost=1
288         fi
289     done
290
291     if (( $obdecho == 0 || $ost == 0 )); then
292         echo "Server setup not done properly"
293         exit 1
294     fi
295     # Now start client setup
296     osc_names_str=$(lctl dl)
297     if [ -n "$osc_names_str" ]; then
298         echo "The existing setup must be cleaned";
299         exit 0;
300     fi
301     ec_using_srv_nid $server_nid "osc_testfs" "test_obdfs"
302     declare -a client_names
303     client_names[0]="ECHO_osc_testfs"
304 fi
305
306 if [ -z "$ECHO_CLIENTS" ]; then
307     if [ $case == "netdisk" ]; then
308         declare -a osc_names
309         declare -a osc_uuids
310         osc_names_str=$(lctl dl |grep osc | awk "{if (\$2 == \"UP\" && \$3 == \"osc\") {print \$4} }")
311         count=0;
312         for name in $osc_names_str; do
313             osc_names[$count]=$name
314             count=$((count+1))
315         done
316         osc_uuid_str=$(lctl dl |grep osc | awk "{if (\$2 == \"UP\" && \$3 == \"osc\") {print \$5} }")
317         count=0;
318         for uuid in $osc_uuid_str; do
319             osc_uuids[$count]=$uuid
320             count=$((count+1))
321         done
322         for ((  i = 0 ;  i < $count;  i++  ))
323         do
324             ec_using_osc ${osc_names[$i]} ${osc_uuids[$i]}
325         done
326         ECHO_CLIENTS=$(lctl dl | grep echo_client | awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") {print \$4} }")
327         cnt=0;
328         for name in $ECHO_CLIENTS; do
329             client_names[$cnt]=$name
330             cnt=$((cnt+1))
331         done
332     fi
333 fi
334
335 if [ -z "$OSTS" ]; then
336     if [ $case == "disk" ]; then
337         get_targets     
338     fi  
339 fi
340
341 # split out hostnames from client/ost names
342 ndevs=${#client_names[@]}
343 if ((ndevs != 0)); then
344     if ((${#ost_names[@]} != 0)); then
345         echo "Please specify client_names or ost_names, but not both" 1>&2
346         exit 1
347     fi
348     for ((i = 0; i < ndevs; i++)); do
349         str=(`split_hostname ${client_names[$i]}`)
350         host_names[$i]=${str[0]}
351         client_names[$i]=${str[1]}
352     done
353 else
354     ndevs=${#ost_names[@]}
355     if ((ndevs == 0)); then
356         echo "Please specify either client_names or ost_names" 1>&2
357         exit 1
358     fi
359     for ((i = 0; i < ndevs; i++)); do
360         str=(`split_hostname ${ost_names[$i]}`)
361         host_names[$i]=${str[0]}
362         ost_names[$i]=${str[1]}
363     done
364 fi
365
366 # get vmstat started
367 # disable portals debug and get obdecho loaded on all relevant hosts
368 unique_hosts=(`unique ${host_names[@]}`)
369 pidcount=0
370 for host in ${unique_hosts[@]}; do
371     host_vmstatf=${vmstatf}_${host}
372     echo -n > $host_vmstatf
373     remote_shell $host "vmstat 5 >> $host_vmstatf" &
374     pid=$!
375     vmstatpids[$pidcount]=$pid
376     pidcount=$((pidcount+1))
377     do_unload_obdecho[$host]=0
378     if obdecho_loaded $host; then
379         continue
380     fi
381     load_obdecho $host
382     if obdecho_loaded $host; then
383         do_unload_obdecho[$host]=1
384         continue
385         fi
386     echo "Can't load obdecho on $host" 1>&2
387     exit 1
388 done
389
390 # get all the echo_client device numbers and names
391 for ((i=0; i < ndevs; i++)); do
392     host=${host_names[$i]}
393     devno=(`get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"`)
394     if ((${#devno[@]} != 3)); then
395         exit 1
396     fi
397     devnos[$i]=${devno[0]}
398     client_names[$i]=${devno[1]}
399     do_teardown_ec[$i]=${devno[2]}
400 done
401 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
402     for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do 
403         for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
404             if ((thr % nobj)); then
405                 continue
406             fi
407             # restart?
408             if [ -n "$restart_rsz" -a\
409                  -n "$restart_nobj" -a\
410                  -n "$restart_thr" ]; then
411                 if ((rsz < restart_rsz ||\
412                      (rsz == restart_rsz &&\
413                       (nobj < restart_nobj ||\
414                        (nobj == restart_nobj &&\
415                         thr < restart_thr))))); then
416                     continue;
417                 fi
418             fi
419             # compute parameters
420             total_thr=$((ndevs*thr))
421             total_nobj=$((ndevs*nobj))
422             pages=$((rsz/PAGE_SIZE))
423             actual_rsz=$((pages*PAGE_SIZE))
424             count=$((size*1024/(actual_rsz*thr)))
425             actual_size=$((actual_rsz*count*thr))
426             total_size=$((actual_size*ndevs))
427             # show computed parameters
428             str=`printf 'ost %2d sz %8dK rsz %4d obj %4d thr %4d ' \
429                      $ndevs $total_size $actual_rsz $total_nobj $total_thr`
430             echo "=======================> $str" >> $workf
431             print_summary -n "$str"
432             if ((total_thr * actual_rsz > max_buffer_mem)); then
433                 print_summary "Too much buffer space"
434                 continue
435             fi
436             # create the objects
437             tmpf="${workf}_tmp"
438             for ((idx = 0; idx < ndevs; idx++)); do
439                 host=${host_names[$idx]}
440                 devno=${devnos[$idx]}
441                 client_name="${host}:${client_names[$idx]}"
442                 echo "=============> Create $nobj on $client_name" >> $workf
443                 first_obj=`create_objects $host $devno $nobj $tmpf`
444                 cat $tmpf >> $workf
445                 rm $tmpf
446                 if [ $first_obj = "ERROR" ]; then
447                     print_summary "created object #s on $client_name not contiguous"
448                     exit 1
449                 fi
450                 first_objs[$idx]=$first_obj
451             done
452             # run tests
453             for test in ${tests[@]}; do
454                 declare -a pidarray
455                 for host in ${unique_hosts[@]}; do
456                     echo "starting run for test: $test rsz: $rsz threads: $thr objects: $nobj" >> ${vmstatf}_${host}
457                 done
458                 print_summary -n "$test "
459                 # create per-host script files
460                 for host in ${unique_hosts[@]}; do
461                     echo -n > ${cmdsf}_${host}
462                 done
463                 for ((idx = 0; idx < ndevs; idx++)); do
464                     host=${host_names[$idx]}
465                     devno=${devnos[$idx]}
466                     tmpfi="${tmpf}_$idx"
467                     first_obj=${first_objs[$idx]}
468                     thr_per_obj=$((${thr}/${nobj}))
469                     echo >> ${cmdsf}_${host} \
470                         "$lctl > $tmpfi 2>&1 \\
471                          --threads $thr -$snap $devno \\
472                          test_brw $count `testname2type $test` q $pages ${thr_per_obj}t${first_obj} &"
473                 done
474                 pidcount=0
475                 for host in ${unique_hosts[@]}; do
476                     echo "wait" >> ${cmdsf}_${host}
477                     pidarray[$pidcount]=0
478                     pidcount=$((pidcount+1))
479                 done
480                 # timed run of all the per-host script files
481                 t0=`date +%s.%N`
482                 pidcount=0
483                 for host in ${unique_hosts[@]}; do
484                     # brutal hack to deal with a non-shared /tmp
485                     scp -q ${cmdsf}_${host} ${host}:/tmp > /dev/null
486                     remote_shell $host bash ${cmdsf}_${host} &
487                     pidarray[$pidcount]=$!
488                     pidcount=$((pidcount+1))
489                 done
490                 pidcount=0
491                 for host in ${unique_hosts[@]}; do
492                     wait ${pidarray[$pidcount]}
493                     pidcount=$((pidcount+1))
494                 done
495                 #wait
496                 t1=`date +%s.%N`
497                 # clean up per-host script files
498                 for host in ${unique_hosts[@]}; do
499                     rm ${cmdsf}_${host}
500                 done
501                 # compute bandwidth from total data / elapsed time
502                 str=`awk "BEGIN {printf \"%7.2f \",\
503                          $total_size / (( $t1 - $t0 ) * 1024)}"`
504                 print_summary -n "$str"
505                 # collect/check individual OST stats
506                 echo -n > $tmpf
507                 for ((idx = 0; idx < ndevs; idx++)); do
508                     client_name="${host_names[$idx]}:${client_names[$idx]}"
509                     tmpfi="${tmpf}_$idx"
510                     echo "=============> $test $client_name" >> $workf
511                     host="${host_names[$idx]}"
512                     scp -q ${host}:$tmpfi $tmpfi > /dev/null
513                     cat $tmpfi >> $workf
514                     get_stats $tmpfi >> $tmpf
515                     rm $tmpfi
516                 done
517                 # compute/display global min/max stats
518                 echo "=============> $test global" >> $workf
519                 cat $tmpf >> $workf
520                 stats=(`get_global_stats $tmpf`)
521                 rm $tmpf
522                 if ((stats[0] <= 0)); then
523                     if ((stats[0] < 0)); then
524                         str=`printf "%17s " ERROR`
525                     else
526                         str=`printf "%17s " SHORT`
527                     fi
528                 else
529                     str=`awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
530                              (${stats[1]} * $actual_rsz)/1024,\
531                              (${stats[2]} * $actual_rsz)/1024; exit}"`
532                 fi
533                 print_summary -n "$str"
534             done
535             print_summary ""
536             # destroy objects we created
537             for ((idx = 0; idx < ndevs; idx++)); do
538                 host=${host_names[$idx]}
539                 devno=${devnos[$idx]}
540                 client_name="${host}:${client_names[$idx]}"
541                 first_obj=${first_objs[$idx]}
542                 echo "=============> Destroy $nobj on $client_name" >> $workf
543                 destroy_objects $host $devno $first_obj $nobj $tmpf
544                 cat $tmpf >> $workf
545                 rm $tmpf
546             done
547         done
548     done
549 done
550
551 cleanup 0
552 exit 0