Last active
March 18, 2025 10:40
-
-
Save tdebatty/0358da0a2068eca1bf4583a06aa0acf2 to your computer and use it in GitHub Desktop.
sysbench wrapper
This file contains 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 | |
# | |
# bench.sh | |
# https://gist.github.com/tdebatty/0358da0a2068eca1bf4583a06aa0acf2 | |
# | |
# https://cylab.be/blog/351/performance-of-virtual-storage-part-2-qemu | |
# | |
# a wrapper for sysbench | |
# quick run: | |
# bash <(curl -Ls https://gist.githubusercontent.com/tdebatty/0358da0a2068eca1bf4583a06aa0acf2/raw/bench.sh) | |
# | |
# | |
# Changelog | |
# --------- | |
# 20250206 : storage: compute IOPS and use 10G | |
# 20250318 : nicer printing + compute random access 1 MiB block | |
echo " | |
███████╗██╗ ██╗███████╗██████╗ ███████╗███╗ ██╗ ██████╗██╗ ██╗ | |
██╔════╝╚██╗ ██╔╝██╔════╝██╔══██╗██╔════╝████╗ ██║██╔════╝██║ ██║ | |
███████╗ ╚████╔╝ ███████╗██████╔╝█████╗ ██╔██╗ ██║██║ ███████║ | |
╚════██║ ╚██╔╝ ╚════██║██╔══██╗██╔══╝ ██║╚██╗██║██║ ██╔══██║ | |
███████║ ██║ ███████║██████╔╝███████╗██║ ╚████║╚██████╗██║ ██║ | |
╚══════╝ ╚═╝ ╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝ | |
v.20250318 | |
https://gist.github.com/tdebatty/0358da0a2068eca1bf4583a06aa0acf2 | |
" | |
printf "check if sysbench is installed ... " | |
command -v sysbench >/dev/null 2>&1 | |
if [[ $? -ne 0 ]]; then | |
printf "\nsysbench not found, installing ... " | |
sudo apt update -qq | |
sudo apt install -y -qq sysbench | |
fi | |
printf "ok\n" | |
printf "\nCPU : single core\n" | |
printf "=================\n" | |
sysbench cpu run | grep -oP 'events per second:\s+(\d+)' | |
printf "\nCPU : multi core\n" | |
printf "================\n" | |
CORES=$(grep -c processor /proc/cpuinfo) | |
echo "$CORES cores" | |
sysbench cpu run --threads="$CORES" | grep -oP 'events per second:\s+(\d+)' | |
printf "\nMemory\n" | |
printf "======\n" | |
sysbench memory run | grep -oP '(\d+\.\d+) MiB\/sec' | |
printf "\nStorage\n" | |
printf "=======\n" | |
printf "prepare data ... " | |
sysbench fileio --file-total-size=10G --file-num=5 --verbosity=0 prepare | |
printf "ok\n" | |
# ---------- RANDOM (4KiB) | |
printf "\nrandom access (4 KiB block) ...\n" | |
# read | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=rndrd --file-block-size=4k run) | |
iops=$(echo "$output" | grep -oP 'reads/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'read, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "read: $throughput MiB/s ($iops IOPS)\n" | |
# write | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=rndwr --file-block-size=4k run) | |
iops=$(echo "$output" | grep -oP 'writes/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'written, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "write: $throughput MiB/s ($iops IOPS)\n" | |
# ---------- RANDOM (1MiB) | |
printf "\nrandom access (1 MiB block) ...\n" | |
# read | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=rndrd --file-block-size=1M run) | |
iops=$(echo "$output" | grep -oP 'reads/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'read, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "read: $throughput MiB/s ($iops IOPS)\n" | |
# write | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=rndwr --file-block-size=1M run) | |
iops=$(echo "$output" | grep -oP 'writes/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'written, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "write: $throughput MiB/s ($iops IOPS)\n" | |
# ---------- SEQUENTIAL (1MiB) | |
printf "\nsequential access (1 MiB block) ...\n" | |
# read | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=seqrd --file-block-size=1M run) | |
iops=$(echo "$output" | grep -oP 'reads/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'read, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "read: $throughput MiB/s ($iops IOPS)\n" | |
# write | |
output=$(sysbench fileio --file-total-size=10G --file-num=5 --file-io-mode=async --file-fsync-freq=0 --file-test-mode=seqwr --file-block-size=1M run) | |
iops=$(echo "$output" | grep -oP 'writes/s:\s+(\d+\.\d+)' | awk '{print $2}') | |
throughput=$(echo "$output" | grep -oP 'written, MiB/s:\s+(\d+)' | awk '{print $3}') | |
printf "write: $throughput MiB/s ($iops IOPS)\n" | |
printf "\ncleanup ... " | |
rm test_file.* | |
printf "ok\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple wrapper for sysbench. I use it to quickly benchmark Linux computers and servers.
bash <(curl -Ls https://gist.githubusercontent.com/tdebatty/0358da0a2068eca1bf4583a06aa0acf2/raw/bench.sh)