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