-
Notifications
You must be signed in to change notification settings - Fork 170
/
fs_bench.sh
executable file
·232 lines (187 loc) · 5.65 KB
/
fs_bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
set -e
if ! command -v fio &> /dev/null; then
echo "fio must be installed to run this benchmark"
exit 1
fi
if [[ -z "${S3_BUCKET_NAME}" ]]; then
echo "Set S3_BUCKET_NAME to run this benchmark"
exit 1
fi
if [[ -z "${S3_BUCKET_TEST_PREFIX}" ]]; then
echo "Set S3_BUCKET_TEST_PREFIX to run this benchmark"
exit 1
fi
if [[ -z "${S3_BUCKET_BENCH_FILE}" ]]; then
echo "Set S3_BUCKET_BENCH_FILE to run this benchmark"
exit 1
fi
if [[ -z "${S3_BUCKET_SMALL_BENCH_FILE}" ]]; then
echo "Set S3_BUCKET_SMALL_BENCH_FILE to run this benchmark"
exit 1
fi
if [[ -n "${S3_JOB_NAME_FILTER}" ]]; then
echo "Will only run fio jobs which match $S3_JOB_NAME_FILTER"
fi
optional_args=""
if [[ -n "${S3_ENDPOINT_URL}" ]]; then
optional_args+="--endpoint-url=${S3_ENDPOINT_URL}"
fi
base_dir=$(dirname "$0")
project_dir="${base_dir}/../.."
cd ${project_dir}
results_dir=results
runtime_seconds=30
startdelay_seconds=30
iterations=10
rm -rf ${results_dir}
mkdir -p ${results_dir}
run_fio_job() {
job_file=$1
bench_file=$2
mount_dir=$3
log_dir=$4
job_name=$(basename "${job_file}")
job_name="${job_name%.*}"
echo -n "Running job ${job_name} for ${iterations} iterations... "
for i in $(seq 1 $iterations);
do
echo -n "${i};"
# we know each fio job will be running for exactly 1 minute from the job definitions.
# there must be something wrong if it takes longer than that.
set +e
timeout 300s fio --thread \
--output=${results_dir}/${job_name}_iter${i}.json \
--output-format=json \
--directory=${mount_dir} \
--filename=${bench_file} \
--eta=never \
${job_file}
job_status=$?
set -e
if [ $job_status -ne 0 ]; then
tail -1000 ${log_dir}/mountpoint-s3-*
echo "Job ${job_name} failed with exit code ${job_status}"
exit 1
fi
done
echo "done"
# combine the results and find an average value
jq -n 'reduce inputs.jobs[] as $job (null; .name = $job.jobname | .len += 1 | .value += (if ($job."job options".rw == "read")
then $job.read.bw / 1024
elif ($job."job options".rw == "randread") then $job.read.bw / 1024
elif ($job."job options".rw == "randwrite") then $job.write.bw / 1024
elif ($job."job options".rw | startswith("read")) then $job.read.bw / 1024
else $job.write.bw / 1024 end)) | {name: .name, value: (.value / .len), unit: "MiB/s"}' ${results_dir}/${job_name}_iter*.json | tee ${results_dir}/${job_name}_parsed.json
}
should_run_job() {
job_file=$1
if [[ -n "${S3_JOB_NAME_FILTER}" ]]; then
if [[ "${job_file}" == *"${S3_JOB_NAME_FILTER}"* ]]; then
# job name matches filter
return 0
else
# job name does not match filter
return 1
fi
fi
}
read_benchmark () {
jobs_dir=mountpoint-s3/scripts/fio/read
for job_file in "${jobs_dir}"/*.fio; do
if ! should_run_job "${job_file}"; then
echo "Skipping job ${job_file} because it does not match ${S3_JOB_NAME_FILTER}"
continue
fi
mount_dir=$(mktemp -d /tmp/fio-XXXXXXXXXXXX)
job_name=$(basename "${job_file}")
job_name="${job_name%.*}"
log_dir=logs/${job_name}
# cleanup mount directory and log directory
cleanup() {
echo "read_benchmark:cleanup"
# unmount file system only if it is mounted
! mountpoint -q ${mount_dir} || sudo umount ${mount_dir}
rm -rf ${mount_dir}
rm -rf ${log_dir}
}
# trap cleanup on exit
trap 'cleanup' EXIT
rm -rf ${log_dir}
mkdir -p ${log_dir}
# mount file system
set +e
cargo run --quiet --release -- \
${S3_BUCKET_NAME} ${mount_dir} \
--debug \
--allow-delete \
--log-directory=${log_dir} \
--prefix=${S3_BUCKET_TEST_PREFIX} \
--part-size=16777216 \
${optional_args}
mount_status=$?
set -e
if [ $mount_status -ne 0 ]; then
echo "Failed to mount file system"
exit 1
fi
# set bench file
bench_file=${S3_BUCKET_BENCH_FILE}
# run against small file if the job file ends with small.fio
if [[ $job_file == *small.fio ]]; then
bench_file=${S3_BUCKET_SMALL_BENCH_FILE}
fi
# run the benchmark
run_fio_job $job_file $bench_file $mount_dir $log_dir
cleanup
done
}
write_benchmark () {
jobs_dir=mountpoint-s3/scripts/fio/write
for job_file in "${jobs_dir}"/*.fio; do
if ! should_run_job "${job_file}"; then
echo "Skipping job ${job_file} because it does not match ${S3_JOB_NAME_FILTER}"
continue
fi
job_name=$(basename "${job_file}")
job_name="${job_name%.*}"
log_dir=logs/${job_name}
# cleanup mount directory and log directory
cleanup() {
echo "write_benchmark:cleanup"
# unmount file system only if it is mounted
! mountpoint -q ${mount_dir} || sudo umount ${mount_dir}
rm -rf ${mount_dir}
rm -rf ${log_dir}
}
# trap cleanup on exit
trap 'cleanup' EXIT
rm -rf ${log_dir}
mkdir -p ${log_dir}
# mount file system
mount_dir=$(mktemp -d /tmp/fio-XXXXXXXXXXXX)
set +e
cargo run --quiet --release -- \
${S3_BUCKET_NAME} ${mount_dir} \
--debug \
--allow-delete \
--log-directory=${log_dir} \
--prefix=${S3_BUCKET_TEST_PREFIX} \
${optional_args}
mount_status=$?
set -e
if [ $mount_status -ne 0 ]; then
echo "Failed to mount file system"
exit 1
fi
# set bench file
bench_file=${job_name}_${RANDOM}.dat
# run the benchmark
run_fio_job $job_file $bench_file $mount_dir $log_dir
cleanup
done
}
read_benchmark
write_benchmark
# combine all bench results into one json file
jq -n '[inputs]' ${results_dir}/*_parsed.json | tee ${results_dir}/output.json