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