Skip to main content

Overview

db_bench is RocksDB’s primary benchmarking tool for measuring database performance across various workloads. It provides extensive configuration options and supports dozens of benchmark types including sequential writes, random reads, compaction testing, and mixed workloads. The tool is essential for:
  • Performance testing and regression detection
  • Tuning database configurations
  • Evaluating hardware capabilities
  • Comparing different compression algorithms
  • Stress testing concurrent operations

Building db_bench

Build a release binary for accurate performance measurements:
Always use release builds (DEBUG_LEVEL=0) for benchmarking. Debug builds include assertions and logging that significantly impact performance.
For debugging crashes during benchmarks:

Basic Usage

Simple Sequential Write Benchmark

This performs a sequential write test with default settings (1 million keys, 16-byte keys, 100-byte values).

Random Read Benchmark

Available Benchmarks

db_bench supports a comprehensive set of benchmark operations. Specify multiple benchmarks as a comma-separated list in execution order.

Write Benchmarks

1

fillseq

Write N values in sequential key order (async mode)
2

fillrandom

Write N values in random key order (async mode)
3

fillsync

Write N/1000 values in random key order with sync mode
4

overwrite

Overwrite N values in random key order (async mode)

Read Benchmarks

1

readseq

Read N times sequentially
2

readrandom

Read N times in random order
3

readreverse

Read N times in reverse order
4

multireadrandom

Multi-key random reads using MultiGet API

Iterator Benchmarks

  • seekrandom - N random seeks, calling Next() seek_nexts times per seek
  • seekrandomwhilewriting - seekrandom with 1 thread doing overwrites
  • newiterator - Repeated iterator creation

Compaction Benchmarks

  • compact - Compact the entire DB
  • compactall - Compact the entire DB
  • compact0 - Compact L0 into L1
  • compact1 - Compact L1 into L2
  • waitforcompaction - Pause until compaction is complete

Mixed Workload Benchmarks

  • readwhilewriting - 1 writer, N threads doing random reads
  • readrandomwriterandom - N threads doing random read-write
  • updaterandom - N threads doing read-modify-write for random keys

Key Configuration Options

Database Size and Keys

Threading and Duration

Memory Configuration

Compaction Settings

Compression

Advanced Use Cases

Multi-Database Benchmarking

Test across multiple database instances:

Column Family Testing

Skewed Access Patterns

Use exponential distribution for read keys:

Transaction Testing

Backup and Restore

Output Interpretation

db_bench outputs performance metrics including:
  • ops/sec - Operations per second (throughput)
  • MB/s - Megabytes per second processed
  • micros/op - Microseconds per operation (latency)
  • Percentiles - P50, P75, P99, P99.9, P99.99 latencies
Use --histogram=true to get detailed latency distribution histograms.
Example output:

Statistics and Monitoring

Enable detailed statistics:
Available meta operations:
  • stats - Print database statistics
  • resetstats - Reset database statistics
  • levelstats - Print number of files and bytes per level
  • sstables - Print SST file information

Performance Tips

1

Use appropriate cache size

Set --cache_size to approximately the size of your working set for read-heavy workloads.
2

Tune write buffer size

Larger write buffers reduce write amplification but use more memory. Balance based on your RAM availability.
3

Enable NUMA awareness

For multi-socket systems:
4

Adjust thread count

Match --threads to your CPU core count for CPU-bound workloads.

Troubleshooting

Out of Memory

Reduce memory footprint:

Slow Compaction

Increase compaction parallelism:

High Write Amplification

Adjust compaction settings:

Source Reference

The db_bench tool is implemented in:
  • tools/db_bench_tool.cc - Main implementation with all benchmark logic
  • Build with: make db_bench (debug) or DEBUG_LEVEL=0 make db_bench (release)
For a complete list of all available flags and options, run ./db_bench --help or examine the DEFINE_* statements in tools/db_bench_tool.cc:111-708.