-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiozone.sh
More file actions
executable file
·123 lines (106 loc) · 3.68 KB
/
Copy pathiozone.sh
File metadata and controls
executable file
·123 lines (106 loc) · 3.68 KB
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
#!/usr/bin/env bash
#
# Script to test disk IO performance using 'iozone'
#
# Set shell options
set +o xtrace -o errexit -o nounset -o pipefail +o history
IFS=$'\n'
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Prepare working directory
WORKDIR="${SCRIPT_DIR}/tmp"
mkdir -p "${WORKDIR}"
cd "${WORKDIR}"
echo
echo "==== Installation ====="
"${SCRIPT_DIR}/install.sh" util-linux grep gawk bc
if lsb_release -c | grep -q "bookworm"; then
"${SCRIPT_DIR}/install.sh" 'http://ftp.debian.org/debian/pool/non-free/i/iozone3/iozone3_489-1_amd64.deb'
else
"${SCRIPT_DIR}/install.sh" iozone3
fi
export LD_LIBRARY_PATH="${WORKDIR}/usr/lib/x86_64-linux-gnu:${WORKDIR}/usr/lib/x86_64-linux-gnu/ceph:${WORKDIR}/lib/x86_64-linux-gnu"
export PATH="${WORKDIR}/usr/bin:${WORKDIR}/usr/local/bin:/usr/local/bin:/usr/bin:/bin"
# --- Configuration ---
# Set test file size - is multiplied by number of threads
FILE_SIZE="${FILE_SIZE:-5G}"
# Set block size in Kbytes (4k is common for random IO)
BLOCK_SIZE="${BLOCK_SIZE:-4}"
# Set number of threads
THREADS="${THREADS:-4}"
# -------------------
# List block devices
echo
echo "==== Block Devices ===="
lsblk -o NAME,FSTYPE,MOUNTPOINT,SIZE,MODEL
echo
# Print test parameters
echo
echo "==== Test Parameters ===="
echo "- Threads: ${THREADS}"
echo "- Size per thread: ${FILE_SIZE}"
echo "- Block Size: ${BLOCK_SIZE}"
# Check available space
required_bytes=$( echo "$(numfmt --from=iec "$FILE_SIZE")*${THREADS}" | bc )
available_bytes=$(df -B1 --output=avail "${WORKDIR}" | tail -n1)
if [ "$required_bytes" -gt "$available_bytes" ]; then
echo
echo "Error: Not enough space available in ${WORKDIR}"
echo "Required: $(numfmt --to=iec "$required_bytes")"
echo "Available: $(numfmt --to=iec "$available_bytes")"
exit 1
fi
# Convert KB/s to MiB/s with 2 decimal places
kb_to_mib() {
local kb_value="$1"
echo "scale=0; ${kb_value}/1024" | bc -l
}
# Extract result using regex
extract_result() {
local result_text="$1"
local regex="$2"
echo -e "${result_text}" | grep -oP "${regex}" | tail -n1 | sed -nE "s/${regex}/\1/p"
}
# Function to run IOzone test
run_iozone_test() {
echo
IOZONE_RESULT=$(
iozone \
-i0 \
-i2 \
-I \
-e \
-t "${THREADS}" \
-s "${FILE_SIZE}" \
-r "${BLOCK_SIZE}" \
| tee /dev/tty
)
if ! grep -q 'O_DIRECT feature enabled' <<< "${IOZONE_RESULT}"; then
echo
echo "ERROR: O_DIRECT feature not enabled, results would be inaccurate." >&2
return 1
fi
local regex_write='Children see throughput for\s*[0-9]+\s+initial writers\s*=\s*([0-9]+\.?[0-9]*)\s*kB\/sec'
local regex_rand_read='Children see throughput for\s*[0-9]+\s+random readers\s*=\s*([0-9]+\.?[0-9]*)\s*kB\/sec'
local regex_rand_write='Children see throughput for\s*[0-9]+\s+random writers\s*=\s*([0-9]+\.?[0-9]*)\s*kB\/sec'
local result_write
local result_rand_read
local result_rand_write
result_write=$(extract_result "${IOZONE_RESULT}" "${regex_write}")
result_rand_read=$(extract_result "${IOZONE_RESULT}" "${regex_rand_read}")
result_rand_write=$(extract_result "${IOZONE_RESULT}" "${regex_rand_write}")
echo
printf "\033[0;33m%-25s %s MiB/sec\033[0m\n" "iozone Sequential Write:" "$(kb_to_mib "${result_write}")"
printf "\033[0;33m%-25s %s MiB/sec\033[0m\n" "iozone Random Read:" "$(kb_to_mib "${result_rand_read}")"
printf "\033[0;33m%-25s %s MiB/sec\033[0m\n" "iozone Random Write:" "$(kb_to_mib "${result_rand_write}")"
}
# Run tests
echo
echo "==== Running Tests ===="
run_iozone_test
# Cleanup temporary files
find "${WORKDIR}" -type f -name "iozone.*" -delete
# Finish
echo
echo "Done."
exit 0