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