Last active
August 18, 2024 22:26
-
-
Save Mstaaravin/ce6726ba7a09eb8f02281713ad4a7b9b to your computer and use it in GitHub Desktop.
Disk benchmark with fio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Global variables | |
OUTPUT_UNIT="MB/s" | |
FILE_SIZE="20g" | |
BLOCK_SIZE="16k" | |
RUNTIME="60" | |
TEST_FILE="$PWD/fio_test_file" | |
IODEPTH="32" | |
NUMJOBS="4" | |
# Function to display fio parameters | |
show_parameters() { | |
echo "" | |
echo "FIO Parameters:" | |
echo "---------------" | |
echo "IO Engine: libaio" | |
echo "Block Size: $BLOCK_SIZE" | |
echo "File Size: $FILE_SIZE" | |
echo "Number of Jobs: $NUMJOBS" | |
echo "IO Depth: $IODEPTH" | |
echo "Direct IO: No" # removed --direct=1 from fio command | |
echo "Runtime: $RUNTIME seconds" | |
echo "Output Unit: $OUTPUT_UNIT" | |
echo "Test file location: $TEST_FILE" | |
echo "---------------" | |
} | |
# Function to convert and format results | |
convert_and_format() { | |
local value=$1 | |
case $OUTPUT_UNIT in | |
"KB/s") | |
echo "$value" | |
;; | |
"MB/s") | |
awk -v val="$value" 'BEGIN {printf "%.2f", val/1000}' | |
;; | |
"Gb/s") | |
awk -v val="$value" 'BEGIN {printf "%.2f", (val*8)/(1000*1000)}' | |
;; | |
*) | |
echo "Invalid unit" | |
exit 1 | |
;; | |
esac | |
} | |
# Function to run fio with common parameters and capture results | |
run_fio() { | |
local name=$1 | |
local rw=$2 | |
local rwmixread=$3 | |
echo "Running $name test..." | |
fio --name=$name \ | |
--ioengine=libaio \ | |
--rw=$rw \ | |
--rwmixread=$rwmixread \ | |
--bs=$BLOCK_SIZE \ | |
--size=$FILE_SIZE \ | |
--numjobs=$NUMJOBS \ | |
--iodepth=$IODEPTH \ | |
--runtime=$RUNTIME \ | |
--filename=$TEST_FILE \ | |
--output-format=json \ | |
--output="${name}_result.json" \ | |
--random_distribution=zipf:1.2 \ | |
--write_lat_log=${name}_latency \ | |
--group_reporting \ | |
--eta=never | |
} | |
# Run tests | |
echo "Running FIO benchmarks..." | |
show_parameters | |
run_fio "seq-write" "write" "0" | |
run_fio "seq-read" "read" "100" | |
run_fio "rand-write" "randwrite" "0" | |
run_fio "rand-read" "randread" "100" | |
run_fio "mixed-randread-write" "randrw" "70" | |
# Print summary | |
echo -e "\nBenchmark Summary:" | |
echo "-------------------" | |
printf "%-25s %-15s %-15s %-15s %-15s\n" "Test" "Read (${OUTPUT_UNIT})" "Write (${OUTPUT_UNIT})" "Read IOPS" "Write IOPS" | |
for test in seq-write seq-read rand-write rand-read mixed-randread-write; do | |
read_bw=$(jq '.jobs[0].read.bw // 0' "${test}_result.json") | |
write_bw=$(jq '.jobs[0].write.bw // 0' "${test}_result.json") | |
read_iops=$(jq '.jobs[0].read.iops // 0' "${test}_result.json") | |
write_iops=$(jq '.jobs[0].write.iops // 0' "${test}_result.json") | |
read_bw_formatted=$(convert_and_format ${read_bw}) | |
write_bw_formatted=$(convert_and_format ${write_bw}) | |
printf "%-25s %-15s %-15s %-15.0f %-15.0f\n" "$test" "$read_bw_formatted" "$write_bw_formatted" "${read_iops}" "${write_iops}" | |
done | |
# Add latency summary | |
echo -e "\nLatency Summary (in microseconds):" | |
echo "-------------------" | |
printf "%-25s %-15s %-15s %-15s %-15s\n" "Test" "Read Avg" "Read 99th" "Write Avg" "Write 99th" | |
for test in seq-write seq-read rand-write rand-read mixed-randread-write; do | |
read_lat_avg=$(jq '.jobs[0].read.lat_ns.mean // 0' "${test}_result.json") | |
read_lat_99=$(jq '.jobs[0].read.clat_ns.percentile."99.000000" // 0' "${test}_result.json") | |
write_lat_avg=$(jq '.jobs[0].write.lat_ns.mean // 0' "${test}_result.json") | |
write_lat_99=$(jq '.jobs[0].write.clat_ns.percentile."99.000000" // 0' "${test}_result.json") | |
read_lat_avg=$(awk -v val="$read_lat_avg" 'BEGIN {printf "%.2f", val/1000}') | |
read_lat_99=$(awk -v val="$read_lat_99" 'BEGIN {printf "%.2f", val/1000}') | |
write_lat_avg=$(awk -v val="$write_lat_avg" 'BEGIN {printf "%.2f", val/1000}') | |
write_lat_99=$(awk -v val="$write_lat_99" 'BEGIN {printf "%.2f", val/1000}') | |
printf "%-25s %-15s %-15s %-15s %-15s\n" "$test" "$read_lat_avg" "$read_lat_99" "$write_lat_avg" "$write_lat_99" | |
done | |
# Clean up JSON files and test file | |
rm *_result.json | |
rm $TEST_FILE | |
rm *_latency* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment