Skip to content

Instantly share code, notes, and snippets.

@snizovtsev
Created December 25, 2020 12:08
Show Gist options
  • Save snizovtsev/254012bbdac3816e076da782eb1049bb to your computer and use it in GitHub Desktop.
Save snizovtsev/254012bbdac3816e076da782eb1049bb to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script is based on https://unix.stackexchange.com/revisions/480191/9 .
# The following changes proved to be necessary to make it work on CentOS 7:
# * removed disk info (model, size) - not very useful, might not work in many cases.
# * using "bw" instead of "bw_bytes" to support fio version 3.1 (those availible through yum @base)
# * escaping exclamation mark in sed command
# * the ".fiomark.txt" is not auto-removed
LOOPS=1 # How many times to run each test
SIZE=8192m # Size of each test, multiples of 32 recommended for Q32 tests to give the most accurate results.
TIME=20 # Time per each job
WRITEZERO=0 # Set whether to write zeroes or randoms to testfile (random is the default for both fio and crystaldiskmark); dd benchmarks typically only write zeroes which is why there can be a speed difference.
if [ -z $1 ]; then
TARGET=$HOME
echo "Defaulting to $TARGET for testing"
else
TARGET="$1"
echo "Testing in $TARGET"
fi
cd "$TARGET" || exit
echo "Configuration: Size:$SIZE Loops:$LOOPS Write Only Zeroes:$WRITEZERO
Running Benchmark, please wait...
"
FIO="fio --loops=$LOOPS --size=$SIZE --filename=fiomark.tmp --stonewall --ioengine=libaio --direct=1 --zero_buffers=$WRITEZERO --output-format=json --runtime=$TIME"
#def cpu(type): [[.[1].sysstat.hosts[0].statistics[]."cpu-load"[] | select(.cpu=="all")] | .[][type]] | add/length * 10 | round / 10;
QUERY='def bw(arg): [.jobs[] | select(.jobname==arg[0]+arg[1])[arg[1]].bw] | add / 1024 | round;
def iops(arg): [.jobs[] | select(.jobname==arg[0]+arg[1])[arg[1]].iops] | add | round;
def job_summary(name):
bw([name, "read"]), iops([name, "read"]),
bw([name, "write"]), iops([name, "write"]);'
echo "Results:"
echo " %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle"
echo " ==== ===== ==== ======= ==== ===== ====== ====== ====== ====="
function run_job() {
local NAME="$1"
local CPUSTATS="$1.cpu.txt"
local FIOSTATS="$1.fio.json"
local RUN_FIO="$FIO $2"
if [ ! -f "$FIOSTATS" ] || [ "x$4" == "xrun" ]; then
S_COLORS=always mpstat 1 "$TIME" > "$CPUSTATS" &
$RUN_FIO --output="$FIOSTATS" \
--name="${NAME}read" --rw="${3}read" \
--name="${NAME}write" --rw="${3}write"
fi
local JQEXP="$QUERY job_summary(\"$NAME\")"
read -d '\n' -ra STATS <<< "$(jq "$JQEXP" "$FIOSTATS")"
echo -ne "\033[0;33m
$NAME Read: ${STATS[0]}MB/s IOPS=${STATS[1]}
$NAME Write: ${STATS[2]}MB/s IOPS=${STATS[3]}
CPU Stats: "
wait
#head -n3 "$CPUSTATS" | tail -n1
tail -n1 "$CPUSTATS" | sed 's/^.*all//'
}
# Warmup
if [ "x$4" == "xrun" ]; then
$FIO --output=/dev/null --name=Bufread --loops=1 --bs=32m --iodepth=1 --numjobs=1 --rw=readwrite
fi
run_job Seq "--bs=32m --iodepth=1 --numjobs=1" "" "$2"
run_job 512k "--bs=512k --iodepth=1 --numjobs=1" "" "$2"
run_job SeqQ32T1 "--bs=32m --iodepth=32 --numjobs=1" "" "$2"
run_job 4k "--bs=4k --iodepth=1 --numjobs=1" "rand" "$2"
run_job 4kQ32T1 "--bs=4k --iodepth=32 --numjobs=1" "rand" "$2"
run_job 4kQ8T8 "--bs=4k --iodepth=8 --numjobs=8" "rand" "$2"
# rm "$TARGET/.fiomark.txt"
if [ -f fiomark.tmp ]; then
rm fiomark.tmp
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment