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