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