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