Whamcloud - gitweb
382db0c3a573ea2c2979fc9053eba62b0f60c7bd
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / obdfilter-survey
1 #!/bin/bash
2 ######################################################################
3 # customize per survey
4
5 # specify obd instances to exercise
6 # these can be either...
7 # obdfilter instances (set 'ost_names')
8 # ...or...
9 # echo_client instances (set 'client_names')
10 # ... use 'host:name' for obd instances on other nodes.
11 # allow these to be passed in via string...
12 # OR
13 # one can specify only case=disk or case=network or case=netdisk through
14 # command line.
15
16 # Prerequisite: For "disk" case and "netdisk" case you need to have lustre setup
17 #             with one or more ost's. For "network" case  you need to have all
18 #             modules (those llmount.sh loades) loaded in kernel. And the
19 #             'lctl dl' output must be blank.
20
21 # How to run test:
22 # case 1 (local disk):
23 #   $ nobjhi=2 thrhi=2 size=1024 case=disk sh obdfilter-survey
24 #   one can also run test with user defined targets as follows,
25 #   $ nobjhi=2 thrhi=2 size=1024 targets="lustre-OST0000 lustre-OST0001 ..." sh obdfilter-survey
26 # case 2 (network):
27 #   $ nobjhi=2 thrhi=2 size=1024 targets="<name/ip_of_server>" case=network sh obdfilter-survey
28 #   where, targets is name or ip address of system, which you want to
29 #   set as server.
30 # case 3 (network and disk):
31 #   $ nobjhi=2 thrhi=2 size=1024 case=netdisk sh obdfilter-survey
32 #   one can also run test with user defined targets as follows,
33 #   $ nobjhi=2 thrhi=2 size=1024 targets="<osc_name> ..." sh obdfilter-survey
34 #[ NOTE: It is advised to have automated login (passwordless entry) between server and
35 #  client systems on which this test runs.]
36
37 # include library
38 source $(dirname $0)/iokit-libecho
39
40 # The following variables can be set in the environment, or on the
41 # command line
42 # result file prefix (date/time + hostname makes unique)
43 # NB ensure path to it exists
44 rslt_loc=${rslt_loc:-"/tmp"}
45 rslt=${rslt:-"$rslt_loc/obdfilter_survey_$(date +%F@%R)_$(uname -n)"}
46
47 # Set this true to check file contents
48 verify=${verify:-0}
49
50 # test targets
51 targets=${targets:-""}
52 # test case
53 case=${case:-"disk"}
54
55 # total size (MBytes) per obd instance
56 # large enough to avoid cache effects
57 # and to make test startup/shutdown overhead insignificant
58 size=${size:-16384}
59
60 # record size (KBytes) ( 7168 max)
61 rszlo=${rszlo:-1024}
62 rszhi=${rszhi:-1024}
63 rszmax=${rszmax:-4096}
64
65 # number of objects per OST
66 nobjlo=${nobjlo:-1}
67 #was nobjhi=${nobjhi:-512}
68 nobjhi=${nobjhi:-16}
69
70 # threads per OST (1024 max)
71 thrlo=${thrlo:-1}
72 thrhi=${thrhi:-16}
73
74 export LC_ALL=POSIX
75
76 # End of variables
77
78 # create a set of objects, check there are 'n' contiguous ones and
79 # echo out the first or 'ERROR'
80 # parameter: 1. hostname
81 #            2. device number
82 #            3. number of object to be created (specified by user)
83 #            4. tempfile name
84 create_objects () {
85         local host=$1
86         local devno=$2
87         local nobj=$3
88         local rfile=$4
89
90         remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
91         first=0
92         prev=0
93         count=0
94         error=0
95
96         # Count number of objects (lines containing " is object id "), and
97         # ensure that the objects numbers are sequential.
98         #
99         exec 3< $rfile
100         while read -u3 line; do
101                 case "$line" in
102                 ( *' is object id '* )
103                 set -- $line
104                 if test $(( count += 1 )) -gt 1 ; then
105                         (( $6 != prev + 1 )) && error=1
106                 else
107                         first=$(( $6 + 0 ))
108                 fi
109                 prev=$6
110                 ;;
111                 esac
112         done
113         exec 3<&-
114
115         if [ $nobj -ne $count ]; then
116                 echo "ERROR: $nobj != $count" >&2
117                 cat $rfile >&2
118                 echo "ERROR"
119         elif [ $error -ne 0 ]; then
120                 echo "ERROR: non contiguous objs found" >&2
121                 echo ERROR
122         else
123                 echo $first
124         fi
125         return $error
126 }
127
128 # destroys all objects created in create_objects routine
129 # parameter: 3. start obj id.
130 destroy_objects () {
131         local host=$1
132         local devno=$2
133         local obj0=$3
134         local nobj=$4
135         local rfile=$5
136
137         remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
138 }
139
140 get_stats () {
141         local rfile=$1
142
143         gawk < $rfile                                                   \
144         '/^Selected device [0-9]+$/ {                                   \
145                 n = 0;                                                  \
146                 next;                                                   \
147         }                                                               \
148         /error/ {                                                       \
149                 n = -1;                                                 \
150                 exit;                                                   \
151         }                                                               \
152         /^Total/ {                                                      \
153                 next;                                                   \
154         }                                                               \
155         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {              \
156                 n++;                                                    \
157                 v=strtonum($3);                                         \
158                 if (n == 1 || v < min)                                  \
159                         min = v;                                        \
160                 if (n == 1 || v > max)                                  \
161                         max = v;                                        \
162                 next;                                                   \
163         }                                                               \
164         {                                                               \
165                 if (n != 0) {                                           \
166                         n = -1;                                         \
167                         exit;                                           \
168                 }                                                       \
169         }                                                               \
170         END {                                                           \
171                 printf "%d %f %f\n", n, min, max                        \
172         }'
173 }
174
175 get_global_stats () {
176         local rfile=$1
177
178         awk < $rfile                                                    \
179         'BEGIN {                                                        \
180                 n = 0;                                                  \
181         }                                                               \
182         {                                                               \
183                 n++;                                                    \
184                 if (n == 1) {                                           \
185                         err = $1;                                       \
186                         min = $2;                                       \
187                         max = $3;                                       \
188                 } else {                                                \
189                         if ($1 < err)                                   \
190                                 err = $1;                               \
191                         if ($2 < min)                                   \
192                                 min = $2;                               \
193                         if ($3 > max)                                   \
194                                 max = $3;                               \
195                 }                                                       \
196         }                                                               \
197         END {                                                           \
198                 if (n == 0)                                             \
199                         err = 0;                                        \
200                 printf "%d %f %f\n", err, min, max                      \
201         }'
202 }
203
204 # enable or disable data check.
205 # parameter: 1. read/write
206 testname2type () {
207         # 'x' disables data check
208         if ((verify)); then
209                 x=""
210         else
211                 x="x"
212         fi
213         case $1 in
214         *write*)  echo "w$x";;
215         *)        echo "r$x";;
216         esac
217 }
218
219 # for "echo_client + obdfilter" case, "prep + commit" mode should be used
220 # for "echo_client + osc" case, "BRW" mode should be used
221 testcase2mode() {
222         case $case in
223         disk)   echo "p";;
224         *)      echo "g";;
225         esac
226 }
227
228 print_summary () {
229         if [ "$1" = "-n" ]; then
230                 minusn=$1; shift
231         else
232                 minusn=""
233         fi
234         echo $minusn "$*" >> $rsltf
235         echo $minusn "$*"
236 }
237
238 # Return a numeric version code based on a version string.  The version
239 # code is useful for comparison two version strings to see which is newer.
240 version_code() {
241         # split arguments like "2.3.61" into "2", "3", "61"
242         eval set -- $(tr "[:punct:]" " " <<< $*)
243         echo -n "$((($1 << 16) | ($2 << 8) | $3))"
244 }
245
246 # inspired from the lustre_build_version routine in test-framework.sh
247 get_lustre_version() {
248         local host=${1:-${unique_hosts[0]}}
249         local ver
250
251         ver=$(remote_shell $host "$lctl get_param -n version 2>/dev/null ||
252                                 $lctl lustre_build_version 2>/dev/null ||
253                                 $lctl --version 2>/dev/null | cut -d' ' -f2")
254         local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
255         [ -n "$lver" ] && ver="$lver"
256
257         sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
258                 cut -d. -f1-4
259 }
260
261 # Check whether the record size (KBytes) exceeds the maximum bulk I/O RPC size
262 # or not.
263 check_record_size() {
264         [ $(version_code $(get_lustre_version)) -lt $(version_code 2.3.61) ] &&
265                 rszmax=1024
266
267         if [ "$rszhi" -gt "$rszmax" ]; then
268                 echo "Test disk case support maximum ${rszmax}KB IO data" \
269                      "(rszhi=$rszhi is too big), please use a smaller value."
270                 return 1
271         fi
272         return 0
273 }
274
275 # Customisation variables
276 #####################################################################
277 # One can change variable values in this section as per requirements
278
279 if [ -n "$targets" ]; then
280         declare -a ost_names
281         declare -a client_names
282         count=0
283         for name in $targets; do
284                 if [ $case == "disk" ]; then
285                 ost_names[$count]=$name
286                 else
287                 client_names[$count]=$name
288                 fi
289                 count=$((count + 1))
290         done
291 fi
292
293 # what tests to run (first must be write)
294 tests_str=${tests_str:-""}
295 if [ -n "$tests_str" ]; then
296         declare -a tests
297         count=0
298         for name in $tests_str; do
299                 tests[$count]=$name
300                 count=$((count + 1))
301         done
302 else
303         #tests=(write rewrite read reread rewrite_again)
304         tests=(write rewrite read)
305 fi
306
307 # restart from here iff all are defined
308 restart_rsz=
309 restart_thr=1
310 restart_nobj=1
311
312 # machine's page size (KB)
313 PAGE_SIZE=${PAGE_SIZE:-$(($(getconf PAGE_SIZE) / 1024))}
314 PAGE_SIZE=${PAGE_SIZE:-4}
315
316 snap=1
317 clean_srv_OSS=0
318 # Customisation variables ends here.
319 #####################################################################
320 # leave the rest of this alone unless you know what you're doing...
321
322 # check and insert obdecho module
323 if ! lsmod | grep obdecho > /dev/null; then
324         modprobe obdecho
325 fi
326 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
327         echo "tests: ${tests[@]}"
328         echo "First test must be 'write'" 1>&2
329         exit 1
330 fi
331
332 rsltf="${rslt}.summary"
333 workf="${rslt}.detail"
334 cmdsf="${rslt}.script"
335 vmstatf="${rslt}.vmstat"
336 echo -n > $rsltf
337 echo -n > $workf
338
339 # hide a little trick to unset this from the command line
340 if [ "$lustre_root" == " " ]; then
341         unset lustre_root
342 fi
343
344 if [ -z "$lustre_root" ]; then
345         lctl=lctl
346 else
347         lctl=${lustre_root}/utils/lctl
348 fi
349
350 # split out hostnames from client/ost names
351 ndevs=0
352 for trgt in $targets; do
353         str=($(split_hostname $trgt))
354         host_names[$ndevs]=${str[0]}
355         client_names[$ndevs]=${str[1]}
356         ndevs=$((ndevs + 1))
357 done
358 if [ $case == "disk" ]; then
359         for ((i = 0; i < $ndevs; i++)); do
360                 ost_names[$i]=${client_names[$i]}
361         done
362 fi
363 if [ $case == "netdisk" ]; then
364         if [ "$targets" ]; then
365                 for ((i = 0; i < $ndevs; i++)); do
366                         setup_osc_for_remote_ost ${host_names[$i]} \
367                                                  ${client_names[$i]} $i
368                         osc_name=${client_names[$i]}_osc
369                         ec_using_osc $osc_name
370                         cleanup_oscs="$cleanup_oscs $osc_name"
371                 done
372         else
373                 client_names_str=$($lctl dl | grep -v mdt |
374                         awk '{if ($2 == "UP" && $3 == "osc") {print $4} }')
375                 count=0;
376                 for name in $client_names_str; do
377                         client_names[$count]=$(echo $name | sed 's/-osc-.*$//')
378                         count=$((count + 1))
379                 done
380
381                 host_names_str=$($lctl dl -t | grep -v mdt |
382                         awk '{if ($2 == "UP" && $3 == "osc") {print $7} }')
383                 count=0;
384                 for name in $host_names_str; do
385                         host_names[$count]=$(echo $name | sed 's/@.*$//')
386                         count=$((count + 1))
387                 done
388
389                 for (( i = 0; i < $count; i++ )) do
390                         setup_osc_for_remote_ost ${host_names[$i]} \
391                                                  ${client_names[$i]} $i
392                         osc_name=${client_names[$i]}_osc
393                         ec_using_osc $osc_name
394                         cleanup_oscs="$cleanup_oscs $osc_name"
395                 done
396         fi
397
398         echo_clients=$($lctl dl | grep echo_client |
399                        awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") { \
400                                 print \$4} }")
401         cnt=0;
402         for name in $echo_clients; do
403                 client_names[$cnt]=$name
404                 host_names[$cnt]=localhost
405                 cnt=$((cnt + 1))
406         done
407         ndevs=${#client_names[@]}
408 fi
409 if [ $case == "network" ]; then
410         server_nid=$targets
411         if [ -z "$server_nid" ]; then
412                 echo "Specify hostname or ip-address of server"
413                 exit 1;
414         fi
415         # check for obdecho module on server
416         if ! dsh $server_nid root "lsmod | grep obdecho > /dev/null"; then
417                 dsh $server_nid root "modprobe obdecho"
418         fi
419         # Now do the server setup
420         setup_srv_obd $server_nid "echo_srv"
421         oss_on_srv=$(dsh $server_nid root "$lctl dl | grep OSS" |
422                      awk '{ print $4 }')
423         if [ -z $oss_on_srv ]; then
424                 setup_OSS $server_nid
425                 clean_srv_OSS=1
426         fi
427         if ! dsh $server_nid root "$lctl dl | grep obdecho > /dev/null 2>&1"; then
428                 echo "obdecho not setup on server"
429                 exit 1
430         fi
431         if ! dsh $server_nid root "$lctl dl | grep ost > /dev/null 2>&1"; then
432                 echo "ost not setup on server"
433                 exit 1
434         fi
435         # Now start client setup
436         osc_names_str=$($lctl dl| grep osc | grep -v mdt | grep UP || true)
437         if [ -n "$osc_names_str" ]; then
438                 echo "The existing setup must be cleaned";
439                 exit 0;
440         fi
441         ec_using_srv_nid $server_nid "echotmp" "echotmp_UUID"
442         client_names[0]="echotmp_ecc"
443 fi
444 if [ -z "$targets" ]; then
445         if [ $case == "disk" ]; then
446                 get_targets
447                 ndevs=${#ost_names[@]}
448         fi
449 fi
450 # get vmstat started
451 # disable portals debug and get obdecho loaded on all relevant hosts
452 unique_hosts=($(unique ${host_names[@]}))
453 load_obdechos
454
455 if [ $case == "disk" ]; then
456         check_record_size || cleanup ${PIPESTATUS[0]}
457 fi
458
459 pidcount=0
460 for host in ${unique_hosts[@]}; do
461         host_vmstatf=${vmstatf}_${host}
462         echo -n > $host_vmstatf
463         remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
464         pid=$!
465         vmstatpids[$pidcount]=$pid
466         pidcount=$((pidcount + 1))
467 done
468 # get all the echo_client device numbers and names
469 for ((i=0; i < $ndevs; i++)); do
470         host=${host_names[$i]}
471         devno=($(get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"))
472         if ((${#devno[@]} != 3)); then
473                 cleanup 2
474         fi
475         devnos[$i]=${devno[0]}
476         client_names[$i]=${devno[1]}
477         do_teardown_ec[$i]=${devno[2]}
478 done
479 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
480         echo "no devices or hosts specified"
481         cleanup 0 $clean_srv_OSS $cleanup_oscs
482 fi
483
484 print_summary "$(date) Obdfilter-survey for case=$case from $(hostname)"
485 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
486         for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do
487                 for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
488                         if ((thr % nobj)); then
489                                 continue
490                         fi
491                         # restart?
492                         if [ -n "$restart_rsz" -a \
493                              -n "$restart_nobj" -a \
494                              -n "$restart_thr" ]; then
495                                 if ((rsz < restart_rsz ||
496                                      (rsz == restart_rsz &&
497                                       (nobj < restart_nobj ||
498                                        (nobj == restart_nobj &&
499                                         thr < restart_thr))))); then
500                                         continue;
501                                 fi
502                         fi
503
504                         # compute parameters
505                         total_thr=$((ndevs * thr))
506                         total_nobj=$((ndevs * nobj))
507                         pages=$((rsz / PAGE_SIZE))
508                         actual_rsz=$((pages * PAGE_SIZE))
509                         count=$((size * 1024 / (actual_rsz * thr)))
510                         actual_size=$((actual_rsz * count * thr))
511                         total_size=$((actual_size * ndevs))
512
513                         # show computed parameters
514                         str=$(printf 'ost %2d sz %8dK rsz %4dK obj %4d thr %4d ' \
515                               $ndevs $total_size $actual_rsz $total_nobj $total_thr)
516                         echo "=======================> $str" >> $workf
517                         print_summary -n "$str"
518
519                         # create the objects
520                         tmpf="${workf}_tmp"
521                         for ((idx = 0; idx < $ndevs; idx++)); do
522                                 host=${host_names[$idx]}
523                                 devno=${devnos[$idx]}
524                                 client_name="${host}:${client_names[$idx]}"
525                                 echo "=============> Create $nobj on $client_name" >> $workf
526                                 first_obj=$(create_objects $host $devno $nobj $tmpf)
527                                 cat $tmpf >> $workf
528                                 rm $tmpf
529                                 if [ $first_obj = "ERROR" ]; then
530                                         print_summary "created object #s on $client_name not contiguous"
531                                         cleanup 3
532                                 fi
533                                 first_objs[$idx]=$first_obj
534                         done # $ndevs
535
536                         # run tests
537                         for test in ${tests[@]}; do
538                                 declare -a pidarray
539                                 for host in ${unique_hosts[@]}; do
540                                         remote_shell $host \
541                                             "lctl set_param -n osd*.*.force_sync 1 &>/dev/null || true"
542                                         echo "starting run for test: $test rsz: $rsz " \
543                                         "threads: $thr objects: $nobj" >> ${vmstatf}_${host}
544                                 done
545                                 print_summary -n "$test "
546
547                                 # create per-host script files
548                                 for host in ${unique_hosts[@]}; do
549                                         echo -n > ${cmdsf}_${host}
550                                 done
551                                 for ((idx = 0; idx < $ndevs; idx++)); do
552                                         host=${host_names[$idx]}
553                                         devno=${devnos[$idx]}
554                                         tmpfi="${tmpf}_$idx"
555                                         first_obj=${first_objs[$idx]}
556                                         thr_per_obj=$((${thr}/${nobj}))
557                                         echo >> ${cmdsf}_${host} \
558                                         "$lctl > $tmpfi 2>&1 \\
559                                         --threads $thr -$snap $devno \\
560                                         test_brw $count $(testname2type $test) q $pages \\
561                                         ${thr_per_obj}t${first_obj} $(testcase2mode)$pages &"
562                                 done # $ndevs
563                                 pidcount=0
564                                 for host in ${unique_hosts[@]}; do
565                                         echo "wait" >> ${cmdsf}_${host}
566                                         pidarray[$pidcount]=0
567                                         pidcount=$((pidcount + 1))
568                                 done
569                                 # timed run of all the per-host script files
570                                 t0=$(date +%s.%N)
571                                 pidcount=0
572                                 for host in ${unique_hosts[@]}; do
573                                         remote_shell $host bash < ${cmdsf}_${host} &
574                                         pidarray[$pidcount]=$!
575                                         pidcount=$((pidcount + 1))
576                                 done
577                                 pidcount=0
578                                 for host in ${unique_hosts[@]}; do
579                                         wait ${pidarray[$pidcount]}
580                                         pidcount=$((pidcount + 1))
581                                 done
582                                 #wait
583                                 t1=$(date +%s.%N)
584                                 # clean up per-host script files
585                                 for host in ${unique_hosts[@]}; do
586                                         rm ${cmdsf}_${host}
587                                 done
588
589                                 # compute bandwidth from total data / elapsed time
590                                 str=$(awk "BEGIN {printf \"%7.2f \",\
591                                 $total_size / (( $t1 - $t0 ) * 1024)}")
592                                 print_summary -n "$str"
593                                 # collect/check individual OST stats
594                                 echo -n > $tmpf
595                                 for ((idx = 0; idx < $ndevs; idx++)); do
596                                         client_name="${host_names[$idx]}:${client_names[$idx]}"
597                                         tmpfi="${tmpf}_$idx"
598                                         echo "=============> $test $client_name" >> $workf
599                                         host="${host_names[$idx]}"
600                                         remote_shell $host cat $tmpfi > ${tmpfi}_local
601                                         cat ${tmpfi}_local >> $workf
602                                         get_stats ${tmpfi}_local >> $tmpf
603                                         rm -f $tmpfi ${tmpfi}_local
604                                 done # $ndevs
605
606                                 # compute/display global min/max stats
607                                 echo "=============> $test global" >> $workf
608                                 cat $tmpf >> $workf
609                                 stats=($(get_global_stats $tmpf))
610                                 rm $tmpf
611                                 if ((stats[0] <= 0)); then
612                                         if ((stats[0] < 0)); then
613                                                 str=$(printf "%17s " ERROR)
614                                         else
615                                                 str=$(printf "%17s " SHORT)
616                                         fi
617                                 else
618                                         str=$(awk "BEGIN {printf \"[%7.2f, %7.2f] \",\
619                                         (${stats[1]} * $actual_rsz)/1024,\
620                                         (${stats[2]} * $actual_rsz)/1024; exit}")
621                                 fi
622                                 print_summary -n "$str"
623                         done # $tests[]
624                         print_summary ""
625
626                         # destroy objects we created
627                         for ((idx = 0; idx < $ndevs; idx++)); do
628                                 host=${host_names[$idx]}
629                                 devno=${devnos[$idx]}
630                                 client_name="${host}:${client_names[$idx]}"
631                                 first_obj=${first_objs[$idx]}
632                                 echo "=============> Destroy $nobj on $client_name" >> $workf
633                                 destroy_objects $host $devno $first_obj $nobj $tmpf
634                                 cat $tmpf >> $workf
635                                 rm $tmpf
636                         done # $ndevs
637                 done # $thr
638         done # $nobj
639 done # $rsz
640 cleanup 0 $clean_srv_OSS $cleanup_oscs
641 exit 0