-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-benchmarks.sh
executable file
·184 lines (161 loc) · 4.94 KB
/
run-benchmarks.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
#!/bin/bash
set -eu
declare -A deviceInfoMap
declare -A modelMap
function gatherDeviceInfo() {
local device
for device in $@; do
deviceInfo=$(smartctl -i -j $device)
deviceInfoMap+=([$device]="$deviceInfo")
local modelName=$(jq -r '.model_name' <<< "$deviceInfo")
if [ ${modelMap[$modelName]+_} ]; then
local models=${modelMap[$modelName]}
models+=" $device"
modelMap[$modelName]="$models"
else
modelMap+=([$modelName]="$device")
fi
done
}
gatherDeviceInfo $@
# ./random/{4k,8k,16k,32k}/{raw,ext4,zfs/{4k,8k,16k}}
# ./sequential/{128k,1m}/{raw,ext4,zfs/{128k,1m}}
function benchmarkDevice() {
local device=$1
runRawBenchmarks $device
runExt4Benchmarks $device
runZfsBenchmarks $device
local deviceName=${device:5}
for mode in random sequential; do
if [[ -d .results/$mode/raw/$deviceName ]]; then
for blocksize in $(ls .results/$mode/raw/$deviceName); do
mkdir -p .results/$mode/$blocksize
mv .results/$mode/{raw/$deviceName/$blocksize,$blocksize/raw}
done
fi
if [[ -d .results/$mode/ext4/$deviceName ]]; then
for blocksize in $(ls .results/$mode/ext4/$deviceName); do
mkdir -p .results/$mode/$blocksize
mv .results/$mode/{ext4/$deviceName/$blocksize,$blocksize/ext4}
done
fi
if [[ -d .results/$mode/zfs ]]; then
for recordsize in $(ls .results/$mode/zfs); do
for blocksize in $(ls .results/$mode/zfs/$recordsize); do
mkdir -p .results/$mode/$blocksize/zfs
mv .results/$mode/{zfs/$recordsize/$blocksize,$blocksize/zfs/$recordsize}
done
done
fi
done
find .results -empty -delete
local deviceInfo=$(smartctl -i -j $device)
local modelName=$(jq -r '.model_name' <<< "$deviceInfo")
local serialNumber=$(jq -r '.serial_number' <<< "$deviceInfo")
mkdir -p "results/$modelName/devices/$serialNumber"
mv .results/{random,sequential} "results/$modelName/devices/$serialNumber"
}
function runRawBenchmarks() {
local device=$1
echo "Preparing '$device' for raw benchmarks"
wipeDevice $device
runBenchmarks $device raw
}
function runExt4Benchmarks() {
local device=$1
echo "Preparing '$device' for ext4 benchmarks"
wipeDevice $device
echo "Partitioning device"
parted -s $device mklabel gpt &> /dev/null
parted -a opt -s $device mkpart primary 0% 100% &> /dev/null
sleep 1
echo "Creating ext4 filesystem"
local partition="${device}1" # this won't work for NVME drives
mke2fs -t ext4 $partition &> /dev/null
local mountPath="/mnt/${device:5}"
mkdir -p "$mountPath"
echo "Mounting partition at $mountPath"
mount $partition $mountPath
sleep 1
runBenchmarks $mountPath ext4
echo "Cleaning '$device' after ext4 benchmarks"
umount $mountPath
sleep 1
rm -rf $mountPath
wipeDevice $device
}
function runZfsBenchmarks() {
local device=$1
echo "Preparing '$device' for ZFS benchmarks"
wipeDevice $device
local poolName=${device:5}
echo "Creating '$poolName' zpool on the device"
zpool create -o ashift=12 $poolName $device
for recordsize in 4k 8k 16k 64k 128k 1m; do
local datasetName="$poolName/$recordsize"
echo "Creating '$datasetName' dataset with $recordsize recordsize"
zfs create -o atime=off -o recordsize=$recordsize $datasetName
runBenchmarks "/$datasetName" zfs
echo "Destroying '$datasetName' dataset"
zfs destroy $datasetName
done
echo "Destroying '$poolName' zpool"
zpool destroy $poolName
echo "Cleaning '$device' after ZFS benchmarks"
wipeDevice $device
}
function wipeDevice() {
local device=$1
local partitions=($(lsblk -J -p -f $device | jq -r '.blockdevices[].children // [] | .[].name'))
if [[ "${#partitions[@]}" -gt 0 ]]; then
local partition
for partition in ${partitions[@]}; do
wipefs -a $partition > /dev/null
done
fi
wipefs -a $device > /dev/null
}
function runBenchmarks() {
local target=$1
local outputPath=$2
local type
lsblk $target &> /dev/null && type="device" || type="directory"
if [[ $type == "device" ]]; then
bench-fio \
--type device \
--target $target \
--mode randread randwrite \
-b 4k 8k 16k 32k 64k \
--iodepth 1 32 64 256 \
--numjobs 1 \
--output .results/random/$outputPath
bench-fio \
--type device \
--target $target \
--mode read write \
-b 128k 1m \
--iodepth 1 32 64 256 \
--numjobs 1 \
--output .results/sequential/$outputPath
else
bench-fio \
--type directory \
--target $target \
--mode randread randwrite \
--size 150g \
-b 4k 8k 16k 32k 64k \
--iodepth 1 32 64 256 \
--numjobs 1 \
--output .results/random/$outputPath
bench-fio \
--type directory \
--target $target \
--mode read write \
--size 150g \
-b 128k 1m \
--iodepth 1 32 64 256 \
--numjobs 1 \
--output .results/sequential/$outputPath
fi
}
benchmarkDevice $1