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