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