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