Last active
June 3, 2025 09:26
-
-
Save MrZoidberg/7dee37e0533ff4999a34793e6e9e8227 to your computer and use it in GitHub Desktop.
fio-based hdd/sdd performance benchmark script
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 | |
set -euo pipefail | |
LOGFILE="fio_test_results_$(date +%Y%m%d_%H%M%S).log" | |
touch "$LOGFILE" | |
# Set up cleanup rules | |
declare -A cleanup_map=( | |
["testfile-seq-160g"]=0 # don't clean up immediately; used by two tests | |
["testfile-rand-4g"]=1 | |
["database-testfile"]=1 | |
["testfile-seq-readwrite"]=1 | |
) | |
run_test() { | |
local desc="$1" | |
local filename="$2" | |
local cmd="$3" | |
echo -e "\n========== $desc ==========\n" | tee -a "$LOGFILE" | |
date "+Start: %Y-%m-%d %H:%M:%S" | tee -a "$LOGFILE" | |
sync | |
eval "$cmd" | tee -a "$LOGFILE" | |
date "+End: %Y-%m-%d %H:%M:%S" | tee -a "$LOGFILE" | |
if [[ "${cleanup_map[$filename]:-0}" -eq 1 && -f "$filename" ]]; then | |
echo "Cleaning up test file: $filename" | tee -a "$LOGFILE" | |
rm -f "$filename" | |
sync | |
fi | |
} | |
# SEQ Write | |
run_test "SEQ Write with 4 vCPU" "testfile-seq-160g" \ | |
"fio --filename=testfile-seq-160g --size=160G --direct=1 --rw=write --bs=1M \ | |
--ioengine=libaio --numjobs=4 --iodepth=32 --name=seq-write-test \ | |
--group_reporting --ramp_time=4" | |
# SEQ Read | |
run_test "SEQ Read with 4 vCPU" "testfile-seq-160g" \ | |
"fio --filename=testfile-seq-160g --size=160G --direct=1 --rw=read --bs=1M \ | |
--ioengine=libaio --numjobs=4 --iodepth=32 --name=seq-read-test \ | |
--group_reporting --readonly --ramp_time=4" | |
# Clean up after both SEQ tests | |
if [[ -f "testfile-seq-160g" ]]; then | |
echo "Final cleanup of testfile-seq-160g" | tee -a "$LOGFILE" | |
rm -f "testfile-seq-160g" | |
sync | |
fi | |
# Random Write | |
run_test "Random Write with 4 vCPU" "testfile-rand-4g" \ | |
"fio --filename=testfile-rand-4g --size=4G --direct=1 --rw=randwrite --bs=4k \ | |
--ioengine=libaio --numjobs=4 --iodepth=32 --name=rand-write-test \ | |
--group_reporting --ramp_time=4 --time_based --runtime=300" | |
# Random Read | |
run_test "Random Read with 4 vCPU" "testfile-rand-4g" \ | |
"fio --filename=testfile-rand-4g --size=4G --direct=1 --rw=randread --bs=4k \ | |
--ioengine=libaio --numjobs=4 --iodepth=32 --name=rand-read-test \ | |
--group_reporting --readonly --ramp_time=4" | |
# Mixed DB Workload | |
run_test "Mixed Random R/W DB workload with 8 vCPU" "database-testfile" \ | |
"fio --filename=database-testfile --size=4G --direct=1 --rw=randrw --bs=8k \ | |
--ioengine=libaio --iodepth=32 --numjobs=8 --rwmixread=70 \ | |
--name=db-mixed-rw-test --group_reporting --ramp_time=4" | |
# Multithreaded App Simulation | |
run_test "Multi-Threaded Read/Write App Simulation with 16 vCPU" "testfile-seq-readwrite" \ | |
"fio --filename=testfile-seq-readwrite --size=160G --direct=1 --rw=readwrite --bs=64k \ | |
--ioengine=libaio --iodepth=16 --numjobs=16 --name=multi-thread-app \ | |
--group_reporting --ramp_time=4" | |
echo -e "\n✅ All tests completed. Results saved to: $LOGFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment