Whamcloud - gitweb
b=20331
[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 [ "$SLOW" = "no" ] && EXCEPT_SLOW="iozone"
28
29
30 build_test_filter
31 check_and_setup_lustre
32
33 test_dbench() {
34     if ! which dbench > /dev/null 2>&1 ; then
35         skip "No dbench installed"
36         return
37     fi
38
39     DBENCHDIR=$MOUNT/d0.$HOSTNAME
40     mkdir -p $DBENCHDIR
41     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
42     DB_THREADS=$((SPACE / 50000))
43     [ $THREADS -lt $DB_THREADS ] && DB_THREADS=$THREADS
44     
45     $DEBUG_OFF
46     myUID=$RUNAS_ID
47     myRUNAS=$RUNAS
48     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myUID $myRUNAS || { myRUNAS="" && myUID=$UID; }
49     chown $myUID:$myUID $DBENCHDIR
50     local duration=""
51     [ "$SLOW" = "no" ] && duration=" -t 120"
52     if [ "$SLOW" != "no" -o $DB_THREADS -eq 1 ]; then
53         $myRUNAS bash rundbench -D $DBENCHDIR 1 $duration || error "dbench failed!"
54         $DEBUG_ON
55     fi
56     if [ $DB_THREADS -gt 1 ]; then
57         $DEBUG_OFF
58         $myRUNAS bash rundbench -D $DBENCHDIR $DB_THREADS $duration
59         $DEBUG_ON
60     fi
61     rm -rf $DBENCHDIR
62 }
63 run_test dbench "dbench"
64
65 test_bonnie() {
66     if ! which bonnie++ > /dev/null 2>&1; then
67         skip "No bonnie++ installed"
68         return 0
69     fi
70     BONDIR=$MOUNT/d0.bonnie
71     mkdir -p $BONDIR
72     $LFS setstripe -c -1 $BONDIR
73     sync
74     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
75     local SPACE=$(( OSTCOUNT * MIN ))
76     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
77     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
78     $DEBUG_OFF
79     myUID=$RUNAS_ID
80     myRUNAS=$RUNAS
81     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myUID $myRUNAS || { myRUNAS="" && myUID=$UID; }
82     chown $myUID:$myUID $BONDIR         
83     $myRUNAS bonnie++ -f -r 0 -s$((SIZE / 1024)) -n 10 -u$myUID:$myUID -d$BONDIR
84     $DEBUG_ON
85 }
86 run_test bonnie "bonnie++"
87
88 test_iozone() {
89     if ! which iozone > /dev/null 2>&1; then
90         skip "No iozone installed"
91         return 0
92     fi
93
94     export O_DIRECT
95     
96     IOZDIR=$MOUNT/d0.iozone
97     mkdir -p $IOZDIR
98     $LFS setstripe -c -1 $IOZDIR
99     sync
100     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
101     local SPACE=$(( OSTCOUNT * MIN ))
102     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
103     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
104     IOZONE_OPTS="-i 0 -i 1 -i 2 -e -+d -r $RSIZE"
105     IOZFILE="$IOZDIR/iozone"
106     IOZLOG=$TMP/iozone.log
107                 # $SPACE was calculated with all OSTs
108     $DEBUG_OFF
109     myUID=$RUNAS_ID
110     myRUNAS=$RUNAS
111     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myUID $myRUNAS || { myRUNAS="" && myUID=$UID; }
112     chown $myUID:$myUID $IOZDIR
113     $myRUNAS iozone $IOZONE_OPTS -s $SIZE -f $IOZFILE 2>&1 | tee $IOZLOG
114     tail -1 $IOZLOG | grep -q complete || \
115         { error "iozone (1) failed" && return 1; }
116     rm -f $IOZLOG
117     $DEBUG_ON
118     
119     # check if O_DIRECT support is implemented in kernel
120     if [ -z "$O_DIRECT" ]; then
121         touch $MOUNT/f.iozone
122         if ! ./directio write $MOUNT/f.iozone 0 1; then
123             log "SKIP iozone DIRECT IO test"
124             O_DIRECT=no
125         fi
126         rm -f $MOUNT/f.iozone
127     fi
128     if [ "$O_DIRECT" != "no" -a "$IOZONE_DIR" != "no" ]; then
129         $DEBUG_OFF
130         $myRUNAS iozone -I $IOZONE_OPTS -s $SIZE -f $IOZFILE.odir 2>&1 | tee $IOZLOG
131         tail -1 $IOZLOG | grep -q complete || \
132             { error "iozone (2) failed" && return 1; }
133         rm -f $IOZLOG
134         $DEBUG_ON
135     fi
136
137     SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
138     IOZ_THREADS=$((SPACE / SIZE * 2 / 3 ))
139     [ $THREADS -lt $IOZ_THREADS ] && IOZ_THREADS=$THREADS
140     IOZVER=`iozone -v | awk '/Revision:/ {print $3}' | tr -d .`
141     if [ "$IOZ_THREADS" -gt 1 -a "$IOZVER" -ge 3145 ]; then
142         $LFS setstripe -c -1 $IOZDIR
143         $DEBUG_OFF
144         THREAD=1
145         IOZFILE=" "
146         while [ $THREAD -le $IOZ_THREADS ]; do
147             IOZFILE="$IOZFILE $IOZDIR/iozone.$THREAD"
148             THREAD=$((THREAD + 1))
149         done
150         $myRUNAS iozone $IOZONE_OPTS -s $((SIZE / IOZ_THREADS)) -t $IOZ_THREADS -F $IOZFILE 2>&1 | tee $IOZLOG
151         tail -1 $IOZLOG | grep -q complete || \
152             { error "iozone (3) failed" && return 1; }
153         rm -f $IOZLOG
154         $DEBUG_ON
155     elif [ $IOZVER -lt 3145 ]; then
156         VER=`iozone -v | awk '/Revision:/ { print $3 }'`
157         echo "iozone $VER too old for multi-thread test"
158     fi
159 }
160 run_test iozone "iozone"
161
162 test_fsx() {
163     FSX_SIZE=$SIZE
164     FSX_COUNT=1000
165     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
166     [ $SPACE -lt $FSX_SIZE ] && FSX_SIZE=$((SPACE * 3 / 4))
167     $DEBUG_OFF
168     FSX_SEED=${FSX_SEED:-$RANDOM}
169     rm -f $MOUNT/fsxfile
170     $LFS setstripe -c -1 $MOUNT/fsxfile
171     echo Using FSX_SEED=$FSX_SEED FSX_SIZE=$FSX_SIZE FSX_COUNT=$FSX_COUNT
172     fsx -c 50 -p 1000 -S $FSX_SEED -P $TMP -l $FSX_SIZE \
173         -N $(($FSX_COUNT * 100)) $MOUNT/fsxfile
174     $DEBUG_ON
175 }
176 run_test fsx "fsx"
177
178 equals_msg `basename $0`: test complete, cleaning up
179 check_and_cleanup_lustre
180 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true