Skip to content

sysbench - System & Database Benchmark Cheatsheet

sysbench - System & Database Benchmark Cheatsheet

sysbench is a scriptable, multi-threaded benchmark tool based on LuaJIT. It is most famous for database benchmarking (especially MySQL and PostgreSQL via OLTP workloads) but also ships built-in tests for CPU, memory, file I/O, threads, and mutexes. Because workloads are parameterized and scriptable, it produces reproducible numbers for capacity planning, tuning, and before/after comparisons.

Installation

PlatformCommand
Debian/Ubuntusudo apt install sysbench
Fedora/RHELsudo dnf install sysbench
Arch Linuxsudo pacman -S sysbench
macOS (Homebrew)brew install sysbench
From sourcebuild from the akopytov/sysbench repo
Verifysysbench --version

Command Structure

sysbench [testname] [options] {prepare | run | cleanup}
PhasePurpose
prepareCreate the data/files the test needs
runExecute the benchmark
cleanupRemove the test data/files

Common Global Options

OptionDescription
--threads=NNumber of worker threads
--time=NRun for N seconds (0 = until events done)
--events=NCap total events
--rate=NTarget events/sec (rate limiting)
--report-interval=NPrint intermediate stats every N seconds
--warmup-time=NWarm up before measuring
--histogramShow a latency histogram

CPU Benchmark

# Verify primes up to 20000 across 4 threads for 30s
sysbench cpu --cpu-max-prime=20000 --threads=4 --time=30 run
OptionDescription
--cpu-max-prime=NUpper bound for prime calculation (work size)

Key metric: events per second (higher is better).

Memory Benchmark

sysbench memory --memory-block-size=1K --memory-total-size=100G \
  --memory-oper=write --threads=4 run
OptionDescription
--memory-block-sizeSize of each memory operation
--memory-total-sizeTotal data to transfer
`—memory-oper=readwrite`
`—memory-access-mode=seqrnd`

Key metric: MiB/sec transfer rate.

File I/O Benchmark

sysbench fileio --file-total-size=4G prepare
sysbench fileio --file-total-size=4G --file-test-mode=rndrw \
  --time=60 --threads=8 run
sysbench fileio --file-total-size=4G cleanup
OptionDescription
--file-total-sizeTotal size of test files
--file-test-modeseqrd, seqwr, rndrd, rndwr, rndrw
--file-block-sizeI/O block size
--file-fsync-freqfsync frequency

Key metrics: IOPS, throughput (MiB/s), latency.

Threads & Mutex

sysbench threads --threads=64 --thread-yields=1000 --time=30 run
sysbench mutex --threads=64 --mutex-num=4096 run

Database (OLTP) Benchmark

sysbench ships Lua OLTP scripts (oltp_read_write, oltp_read_only, oltp_point_select, etc.).

# Prepare 10 tables of 1,000,000 rows in a MySQL database
sysbench oltp_read_write \
  --db-driver=mysql --mysql-host=127.0.0.1 --mysql-user=bench \
  --mysql-password=secret --mysql-db=benchdb \
  --tables=10 --table-size=1000000 prepare

# Run a 5-minute mixed read/write test with 16 threads
sysbench oltp_read_write \
  --db-driver=mysql --mysql-host=127.0.0.1 --mysql-user=bench \
  --mysql-password=secret --mysql-db=benchdb \
  --tables=10 --table-size=1000000 --threads=16 --time=300 \
  --report-interval=10 run

# Clean up
sysbench oltp_read_write --db-driver=mysql --mysql-db=benchdb cleanup
OptionDescription
`—db-driver=mysqlpgsql`
--tables / --table-sizeDataset shape
oltp_read_only / oltp_write_onlyWorkload mix variants
--db-ps-mode=disableDisable prepared statements

Key metrics: transactions/sec (TPS), queries/sec (QPS), latency percentiles.

Reading Results

MetricMeaning
events/sThroughput of the operation
latency (avg/95th)Response time; watch the 95th percentile
TPS / QPSDatabase transaction/query throughput
min/max/avgDistribution of per-event timing

Common Workflows

# Compare CPU before/after a governor change
sysbench cpu --cpu-max-prime=20000 --threads=$(nproc) --time=30 run

# Storage sanity check on a new disk
sysbench fileio --file-total-size=8G --file-test-mode=rndrw --time=60 run

# Tune MySQL: vary --threads and watch TPS/latency scale

Resources