Skip to content

Lesson 2 of 9 · 22m

Benchmarking Without Self-Deception

Microbenchmarks, load generation, and experiment design that produce evidence instead of comforting noise.

The fastest way to waste a performance budget is to benchmark the system you wish you had. Clean caches, one client, no TLS, no background jobs — the graph looks beautiful and means nothing. A benchmark is not a demo. It is an experiment designed to answer a narrow question under controlled, honest conditions.

Start with a question

Bad: "test performance." Good: "does raising innodb_buffer_pool_size from 2 GiB to 8 GiB reduce p95 query latency at 300 concurrent readers?" The question defines workload, duration, metrics, and the maximum acceptable cost of the test.

Write it down with three limits:

Hypothesis: 8 GiB buffer pool reduces p95 read latency by 20%
Workload:   production-like read mix, 300 clients, 15 minutes
Limits:     no production traffic, CPU steal must stay below 5%

Control the environment

On Linux, the machine fights your experiment in ordinary ways. Turbo Boost changes CPU frequency, cron starts at inconvenient times, transparent hugepages allocate memory in bursts, and cloud neighbors steal CPU. Capture the environment before trusting the result:

uname -a
cat /proc/cpuinfo | grep 'model name' | head -1
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null
cat /sys/kernel/mm/transparent_hugepage/enabled
systemctl list-timers --no-pager | head

Run each variant more than once. If the results do not reproduce, you do not have a performance result yet — you have weather.

Use realistic load generators

ab is fine for a smoke test, but closed-loop tools hide queuing effects: each client waits for a response before sending the next request, so the system never experiences real arrival pressure. Prefer tools that can model open-loop arrivals or at least report coordinated omission honestly — wrk2, k6, or a purpose-built replay harness.

wrk2 -t8 -c256 -R2000 -d3m --latency https://service.internal/search

That command says eight threads, 256 connections, a target of 2,000 requests per second, for three minutes. The fixed rate matters because latency at a controlled arrival rate is much easier to compare than "as fast as possible."

Measure latency as a distribution

Averages lie. Use p50, p95, p99, max, throughput, and error rate together. A service can improve mean latency while making the p99 worse by favoring cheap requests and starving expensive ones.

Field notes

  • Warm-up is not optional, but hiding behind a warm cache is cheating; decide whether cache warmth matches production.
  • Compare medians of repeated runs, not the single best run. Best-case numbers are usually marketing, even when self-inflicted.
  • Watch the load generator too. If the generator is saturated, you measured the client, not the server.
  • Save raw output and exact commands. A number without its test harness is a rumor.

Was this lesson helpful?

Sign in to rate