Skip to content

Instantly share code, notes, and snippets.

@davlgd
Last active January 3, 2023 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davlgd/4bfcb718f93df16cba597ba2d1ef9377 to your computer and use it in GitHub Desktop.
Save davlgd/4bfcb718f93df16cba597ba2d1ef9377 to your computer and use it in GitHub Desktop.
fio benchmark script
#!/bin/bash
IO_ENGINE=$1
TESTS=$2
TARGET=$3
SIZE=$4
launch () {
sudo fio --name=test --group_reporting --ioengine=$1 --disable_clat=1 --disable_slat=1 --percentile_list=0 --norandommap=1 --randrepeat=0 --direct=1 --rw=$2 --bs=$3 --size=$4 --iodepth=$5 --numjobs=$6 --filename=$7 | grep avg=
}
if [[ $1 == "--help" ]] || [[ $# != 4 ]]
then
[[ $# -ne 4 ]] && { echo "Error : invalid argument numbers"; echo; }
echo "*************************************************************"
echo "* WARNING : this tool is writing data and can erase devices *"
echo "*************************************************************"
echo
echo "Usage : ./fio.sh [IO engine] [tests] [target] [size]"
echo
echo " IO engine : choose one available for this system (ex : psync, libaio, io_uring, null)"
echo " tests : rand (random 4k), seq (sequential 1M), suite (both), read or write (QD/threads)"
echo " target : one or more files/devices name (separated by ':')"
echo " size : how much data to read/write (ex : 512b, 4k, 1024M, 10G)"
echo
echo "fio benchmark from David Legrand distributed under MIT Licence"
echo "Script testing storage latency & performance."
echo
echo "Examples :"
echo
echo " ./fio.sh libaio suite test.fio 512M"
echo " ./fio.sh io_uring read /dev/sda 1G"
echo " ./fio.sh io_uring write /dev/nvme0n1:/dev/nvme1n1 10G"
echo
[[ $# -ne 4 ]] && exit 2 || exit 0
fi
if [ $TESTS != "read" ]
then
echo
echo "*** WARNING : this tool is writing data and can erase devices ***"
echo "Press any key to continue, CTRL+C to end..."
read
fi
sudo clear
echo "File size : $SIZE"
echo "IO Engine : $IO_ENGINE"
echo "Target : $TARGET"
echo "Tests : $TESTS"
echo "Threads : $(nproc)"
echo
if [ $TESTS == "suite" ] || [ $TESTS == "rand" ]
then
echo " * Random 4k read (QD1T1) :"
launch $IO_ENGINE randread 4k $SIZE 1 1 $TARGET
sleep 5
echo
echo " * Random 4k write (QD1T1) :"
launch $IO_ENGINE randwrite 4k $SIZE 1 1 $TARGET
sleep 5
echo
echo " * Random 4k read (QD32T$(nproc)) :"
launch $IO_ENGINE randread 4k $SIZE 32 $(nproc) $TARGET
sleep 5
echo
echo " * Random 4k write (QD32T$(nproc)) :"
launch $IO_ENGINE randwrite 4k $SIZE 32 $(nproc) $TARGET
sleep 5
echo
fi
if [ $TESTS == "suite" ] || [ $TESTS == "seq" ]
then
echo "* Sequential read (QD1T1) :"
launch $IO_ENGINE read 1M $SIZE 1 1 $TARGET
sleep 5
echo
echo " * Sequential write (QD1T1) :"
launch $IO_ENGINE write 1M $SIZE 1 1 $TARGET
echo
echo " * Sequential read (QD32T$(nproc)) :"
launch $IO_ENGINE read 1M $SIZE 32 $(nproc) $TARGET
sleep 5
echo
echo " * Sequential write (QD32T$(nproc)) :"
launch $IO_ENGINE write 1M $SIZE 32 $(nproc) $TARGET
echo
fi
if [ $TESTS == "read" ] || [ $TESTS == "write" ]
then
echo "===== Random access QD performance tests ====="
echo
for QD in 1 4 8 16 32 64 128 256
do
echo " * 4k $TESTS (QD$QD)"
launch $IO_ENGINE rand$TESTS 4k $SIZE $QD 1 $TARGET
echo
done
echo "===== Random access threads performance tests ====="
echo
for JOBS in 1 4 8 16 32 64 128
do
echo " * 4k $TESTS (${JOBS}T)"
launch $IO_ENGINE rand$TESTS 4k $SIZE 1 $JOBS $TARGET
echo
done
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment