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