Whamcloud - gitweb
LU-6142 tests: Fix style issues for mkdirmany.c
[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 # bug number:
18 ALWAYS_EXCEPT="$SANITY_BENCHMARK_EXCEPT"
19
20 MAX_THREADS=${MAX_THREADS:-20}
21 RAMKB=`awk '/MemTotal:/ { print $2 }' /proc/meminfo`
22 if [ -z "$THREADS" ]; then
23         THREADS=$((RAMKB / 16384))
24         [ $THREADS -gt $MAX_THREADS ] && THREADS=$MAX_THREADS
25 fi
26 SIZE=${SIZE:-$((RAMKB * 2))}
27 RSIZE=${RSIZE:-512}
28
29 DEBUG_LVL=${DEBUG_LVL:-0}
30 DEBUG_OFF=${DEBUG_OFF:-"eval lctl set_param debug=\"$DEBUG_LVL\""}
31 DEBUG_ON=${DEBUG_ON:-"eval lctl set_param debug=0x33f0484"}
32 DIRECTIO=${DIRECTIO:-directio}
33
34 [ "$SLOW" = "no" ] && EXCEPT_SLOW="iozone"
35
36 build_test_filter
37 check_and_setup_lustre
38
39 assert_DIR
40 rm -rf $DIR/[df][0-9]*
41
42 test_dbench() {
43     if ! which dbench > /dev/null 2>&1 ; then
44         skip_env "No dbench installed"
45         return
46     fi
47
48     local DBENCHDIR=$DIR/d0.$HOSTNAME
49     mkdir -p $DBENCHDIR
50     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
51     DB_THREADS=$((SPACE / 50000))
52     [ $THREADS -lt $DB_THREADS ] && DB_THREADS=$THREADS
53     
54     $DEBUG_OFF
55     myUID=$RUNAS_ID
56     myGID=$RUNAS_GID
57     myRUNAS=$RUNAS
58     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
59       { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
60     chown $myUID:$myGID $DBENCHDIR
61     local duration=""
62     [ "$SLOW" = "no" ] && duration=" -t 120"
63     if [ "$SLOW" != "no" -o $DB_THREADS -eq 1 ]; then
64         $myRUNAS bash rundbench -D $DBENCHDIR 1 $duration || error "dbench failed!"
65         $DEBUG_ON
66     fi
67     if [ $DB_THREADS -gt 1 ]; then
68         $DEBUG_OFF
69         $myRUNAS bash rundbench -D $DBENCHDIR $DB_THREADS $duration
70         $DEBUG_ON
71     fi
72     rm -rf $DBENCHDIR
73 }
74 run_test dbench "dbench"
75
76 test_bonnie() {
77     if ! which bonnie++ > /dev/null 2>&1; then
78         skip_env "No bonnie++ installed"
79         return 0
80     fi
81     local BONDIR=$DIR/d0.bonnie
82     mkdir -p $BONDIR
83     $LFS setstripe -c -1 $BONDIR
84     sync
85     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
86     local SPACE=$(( OSTCOUNT * MIN ))
87     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
88     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
89     $DEBUG_OFF
90     myUID=$RUNAS_ID
91     myGID=$RUNAS_GID
92     myRUNAS=$RUNAS
93     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
94       { myRUNAS="" && myUID=$UID && myGID=`id -$USER`; }
95     chown $myUID:$myGID $BONDIR         
96     $myRUNAS bonnie++ -f -r 0 -s$((SIZE / 1024)) -n 10 -u$myUID:$myGID -d$BONDIR
97     $DEBUG_ON
98 }
99 run_test bonnie "bonnie++"
100
101 test_iozone() {
102     if ! which iozone > /dev/null 2>&1; then
103         skip_env "No iozone installed"
104         return 0
105     fi
106
107     export O_DIRECT
108     
109     local IOZDIR=$DIR/d0.iozone
110     wait_delete_completed || true
111     mkdir -p $IOZDIR
112     $LFS setstripe -c -1 $IOZDIR
113     sync
114     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
115     local SPACE=$(( OSTCOUNT * MIN ))
116     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
117     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
118     IOZONE_OPTS="-i 0 -i 1 -i 2 -e -+d -r $RSIZE"
119     IOZFILE="$IOZDIR/iozone"
120     IOZLOG=$TMP/iozone.log
121                 # $SPACE was calculated with all OSTs
122     $DEBUG_OFF
123     myUID=$RUNAS_ID
124     myGID=$RUNAS_GID
125     myRUNAS=$RUNAS
126     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
127         { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
128     chown $myUID:$myGID $IOZDIR
129     $myRUNAS iozone $IOZONE_OPTS -s $SIZE -f $IOZFILE 2>&1 | tee $IOZLOG
130     tail -1 $IOZLOG | grep -q complete || \
131         { error "iozone (1) failed" && return 1; }
132     rm -f $IOZLOG
133     wait_delete_completed || true
134     $DEBUG_ON
135     
136     # check if O_DIRECT support is implemented in kernel
137     if [ -z "$O_DIRECT" ]; then
138         touch $DIR/f.iozone
139         if ! $DIRECTIO write $DIR/f.iozone 0 1; then
140             log "SKIP iozone DIRECT IO test"
141             O_DIRECT=no
142         fi
143         rm -f $DIR/f.iozone
144         wait_delete_completed || true
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         wait_delete_completed || true
153         $DEBUG_ON
154     fi
155
156     SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
157     IOZ_THREADS=$((SPACE / SIZE * 2 / 3 ))
158     [ $THREADS -lt $IOZ_THREADS ] && IOZ_THREADS=$THREADS
159     IOZVER=`iozone -v | awk '/Revision:/ {print $3}' | tr -d .`
160     if [ "$IOZ_THREADS" -gt 1 -a "$IOZVER" -ge 3145 ]; then
161         $LFS setstripe -c -1 $IOZDIR
162         $DEBUG_OFF
163         THREAD=1
164         IOZFILE=" "
165         while [ $THREAD -le $IOZ_THREADS ]; do
166             IOZFILE="$IOZFILE $IOZDIR/iozone.$THREAD"
167             THREAD=$((THREAD + 1))
168         done
169         $myRUNAS iozone $IOZONE_OPTS -s $((SIZE / IOZ_THREADS)) -t $IOZ_THREADS -F $IOZFILE 2>&1 | tee $IOZLOG
170         tail -1 $IOZLOG | grep -q complete || \
171             { error "iozone (3) failed" && return 1; }
172         rm -f $IOZLOG
173         wait_delete_completed || true
174         $DEBUG_ON
175     elif [ $IOZVER -lt 3145 ]; then
176         VER=`iozone -v | awk '/Revision:/ { print $3 }'`
177         echo "iozone $VER too old for multi-thread test"
178     fi
179 }
180 run_test iozone "iozone"
181
182 test_fsx() {
183     local testfile=$DIR/f0.fsxfile
184     FSX_SIZE=$SIZE
185     FSX_COUNT=1000
186     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
187     [ $SPACE -lt $FSX_SIZE ] && FSX_SIZE=$((SPACE * 3 / 4))
188     $DEBUG_OFF
189     FSX_SEED=${FSX_SEED:-$RANDOM}
190     rm -f $testfile
191     $LFS setstripe -c -1 $testfile
192     CMD="fsx -c 50 -p 1000 -S $FSX_SEED -P $TMP -l $FSX_SIZE \
193         -N $((FSX_COUNT * 100)) $FSXOPT $testfile"
194     echo "Using: $CMD"
195     $CMD || error "fsx failed"
196     rm -f $testfile
197     $DEBUG_ON
198 }
199 run_test fsx "fsx"
200
201 complete $SECONDS
202 check_and_cleanup_lustre
203 exit_status