Whamcloud - gitweb
LU-6210 tests: Change positional struct initializers to C99
[fs/lustre-release.git] / lustre / tests / sanity-benchmark.sh
1 #!/bin/bash
2 #
3 # Test basic functionality of the filesystem using simple
4 # benchmarks.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env $@
14 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
15 init_logging
16
17 # bug number:
18 ALWAYS_EXCEPT="$SANITY_BENCHMARK_EXCEPT"
19
20 MAX_THREADS=${MAX_THREADS:-20}
21 RAMKB=`awk '/MemTotal:/ { print $2 }' /proc/meminfo`
22 if [ -z "$THREADS" ]; then
23         THREADS=$((RAMKB / 16384))
24         [ $THREADS -gt $MAX_THREADS ] && THREADS=$MAX_THREADS
25 fi
26 SIZE=${SIZE:-$((RAMKB * 2))}
27 RSIZE=${RSIZE:-512}
28
29 DEBUG_LVL=${DEBUG_LVL:-0}
30 DEBUG_OFF=${DEBUG_OFF:-"eval lctl set_param debug=\"$DEBUG_LVL\""}
31 DEBUG_ON=${DEBUG_ON:-"eval lctl set_param debug=0x33f0484"}
32 DIRECTIO=${DIRECTIO:-directio}
33
34 PIOSBIN=${PIOSBIN:-$(which pios 2> /dev/null || true)}
35
36 pios_THREADCOUNT=${pios_THREADCOUNT:-"1,8,40"}
37 [ "$SLOW" = "no" ] && pios_THREADCOUNT=8
38
39 pios_REGIONCOUNT=${pios_REGIONCOUNT:-1024}
40 pios_CHUNKSIZE=${pios_CHUNKSIZE:-1M}
41 pios_REGIONSIZE=${pios_REGIONSIZE:-8M}
42 pios_OFFSET=${pios_OFFSET:-16M}
43
44 [ "$SLOW" = "no" ] && EXCEPT_SLOW="iozone"
45
46 build_test_filter
47 check_and_setup_lustre
48
49 assert_DIR
50 rm -rf $DIR/[df][0-9]*
51
52 test_dbench() {
53     if ! which dbench > /dev/null 2>&1 ; then
54         skip_env "No dbench installed"
55         return
56     fi
57
58     local DBENCHDIR=$DIR/d0.$HOSTNAME
59     mkdir -p $DBENCHDIR
60     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
61     DB_THREADS=$((SPACE / 50000))
62     [ $THREADS -lt $DB_THREADS ] && DB_THREADS=$THREADS
63     
64     $DEBUG_OFF
65     myUID=$RUNAS_ID
66     myGID=$RUNAS_GID
67     myRUNAS=$RUNAS
68     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
69       { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
70     chown $myUID:$myGID $DBENCHDIR
71     local duration=""
72     [ "$SLOW" = "no" ] && duration=" -t 120"
73     if [ "$SLOW" != "no" -o $DB_THREADS -eq 1 ]; then
74         $myRUNAS bash rundbench -D $DBENCHDIR 1 $duration || error "dbench failed!"
75         $DEBUG_ON
76     fi
77     if [ $DB_THREADS -gt 1 ]; then
78         $DEBUG_OFF
79         $myRUNAS bash rundbench -D $DBENCHDIR $DB_THREADS $duration
80         $DEBUG_ON
81     fi
82     rm -rf $DBENCHDIR
83 }
84 run_test dbench "dbench"
85
86 test_bonnie() {
87     if ! which bonnie++ > /dev/null 2>&1; then
88         skip_env "No bonnie++ installed"
89         return 0
90     fi
91     local BONDIR=$DIR/d0.bonnie
92     mkdir -p $BONDIR
93     $LFS setstripe -c -1 $BONDIR
94     sync
95     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
96     local SPACE=$(( OSTCOUNT * MIN ))
97     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
98     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
99     $DEBUG_OFF
100     myUID=$RUNAS_ID
101     myGID=$RUNAS_GID
102     myRUNAS=$RUNAS
103     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
104       { myRUNAS="" && myUID=$UID && myGID=`id -$USER`; }
105     chown $myUID:$myGID $BONDIR         
106     $myRUNAS bonnie++ -f -r 0 -s$((SIZE / 1024)) -n 10 -u$myUID:$myGID -d$BONDIR
107     $DEBUG_ON
108 }
109 run_test bonnie "bonnie++"
110
111 test_iozone() {
112     if ! which iozone > /dev/null 2>&1; then
113         skip_env "No iozone installed"
114         return 0
115     fi
116
117     export O_DIRECT
118     
119     local IOZDIR=$DIR/d0.iozone
120     mkdir -p $IOZDIR
121     $LFS setstripe -c -1 $IOZDIR
122     sync
123     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
124     local SPACE=$(( OSTCOUNT * MIN ))
125     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
126     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
127     IOZONE_OPTS="-i 0 -i 1 -i 2 -e -+d -r $RSIZE"
128     IOZFILE="$IOZDIR/iozone"
129     IOZLOG=$TMP/iozone.log
130                 # $SPACE was calculated with all OSTs
131     $DEBUG_OFF
132     myUID=$RUNAS_ID
133     myGID=$RUNAS_GID
134     myRUNAS=$RUNAS
135     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
136         { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
137     chown $myUID:$myGID $IOZDIR
138     $myRUNAS iozone $IOZONE_OPTS -s $SIZE -f $IOZFILE 2>&1 | tee $IOZLOG
139     tail -1 $IOZLOG | grep -q complete || \
140         { error "iozone (1) failed" && return 1; }
141     rm -f $IOZLOG
142     $DEBUG_ON
143     
144     # check if O_DIRECT support is implemented in kernel
145     if [ -z "$O_DIRECT" ]; then
146         touch $DIR/f.iozone
147         if ! $DIRECTIO write $DIR/f.iozone 0 1; then
148             log "SKIP iozone DIRECT IO test"
149             O_DIRECT=no
150         fi
151         rm -f $DIR/f.iozone
152     fi
153     if [ "$O_DIRECT" != "no" -a "$IOZONE_DIR" != "no" ]; then
154         $DEBUG_OFF
155         $myRUNAS iozone -I $IOZONE_OPTS -s $SIZE -f $IOZFILE.odir 2>&1 | tee $IOZLOG
156         tail -1 $IOZLOG | grep -q complete || \
157             { error "iozone (2) failed" && return 1; }
158         rm -f $IOZLOG
159         $DEBUG_ON
160     fi
161
162     SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
163     IOZ_THREADS=$((SPACE / SIZE * 2 / 3 ))
164     [ $THREADS -lt $IOZ_THREADS ] && IOZ_THREADS=$THREADS
165     IOZVER=`iozone -v | awk '/Revision:/ {print $3}' | tr -d .`
166     if [ "$IOZ_THREADS" -gt 1 -a "$IOZVER" -ge 3145 ]; then
167         $LFS setstripe -c -1 $IOZDIR
168         $DEBUG_OFF
169         THREAD=1
170         IOZFILE=" "
171         while [ $THREAD -le $IOZ_THREADS ]; do
172             IOZFILE="$IOZFILE $IOZDIR/iozone.$THREAD"
173             THREAD=$((THREAD + 1))
174         done
175         $myRUNAS iozone $IOZONE_OPTS -s $((SIZE / IOZ_THREADS)) -t $IOZ_THREADS -F $IOZFILE 2>&1 | tee $IOZLOG
176         tail -1 $IOZLOG | grep -q complete || \
177             { error "iozone (3) failed" && return 1; }
178         rm -f $IOZLOG
179         $DEBUG_ON
180     elif [ $IOZVER -lt 3145 ]; then
181         VER=`iozone -v | awk '/Revision:/ { print $3 }'`
182         echo "iozone $VER too old for multi-thread test"
183     fi
184 }
185 run_test iozone "iozone"
186
187 test_fsx() {
188     local testfile=$DIR/f0.fsxfile
189     FSX_SIZE=$SIZE
190     FSX_COUNT=1000
191     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
192     [ $SPACE -lt $FSX_SIZE ] && FSX_SIZE=$((SPACE * 3 / 4))
193     $DEBUG_OFF
194     FSX_SEED=${FSX_SEED:-$RANDOM}
195     rm -f $testfile
196     $LFS setstripe -c -1 $testfile
197     CMD="fsx -c 50 -p 1000 -S $FSX_SEED -P $TMP -l $FSX_SIZE \
198         -N $((FSX_COUNT * 100)) $FSXOPT $testfile"
199     echo "Using: $CMD"
200     $CMD || error "fsx failed"
201     rm -f $testfile
202     $DEBUG_ON
203 }
204 run_test fsx "fsx"
205
206
207 ############################################################
208 # PIOS
209 #
210
211 iterpr_KMGT () {
212     local str=$1
213     local num=${str:0:${#str}-1}
214     case ${str:${#str}-1} in
215         k|K ) num=$((num << 10));; #
216         m|M ) num=$((num << 20));; # emacs is confsued by the <<  and
217         g|G ) num=$((num << 30));; # these comments help it out.
218         t|T ) num=$((num << 40));; #
219           * ) num=$str;;
220     esac
221     echo $num
222 }
223
224 pios_file_size () {
225     # pios.c: check_device_size ()
226     # /* Adding 10% to total test size for filesystem overhead */
227     # size = size + (double)(size) * (double) (0.1);
228     # pios.c: set_actual_streams ()
229     #  total_test_size = runarg->regioncount * runarg->regionsize
230
231     local size=$(($(iterpr_KMGT $pios_REGIONCOUNT) * \
232                   $(iterpr_KMGT $pios_REGIONSIZE) ))
233     echo $size
234 }
235
236 space_check () {
237         local testdir=$DIR/$tdir
238         local stripe=$($LFS getstripe -c $testdir)
239         local min_space_available=0
240
241         # if stripe_count = 1 the size should be less than min ost size,
242         # bug 24294
243         min_space_available=$(lfs df | grep "^$FSNAME-OST" | \
244                 awk '{print $4}' | sort -un | head -1)
245         local space=$((min_space_available * OSTCOUNT))
246
247         [ $stripe -eq 1 ] && space=$(min_ost_size)
248
249         local size=$(pios_file_size)
250         size=$(( size + size / 10 ))
251         # we can not use pios --cleanup|-x because we need the files exist for
252         # pios --verify, so, we need space available for each of
253         # pios_THREADCOUNT value run
254         local num_runs=$(echo ${pios_THREADCOUNT//,/ } | wc -w)
255         size=$(( size * $num_runs))
256         space=$((space * 1024))
257         echo size=$size space=$space
258         if [ $space -le $size ]; then
259                 local ratio=$(( size / space + 1 ))
260                 echo "Need free space atleast $size, \
261                         available $space, ratio=$ratio"
262                 local rgcount=$(( pios_REGIONCOUNT / ratio ))
263                 echo "reducing pios_REGIONCOUNT=$pios_REGIONCOUNT on $ratio"
264                 if [ $rgcount -eq 0 ]; then
265                         echo "fs is too small, \
266                                 reduced pios_REGIONCOUNT=$rgcount"
267                         return 10
268                 fi
269                 pios_REGIONCOUNT=$(( pios_REGIONCOUNT / ratio ))
270                 echo using pios_REGIONCOUNT=$pios_REGIONCOUNT \
271                         size=$(pios_file_size)
272         fi
273 }
274
275 pios_setup() { 
276     local testdir=$DIR/$tdir
277     mkdir -p $testdir
278
279     stripes=1
280     [ "$1" == "--stripe" ] && stripes=-1
281     $LFS setstripe $testdir -c $stripes
282     echo "Test directory $testdir stripe count: $stripes"
283 }
284
285 pios_cleanup() {
286     local rc=${1:-0}
287     local testdir=$DIR/$tdir
288     if [ $rc -eq 0 ]; then
289         echo cleanup: testdir=$testdir rc=$rc
290         rm -rf $testdir
291         wait_delete_completed || true
292     fi
293 }
294
295 run_pios () {
296     local testdir=$DIR/$tdir
297     local cmd="$PIOSBIN  -t $pios_THREADCOUNT -n $pios_REGIONCOUNT \
298                          -c $pios_CHUNKSIZE -s $pios_REGIONSIZE    \
299                          -o $pios_OFFSET $@ -p $testdir"
300     
301     if [ ! -d $testdir ]; then  
302         error "No test directory created, setup_pios must have failed"
303         return 20
304     fi
305
306     log "$cmd"
307
308     local rc=0
309     eval $cmd
310     rc=$?
311
312     return $rc
313 }
314
315 test_pios_ssf() {
316     if  [ -z "$PIOSBIN" ]; then
317         skip_env "$0 : pios not found PIOSBIN=$PIOSBIN"
318         return
319     fi
320
321     local rc=0
322     pios_setup --stripe || return
323     if ! space_check; then
324         skip_env "not enough space"
325         pios_cleanup
326         return 0
327     fi
328     run_pios || return
329     run_pios  --verify || rc=$? 
330     pios_cleanup $rc
331     return $rc
332 }
333 run_test pios_ssf "pios shared single file"
334
335 test_pios_fpp() {
336     if  [ -z "$PIOSBIN" ]; then
337         skip_env "pios not found PIOSBIN=$PIOSBIN"
338         return
339     fi
340
341     local rc=0
342     pios_setup || return
343     if ! space_check; then
344         skip_env "not enough space"
345         pios_cleanup
346         return 0
347     fi
348     run_pios -L fpp || return
349     run_pios -L fpp --verify || rc=$?
350     pios_cleanup $rc
351     return $rc
352 }
353 run_test pios_fpp "pios file per process"
354
355 complete $SECONDS
356 check_and_cleanup_lustre
357 exit_status