Skip to content

Instantly share code, notes, and snippets.

@JohnStarich
Created January 2, 2025 08:58
Show Gist options
  • Save JohnStarich/fb31b6657d8ad629e87df7a3c611c3bc to your computer and use it in GitHub Desktop.
Save JohnStarich/fb31b6657d8ad629e87df7a3c611c3bc to your computer and use it in GitHub Desktop.
Linux Disk Benchmark

Linux Disk Benchmark

Runs fio to benchmark similar metrics to KDiskMark and CrystalDiskMark.

This produces results like the one below for easy comparison to existing tools, though when a GUI is not available or convenient.

fiotest-1024m:
Benchmark           Bandwidth
Read-Seq1M-Q8T1     5518 Mbps  (   690 IOPS)
Write-Seq1M-Q8T1    3547 Mbps  (   443 IOPS)
Read-Seq1M-Q1T1     2792 Mbps  (   349 IOPS)
Write-Seq1M-Q1T1    2287 Mbps  (   286 IOPS)
Read-RND4K-Q32T1    1441 Mbps  ( 46122 IOPS)
Write-RND4K-Q32T1   1121 Mbps  ( 35877 IOPS)
Read-RND4K-Q1T1      121 Mbps  (  3861 IOPS)
Write-RND4K-Q1T1     102 Mbps  (  3254 IOPS)
[global]
direct=1 ; May not work from inside a container, but needed on Linux with ioengine=libaio
stonewall
ioengine=libaio
randrepeat=0
refill_buffers
end_fsync=1
rwmixread=70
runtime=5
group_reporting
[Read-Seq1M-Q8T1]
bs=1m
iodepth=8
rw=read
[Write-Seq1M-Q8T1]
bs=1m
iodepth=8
rw=write
[Read-Seq1M-Q1T1]
bs=1m
iodepth=1
rw=read
[Write-Seq1M-Q1T1]
bs=1m
iodepth=1
rw=write
[Read-RND4K-Q32T1]
bs=4k
iodepth=32
rw=randread
[Write-RND4K-Q32T1]
bs=4k
iodepth=32
rw=randwrite
[Read-RND4K-Q1T1]
bs=4k
iodepth=1
rw=randread
[Write-RND4K-Q1T1]
bs=4k
iodepth=1
rw=randwrite
#!/usr/bin/env bash
# Linux Disk Benchmark
# Runs fio to benchmark similar metrics to KDiskMark and CrystalDiskMark.
#
# Usage: ./fio-bench.sh [ITERATIONS] [FILE_SIZE_MEGABYTES]
# Run this script in the file system and disk you would like to test alongside the bench.fio jobfile.
set -ex
cd "$(dirname "${BASH_SOURCE[0]}")"
loops=${1:-1} # number of iterations
file_megabytes=${2:-1024}
file_base=fiotest-${file_megabytes}m
file=${file_base}.tmp
bytes=$(( file_megabytes * 1024 * 1024 ))
if [[ ! -f "$file" || "$(wc -c "$file")" != "$bytes $file" ]]; then
fio \
--output-format=json \
--create_only=1 \
--filename="$file" \
--size=${file_megabytes}m \
--zero_buffers=0 \
--name=prepare
fi
fio \
--output-format=json \
--eta=always \
--loops="$loops" \
--filename="$file" \
--size="${file_megabytes}"m \
--warnings-fatal \
--exitall_on_error \
bench.fio \
| tee "$file_base".json
set +x
printf 'Check %s.json for full results.\n' "$file_base"
printf '%s:\n' "$file_base"
printf '%-20s%s\n' 'Benchmark' 'Bandwidth'
# Note: Adding read+write is a shortcut to show only a single result from JSON
jq '.jobs[] | .jobname, (.read.bw + .write.bw) * 8 / 1024, (.read.iops + .write.iops)' "$file_base".json \
| xargs -n3 printf '%-20s%4.0f Mbps (%6.0f IOPS)\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment