Whamcloud - gitweb
LU-6913 test: fix conf-sanity test_30b defect
[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
240     # if stripe_count = 1 the size should be less than min ost size, bug 24294
241     local space=$(lfs_df $testdir | grep "summary"  | awk '{print $4}')
242     [ $stripe -eq 1 ] && space=$(min_ost_size)
243
244     local size=$(pios_file_size)
245     size=$(( size + size / 10 ))
246     # we can not use pios --cleanup|-x because we need the files exist for pios --verify,
247     # so, we need space available for each of pios_THREADCOUNT value run
248     local num_runs=$(echo ${pios_THREADCOUNT//,/ } | wc -w)
249     size=$(( size * $num_runs))
250     space=$((space * 1024))
251     echo size=$size space=$space
252     if [ $space -le $size ]; then
253         local ratio=$(( size / space + 1 ))
254         echo "Need free space atleast $size, available $space, ratio=$ratio"
255         local rgcount=$(( pios_REGIONCOUNT / ratio ))
256         echo "reducing pios_REGIONCOUNT=$pios_REGIONCOUNT on $ratio"
257         if [ $rgcount -eq 0 ]; then
258             echo "fs is too small, reduced pios_REGIONCOUNT=$rgcount"
259             return 10
260         fi
261         pios_REGIONCOUNT=$(( pios_REGIONCOUNT / ratio ))
262         echo using pios_REGIONCOUNT=$pios_REGIONCOUNT size=$(pios_file_size)
263     fi
264 }
265
266 pios_setup() { 
267     local testdir=$DIR/$tdir
268     mkdir -p $testdir
269
270     stripes=1
271     [ "$1" == "--stripe" ] && stripes=-1
272     $LFS setstripe $testdir -c $stripes
273     echo "Test directory $testdir stripe count: $stripes"
274 }
275
276 pios_cleanup() {
277     local rc=${1:-0}
278     local testdir=$DIR/$tdir
279     if [ $rc -eq 0 ]; then
280         echo cleanup: testdir=$testdir rc=$rc
281         rm -rf $testdir
282         wait_delete_completed || true
283     fi
284 }
285
286 run_pios () {
287     local testdir=$DIR/$tdir
288     local cmd="$PIOSBIN  -t $pios_THREADCOUNT -n $pios_REGIONCOUNT \
289                          -c $pios_CHUNKSIZE -s $pios_REGIONSIZE    \
290                          -o $pios_OFFSET $@ -p $testdir"
291     
292     if [ ! -d $testdir ]; then  
293         error "No test directory created, setup_pios must have failed"
294         return 20
295     fi
296
297     log "$cmd"
298
299     local rc=0
300     eval $cmd
301     rc=$?
302
303     return $rc
304 }
305
306 test_pios_ssf() {
307     if  [ -z "$PIOSBIN" ]; then
308         skip_env "$0 : pios not found PIOSBIN=$PIOSBIN"
309         return
310     fi
311
312     local rc=0
313     pios_setup --stripe || return
314     if ! space_check; then
315         skip_env "not enough space"
316         pios_cleanup
317         return 0
318     fi
319     run_pios || return
320     run_pios  --verify || rc=$? 
321     pios_cleanup $rc
322     return $rc
323 }
324 run_test pios_ssf "pios shared single file"
325
326 test_pios_fpp() {
327     if  [ -z "$PIOSBIN" ]; then
328         skip_env "pios not found PIOSBIN=$PIOSBIN"
329         return
330     fi
331
332     local rc=0
333     pios_setup || return
334     if ! space_check; then
335         skip_env "not enough space"
336         pios_cleanup
337         return 0
338     fi
339     run_pios -L fpp || return
340     run_pios -L fpp --verify || rc=$?
341     pios_cleanup $rc
342     return $rc
343 }
344 run_test pios_fpp "pios file per process"
345
346 complete $SECONDS
347 check_and_cleanup_lustre
348 exit_status