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