Whamcloud - gitweb
a43b860017868b08a4edc063656c52358951bf2b
[fs/lustre-release.git] / lustre / tests / scrub-performance.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 ALWAYS_EXCEPT="$SCRUB_PERFORMANCE_EXCEPT"
7 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
14 init_logging
15
16 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
17         skip "OI scrub performance only for ldiskfs" && exit 0
18 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.2.90) ]] &&
19         skip "Need MDS version at least 2.2.90" && exit 0
20 require_dsh_mds || exit 0
21 [ "$SLOW" = "no" ] && skip "skip scrub performance test under non-SLOW mode"
22
23
24 NTHREADS=${NTHREADS:-0}
25 UNIT=${UNIT:-1048576}
26 BACKUP=${BACKUP:-0}
27 MINCOUNT=${MINCOUNT:-8192}
28 MAXCOUNT=${MAXCOUNT:-32768}
29 FACTOR=${FACTOR:-2}
30
31 RCMD="do_facet ${SINGLEMDS}"
32 RLCTL="${RCMD} ${LCTL}"
33 MDT_DEV="${FSNAME}-MDT0000"
34 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
35 SHOW_SCRUB="${RLCTL} get_param -n osd-ldiskfs.${MDT_DEV}.oi_scrub"
36 remote_mds && ECHOCMD=${RCMD} || ECHOCMD="eval"
37
38 if [ ${NTHREADS} -eq 0 ]; then
39         CPUCORE=$(${RCMD} cat /proc/cpuinfo | grep "processor.*:" | wc -l)
40         NTHREADS=$((CPUCORE * 2))
41 fi
42
43 stopall
44 do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
45 reformat_external_journal ${SINGLEMDS}
46 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype ldiskfs \
47         --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null || exit 2
48
49 scrub_attach() {
50         ${ECHOCMD} "${LCTL} <<-EOF
51                 attach echo_client scrub-MDT0000 scrub-MDT0000_UUID
52                 setup ${MDT_DEV} mdd
53         EOF"
54 }
55
56 scrub_detach() {
57         ${ECHOCMD} "${LCTL} <<-EOF
58                 device scrub-MDT0000
59                 cleanup
60                 detach
61         EOF"
62 }
63
64 scrub_create() {
65         local echodev=$(${RLCTL} dl | grep echo_client|awk '{print $1}')
66         local j
67
68         ${ECHOCMD} "${LCTL} <<-EOF
69                 cfg_device ${echodev}
70                 test_mkdir ${tdir}
71         EOF"
72
73         for ((j=1; j<${threads}; j++)); do
74                 ${ECHOCMD} "${LCTL} <<-EOF
75                         cfg_device ${echodev}
76                         test_mkdir ${tdir}${j}
77                 EOF"
78         done
79
80         ${ECHOCMD} "${LCTL} <<-EOF
81                 cfg_device ${echodev}
82                 --threads ${threads} 0 ${echodev} test_create \
83                 -d ${tdir} -D ${threads} -b ${lbase} -c 0 -n ${usize}
84         EOF"
85 }
86
87 scrub_cleanup() {
88         do_rpc_nodes $(facet_active_host $SINGLEMDS) unload_modules
89         formatall
90 }
91
92 scrub_create_nfiles() {
93         local total=$1
94         local lbase=$2
95         local threads=$3
96         local ldir="/test-${lbase}"
97         local cycle=0
98         local count=${UNIT}
99
100         while true; do
101                 [ ${count} -eq 0 -o  ${count} -gt ${total} ] && count=${total}
102                 local usize=$((count / NTHREADS))
103                 [ ${usize} -eq 0 ] && break
104                 local tdir=${ldir}-${cycle}-
105
106                 echo "[cycle: ${cycle}] [threads: ${threads}]"\
107                      "[files: ${count}] [basedir: ${tdir}]"
108                 start ${SINGLEMDS} $MDT_DEVNAME $MDS_MOUNT_OPTS ||
109                         error "Fail to start MDS!"
110                 scrub_attach
111                 scrub_create
112                 scrub_detach
113                 stop ${SINGLEMDS} || error "Fail to stop MDS!"
114
115                 total=$((total - usize * NTHREADS))
116                 [ ${total} -eq 0 ] && break
117                 lbase=$((lbase + usize))
118                 cycle=$((cycle + 1))
119         done
120 }
121
122 build_test_filter
123
124 test_0() {
125         local BASECOUNT=0
126         local i
127
128         for ((i=$MINCOUNT; i<=$MAXCOUNT; i=$((i * FACTOR)))); do
129                 local nfiles=$((i - BASECOUNT))
130                 local stime=$(date +%s)
131
132                 echo "+++ start to create for ${i} files set at: $(date) +++"
133                 scrub_create_nfiles ${nfiles} ${BASECOUNT} ${NTHREADS} ||
134                         error "Fail to create files!"
135                 echo "+++ end to create for ${i} files set at: $(date) +++"
136                 local etime=$(date +%s)
137                 local delta=$((etime - stime))
138                 [ $delta -gt 0 ] || delta=1
139                 echo "create ${nfiles} files used ${delta} seconds"
140                 echo "create speed is $((nfiles / delta))/sec"
141
142                 BASECOUNT=${i}
143                 if [ ${BACKUP} -ne 0 ]; then
144                         stime=$(date +%s)
145                         echo "backup/restore ${i} files start at: $(date)"
146                         mds_backup_restore $SINGLEMDS ||
147                                 error "Fail to backup/restore!"
148                         echo "backup/restore ${i} files end at: $(date)"
149                         etime=$(date +%s)
150                         delta=$((etime - stime))
151                         [ $delta -gt 0 ] || delta=1
152                         echo "backup/restore ${i} files used ${delta} seconds"
153                         echo "backup/restore speed is $((i / delta))/sec"
154                 else
155                         mds_remove_ois $SINGLEMDS ||
156                                 error "Fail to remove/recreate!"
157                 fi
158
159                 echo "--- start to rebuild OI for $i files set at: $(date) ---"
160                 start ${SINGLEMDS} $MDT_DEVNAME $MDS_MOUNT_OPTS > /dev/null ||
161                         error "Fail to start MDS!"
162
163                 while true; do
164                         local STATUS=$($SHOW_SCRUB |
165                                         awk '/^status/ { print $2 }')
166                         [ "$STATUS" == "completed" ] && break
167                         sleep 3 # check status every 3 seconds
168                 done
169
170                 echo "--- end to rebuild OI for ${i} files set at: $(date) ---"
171                 local RTIME=$($SHOW_SCRUB | awk '/^run_time/ { print $2 }')
172                 echo "rebuild OI for ${i} files used ${RTIME} seconds"
173                 local SPEED=$($SHOW_SCRUB | awk '/^average_speed/ { print $2 }')
174                 echo "rebuild speed is ${SPEED}/sec"
175                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
176         done
177 }
178 run_test 0 "OI scrub performance test"
179
180 # cleanup the system at last
181 scrub_cleanup
182 complete $SECONDS
183 exit_status