Last active
August 11, 2025 12:44
-
-
Save maxpain/4d4b5d619c4589a68776be620dd2eddf to your computer and use it in GitHub Desktop.
fio script for complex benchmarking
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/sh | |
run(){ | |
name="$1" | |
shift | |
( | |
set -x | |
fio -name="$name" -filename=$disk -output-format=json --output=results/$disk_dashed-$name.json -ioengine=libaio -direct=1 -randrepeat=0 -random_generator=tausworthe64 -size=100G -runtime=60 -time_based=1 "$@" | |
) | |
} | |
if [ ! -b "$1" ]; then | |
echo "$1 is not a device!" >&2 | |
exit 1 | |
fi | |
command -V fio >&2 || exit $? | |
command -V jq >&2 || exit $? | |
disk=$1 | |
disk_dashed=$(echo "$disk" | tr / - | sed 's/^-//') | |
mkdir -p results | |
rm -f results/$disk_dashed-* | |
blkdiscard -f $disk | |
# Preconditioning | |
fio -name=prefill -filename=$disk -ioengine=libaio -direct=1 -rw=write -bs=4M -iodepth=32 -size=100G -numjobs=1 -end_fsync=1 | |
# Tests | |
run write -rw=write -bs=4M -numjobs=1 -iodepth=16 | |
run randwrite_fsync -rw=randwrite -bs=4k -numjobs=1 -iodepth=1 -fsync=1 | |
run randwrite_jobs4 -rw=randwrite -bs=4k -numjobs=4 -iodepth=128 -group_reporting | |
run randwrite -rw=randwrite -bs=4k -numjobs=1 -iodepth=128 | |
run read -rw=read -bs=4M -numjobs=1 -iodepth=16 | |
run randread_fsync -rw=randread -bs=4k -numjobs=1 -iodepth=1 -fsync=1 | |
run randread_jobs4 -rw=randread -bs=4k -numjobs=4 -iodepth=128 -group_reporting | |
run randread -rw=randread -bs=4k -numjobs=1 -iodepth=128 | |
# Initialize variables | |
bw_seq_read=0; bw_seq_write=0 | |
bw_rand_read=0; bw_rand_write=0 | |
bw_rand_t4_read=0; bw_rand_t4_write=0 | |
bw_rand_fsync_read=0; bw_rand_fsync_write=0 | |
iops_seq_read=0; iops_seq_write=0 | |
iops_rand_read=0; iops_rand_write=0 | |
iops_rand_t4_read=0; iops_rand_t4_write=0 | |
iops_rand_fsync_read=0; iops_rand_fsync_write=0 | |
lat_seq_read=0; lat_seq_write=0 | |
lat_rand_read=0; lat_rand_write=0 | |
lat_rand_t4_read=0; lat_rand_t4_write=0 | |
lat_rand_fsync_read=0; lat_rand_fsync_write=0 | |
files=$(find results -name "$disk_dashed-*.json") | |
for i in $files; do | |
testname=$(jq -r '.jobs[0]["job options"].name' "$i") | |
if echo "$testname" | grep -q 'read'; then | |
bw=$(jq '.jobs[0].read.bw_mean / 1024 | floor' "$i") | |
iops=$(jq '.jobs[0].read.iops_mean | floor' "$i") | |
lat=$(jq '.jobs[0].read.clat_ns.mean / 1000 | floor' "$i") | |
case "$testname" in | |
read) | |
bw_seq_read=$bw | |
iops_seq_read=$iops | |
lat_seq_read=$lat | |
;; | |
randread) | |
bw_rand_read=$bw | |
iops_rand_read=$iops | |
lat_rand_read=$lat | |
;; | |
randread_jobs4) | |
bw_rand_t4_read=$bw | |
iops_rand_t4_read=$iops | |
lat_rand_t4_read=$lat | |
;; | |
randread_fsync) | |
bw_rand_fsync_read=$bw | |
iops_rand_fsync_read=$iops | |
lat_rand_fsync_read=$lat | |
;; | |
esac | |
elif echo "$testname" | grep -q 'write'; then | |
bw=$(jq '.jobs[0].write.bw_mean / 1024 | floor' "$i") | |
iops=$(jq '.jobs[0].write.iops_mean | floor' "$i") | |
lat=$(jq '.jobs[0].write.clat_ns.mean / 1000 | floor' "$i") | |
case "$testname" in | |
write) | |
bw_seq_write=$bw | |
iops_seq_write=$iops | |
lat_seq_write=$lat | |
;; | |
randwrite) | |
bw_rand_write=$bw | |
iops_rand_write=$iops | |
lat_rand_write=$lat | |
;; | |
randwrite_jobs4) | |
bw_rand_t4_write=$bw | |
iops_rand_t4_write=$iops | |
lat_rand_t4_write=$lat | |
;; | |
randwrite_fsync) | |
bw_rand_fsync_write=$bw | |
iops_rand_fsync_write=$iops | |
lat_rand_fsync_write=$lat | |
;; | |
esac | |
fi | |
done | |
# Output the header | |
echo "Test,Bandwidth,,,,,,,,IOPS,,,,,,,,Latency,,,,,,," | |
echo ",Seq 4M T1Q16,,Rand 4K T1Q128,,Rand 4K T4Q128,,Rand 4K T1Q1 fsync=1,,Seq 4M T1Q16,,Rand 4K T1Q128,,Rand 4K T4Q128,,Rand 4K T1Q1 fsync=1,,Seq 4M T1Q16,,Rand 4K T1Q128,,Rand 4K T4Q128,,Rand 4K T1Q1 fsync=1," | |
echo ",Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write,Read,Write" | |
# Output the results | |
echo "Results,$bw_seq_read,$bw_seq_write,$bw_rand_read,$bw_rand_write,$bw_rand_t4_read,$bw_rand_t4_write,$bw_rand_fsync_read,$bw_rand_fsync_write,$iops_seq_read,$iops_seq_write,$iops_rand_read,$iops_rand_write,$iops_rand_t4_read,$iops_rand_t4_write,$iops_rand_fsync_read,$iops_rand_fsync_write,$lat_seq_read,$lat_seq_write,$lat_rand_read,$lat_rand_write,$lat_rand_t4_read,$lat_rand_t4_write,$lat_rand_fsync_read,$lat_rand_fsync_write" | |
rm -f results/$disk_dashed-* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment