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