Created
December 20, 2023 19:26
-
-
Save elfurbe/29e5f9d4ef9f17da2aed948bb77ec3cd to your computer and use it in GitHub Desktop.
Yet Another FIO 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 | |
## Make sure fio is available to run | |
which fio &>/dev/null && FIO=`which fio` || echo "fio not found in PATH." | |
[ -z "$FIO" ] && exit 1 | |
## Make sure a test destination directory was provided | |
if [ -z "$1" ]; then | |
echo "No test path provided." | |
exit 2 | |
else | |
TESTDIR="$1" | |
fi | |
function timestamp { | |
date --iso-8601=seconds &>/dev/null && date --iso-8601=seconds || gdate --iso-8601=seconds | |
} | |
function log { | |
echo "[ $(timestamp) ] $*" | tee -a $LOGFILE | |
} | |
## When you're using this interactively, it's nice to know how much time is left | |
function countdown() { | |
SECS=$1 | |
while [ $SECS -gt 0 ] | |
do | |
printf "\r\033[KT-Minus %.d seconds and counting..." $((SECS--)) | |
sleep 1 | |
done | |
printf "\r\033[KT-Minus %.1d seconds and counting..." 0 | |
echo "Liftoff" | |
} | |
function randosleep { | |
SLEEP=$[ ( $RANDOM % 300 ) + 1 ] | |
log "=== Sleeping for ${SLEEP} seconds ===" | |
countdown $SLEEP | |
} | |
## FIO COMMAND FLAGS | |
FIO_FLAGS="--ioengine=linuxaio --direct=1 --buffered=0 --atomic=1 --name=benchmark --directory=${TESTDIR}" | |
## STATIC/ARBITRARY VARIABLES | |
RUNTIME_SHORT=120 | |
RUNTIME_LONG=3600 | |
IODEPTH=64 | |
LOGFILE=/root/fio.log.$(hostname -f).$(timestamp) | |
## COMPUTED VARIABLED | |
NUMJOBS=$(nproc --all || sysctl -n hw.ncpu) | |
TOTALMEM=$(lsmem -b --summary=only | grep "Total online memory" | awk -F\: '{print $2}' | sed 's/^[[:space:]]*//') | |
TOTALMEM_MB=$(echo "$TOTALMEM / 1024 / 1024" | bc ) | |
TOTALMEM_GB=$(echo "$TOTALMEM_MB / 1024" | bc ) | |
PERJOBSIZEVALUE=$(echo "$TOTALMEM_MB / $NUMJOBS * 2" | bc ) | |
SIZE="${PERJOBSIZEVALUE}m" | |
log "=== Runtime Parameters ===" | |
log " jobs: $NUMJOBS" | |
log " iodepth: $IODEPTH" | |
log " memory: ${TOTALMEM_GB}G" | |
log " job size: $SIZE" | |
log " short job: $RUNTIME_SHORT" | |
log " long job: $RUNTIME_LONG" | |
log " logfile: $LOGFILE" | |
log "==========================" | |
log "=== Pseudo-random sleeping for multi-client de-sync ===" | |
randosleep | |
log "=== Launching, using path ${TESTDIR} ===" | |
log "Launching fio random write (4k) for ${RUNTIME_SHORT}s..." | |
echo "$FIO $FIO_FLAGS --rw=randwrite --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting" | |
$FIO $FIO_FLAGS --rw=randwrite --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting 2>&1 | tee -a $LOGFILE | |
log "=== Pseudo-random sleeping for multi-client de-sync ===" | |
randosleep | |
log "Launching fio random read (4k) for ${RUNTIME_SHORT}s..." | |
echo "$FIO $FIO_FLAGS --rw=randread --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting" | |
$FIO $FIO_FLAGS --rw=randread --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting 2>&1 | tee -a $LOGFILE | |
log "=== Pseudo-random sleeping for multi-client de-sync ===" | |
randosleep | |
log "Launching fio random read/write mix (4k 3:1 read:write) for ${RUNTIME_LONG}s..." | |
echo "$FIO $FIO_FLAGS --rw=randrw --rwmixread=75 --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_LONG --time_based --end_fsync=1 --group_reporting" | |
$FIO $FIO_FLAGS --rw=randrw --rwmixread=75 --bs=4k --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_LONG --time_based --end_fsync=1 --group_reporting 2>&1 | tee -a $LOGFILE | |
log "=== Pseudo-random sleeping for multi-client de-sync ===" | |
randosleep | |
log "Launching fio sequential write (1M) for ${RUNTIME_SHORT}s..." | |
echo "$FIO $FIO_FLAGS --rw=write --bs=1M --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting" | |
$FIO $FIO_FLAGS --rw=write --bs=1M --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting 2>&1 | tee -a $LOGFILE | |
log "=== Pseudo-random sleeping for multi-client de-sync ===" | |
randosleep | |
log "Launching fio sequential read (1M) for ${RUNTIME_SHORT}s..." | |
echo "$FIO $FIO_FLAGS --rw=read --bs=1M --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting" | |
$FIO $FIO_FLAGS --rw=read --bs=1M --numjobs=$NUMJOBS --size=$SIZE --iodepth=$IODEPTH --runtime=$RUNTIME_SHORT --time_based --end_fsync=1 --group_reporting 2>&1 | tee -a $LOGFILE | |
log "=== Finished ===" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment