Whamcloud - gitweb
b=23051 improve summary of acc-sm to include test times
[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     echo Using FSX_SEED=$FSX_SEED FSX_SIZE=$FSX_SIZE FSX_COUNT=$FSX_COUNT
197     fsx -c 50 -p 1000 -S $FSX_SEED -P $TMP -l $FSX_SIZE \
198         -N $(($FSX_COUNT * 100)) $DIR/fsxfile
199     $DEBUG_ON
200 }
201 run_test fsx "fsx"
202
203
204 ############################################################
205 # PIOS
206 #
207
208 iterpr_KMGT () {
209     local str=$1
210     local num=${str:0:${#str}-1}
211     case ${str:${#str}-1} in
212         k|K ) num=$((num << 10));; #
213         m|M ) num=$((num << 20));; # emacs is confsued by the <<  and
214         g|G ) num=$((num << 30));; # these comments help it out.
215         t|T ) num=$((num << 40));; #
216           * ) num=$str;;
217     esac
218     echo $num
219 }
220
221 pios_file_size () {
222     # pios.c: check_device_size ()
223     # /* Adding 10% to total test size for filesystem overhead */
224     # size = size + (double)(size) * (double) (0.1);
225     # pios.c: set_actual_streams ()
226     #  total_test_size = runarg->regioncount * runarg->regionsize
227
228     local size=$(($(iterpr_KMGT $pios_REGIONCOUNT) * \
229                   $(iterpr_KMGT $pios_REGIONSIZE) ))
230     echo $size
231 }
232
233 space_check () {
234     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
235     local size=$(pios_file_size)
236     size=$(( size + size / 10 ))
237     # we can not use pios --cleanup|-x because we need the files exist for pios --verify,
238     # so, we need space available for each of pios_THREADCOUNT value run
239     local num_runs=$(echo ${pios_THREADCOUNT//,/ } | wc -w)
240     size=$(( size * $num_runs))
241     space=$((space * 1024))
242     echo size=$size space=$space
243     if [ $space -le $size ]; then
244         local ratio=$(( size / space + 1 ))
245         echo "Need free space atleast $size, available $space, ratio=$ratio"
246         local rgcount=$(( pios_REGIONCOUNT / ratio ))
247         echo "reducing pios_REGIONCOUNT=$pios_REGIONCOUNT on $ratio"
248         if [ $rgcount -eq 0 ]; then
249             echo "fs is too small, reduced pios_REGIONCOUNT=$rgcount"
250             return 10
251         fi
252         pios_REGIONCOUNT=$(( pios_REGIONCOUNT / ratio ))
253         echo using pios_REGIONCOUNT=$pios_REGIONCOUNT size=$(pios_file_size)
254     fi
255 }
256
257 pios_setup() { 
258     local testdir=$DIR/$tdir
259     mkdir -p $testdir
260
261     stripes=1
262     [ "$1" == "--stripe" ] && stripes=-1
263     $LFS setstripe $testdir -c $stripes
264     echo "Test directory $testdir stripe count: $stripes"
265 }
266
267 pios_cleanup() {
268     local rc=$1
269     local testdir=$DIR/$tdir
270     if [ $rc -eq 0 ]; then
271         echo cleanup: testdir=$testdir rc=$rc
272         rm -rf $testdir
273         wait_delete_completed || true
274     fi
275 }
276
277 run_pios () {
278     local testdir=$DIR/$tdir
279     local cmd="$PIOSBIN  -t $pios_THREADCOUNT -n $pios_REGIONCOUNT \
280                          -c $pios_CHUNKSIZE -s $pios_REGIONSIZE    \
281                          -o $pios_OFFSET $@ -p $testdir"
282     
283     if [ ! -d $testdir ]; then  
284         error "No test directory created, setup_pios must have failed"
285         return 20
286     fi
287
288     log "$cmd"
289
290     local rc=0
291     eval $cmd
292     rc=$?
293
294     return $rc
295 }
296
297 test_pios_ssf() {
298     if  [ -z "$PIOSBIN" ]; then
299         skip_env "$0 : pios not found PIOSBIN=$PIOSBIN"
300         return
301     fi
302
303     local rc=0
304     space_check || { skip_env "not enough space" && return 0; }
305     pios_setup --stripe || return
306     run_pios || return
307     run_pios  --verify || rc=$? 
308     pios_cleanup $rc
309     return $rc
310 }
311 run_test pios_ssf "pios shared single file"
312
313 test_pios_fpp() {
314     if  [ -z "$PIOSBIN" ]; then
315         skip_env "pios not found PIOSBIN=$PIOSBIN"
316         return
317     fi
318
319     local rc=0
320     space_check || { skip_env "not enough space" && return 0; }
321     pios_setup || return
322     run_pios -L fpp || return
323     run_pios -L fpp --verify || rc=$?
324     pios_cleanup $rc
325     return $rc
326 }
327 run_test pios_fpp "pios file per process"
328
329 complete $(basename $0) $SECONDS
330 check_and_cleanup_lustre
331 exit_status