<< back to Guides

⚑ Performance Benchmarking Guide for High-Performance Databases

Designing meaningful, reproducible benchmarks is essential for tuning databases under real-world workloads. This guide outlines key principles, strategies, and pitfalls to avoid when benchmarking latency-sensitive systems like high-performance databases, caches, and analytics engines.


🎯 Goals


1. πŸ§ͺ Designing Real-World Benchmarks

"If your benchmark doesn't reflect real-world usage, your tuning won't either."

βœ… Strategies

# Example: Load test with realistic query patterns
wrk -t4 -c100 -d30s --script=benchmark.lua http://dbproxy.local/query

❌ Pitfalls


2. βš™οΈ Infrastructure Sizing & Concurrency

"Always rightsize infra to your workload, not the other way around."

βœ… Tips

# Example: K6 test with ramping VUs and fixed throughput
export let options = {
  stages: [
    { duration: '1m', target: 50 },
    { duration: '5m', target: 100 }
  ],
  rps: 100,
};

3. ⚠️ Recognize and Mitigate Coordinated Omission

"Your benchmark might lie if you don’t simulate realistic delays."

What Is It?

If you measure response time only when you send a request, you’ll miss the long delays that occur under load when the system is overloaded.

βœ… Solutions

# Use HdrHistogram to record actual vs intended timing
recordValueWithExpectedInterval(actual_latency_ms, expected_interval_ms)

Learn More


4. πŸ“ˆ Understand Latency Distributions (Not Just Averages)

β€œP99 latency tells you what your worst users experience.”

βœ… Key Metrics

Metric Why It Matters
Avg latency Misleading in non-normal distributions
P95 / P99 Critical for SLAs, SLOs
Max latency Surface worst-case stalls
Std. Dev Variability across requests
# Example: Wrapping a test with latency histogram
import hdrhistogram
hist = hdrhistogram.HdrHistogram(1, 3600000, 3)

for latency in results:
    hist.record_value(latency)

print("P95:", hist.get_value_at_percentile(95))
print("P99:", hist.get_value_at_percentile(99))

5. πŸ”„ Measure Warm-up, Throttling, and Internals

βœ… Include:

# Warm-up example: Ignore first N seconds
start_time = time.time()
for i in range(N):
    latency = run_query()
    if time.time() - start_time > 30:
        record(latency)

6. πŸ“Š Latency vs Throughput vs Resource Usage

β€œA high-QPS system that spikes CPU at 80% isn't fast β€” it's on fire.”

βœ… Correlate:

Use tools like:


7. βœ… Reporting Best Practices

βœ… Always Report:

# Basic benchmark report structure
## Setup
- DB: Postgres 15
- Host: 8-core AMD, 64GB RAM
- Client: wrk, 4 threads, 100 connections

## Results

| Metric    | Value      |
|-----------|------------|
| Avg Lat   | 5.2 ms     |
| P95       | 12.1 ms    |
| P99       | 21.7 ms    |
| Max       | 65.0 ms    |
| Throughput| 12,700 RPS |

## Observations
- P99 spikes during connection churn
- IOWait correlates with spikes on write-heavy phases

βœ… Summary Checklist


πŸ“š Further Reading


<< back to Guides