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
| Platform | Command |
|---|
| Debian/Ubuntu | sudo apt install sysbench |
| Fedora/RHEL | sudo dnf install sysbench |
| Arch Linux | sudo pacman -S sysbench |
| macOS (Homebrew) | brew install sysbench |
| From source | build from the akopytov/sysbench repo |
| Verify | sysbench --version |
Command Structure
sysbench [testname] [options] {prepare | run | cleanup}
| Phase | Purpose |
|---|
prepare | Create the data/files the test needs |
run | Execute the benchmark |
cleanup | Remove the test data/files |
Common Global Options
| Option | Description |
|---|
--threads=N | Number of worker threads |
--time=N | Run for N seconds (0 = until events done) |
--events=N | Cap total events |
--rate=N | Target events/sec (rate limiting) |
--report-interval=N | Print intermediate stats every N seconds |
--warmup-time=N | Warm up before measuring |
--histogram | Show 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
| Option | Description |
|---|
--cpu-max-prime=N | Upper 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
| Option | Description |
|---|
--memory-block-size | Size of each memory operation |
--memory-total-size | Total data to transfer |
| `—memory-oper=read | write` |
| `—memory-access-mode=seq | rnd` |
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
| Option | Description |
|---|
--file-total-size | Total size of test files |
--file-test-mode | seqrd, seqwr, rndrd, rndwr, rndrw |
--file-block-size | I/O block size |
--file-fsync-freq | fsync 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
| Option | Description |
|---|
| `—db-driver=mysql | pgsql` |
--tables / --table-size | Dataset shape |
oltp_read_only / oltp_write_only | Workload mix variants |
--db-ps-mode=disable | Disable prepared statements |
Key metrics: transactions/sec (TPS), queries/sec (QPS), latency percentiles.
Reading Results
| Metric | Meaning |
|---|
| events/s | Throughput of the operation |
| latency (avg/95th) | Response time; watch the 95th percentile |
| TPS / QPS | Database transaction/query throughput |
| min/max/avg | Distribution 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