Video in progress

The team brought a benchmark result saying "our new file library is 3 times faster". What mistakes show up in IO benchmarks, and what do you require before trusting the result?

Most of the lying in IO benchmarks comes from the page cache: the second read comes from RAM, not the disk. And on writes, measuring without fsync measures the kernel buffer. I require cold/warm cache states, file size relative to RAM, an fsync policy and a prod-like environment.

📖 Answer

The typical "3x speedup" story: the old code ran first and read the file from disk, the new one ran second, from the page cache. Or the new library doesn't fsync on close() and the old one does. Both results are real, but they measure different things.

My requirements for a trustworthy benchmark:

  • JMH. Hand-written System.nanoTime() loops mislead because of JIT warmup, dead code elimination and GC. In JMH, a fresh file each iteration with @Setup(Level.Iteration) and passing the result to a Blackhole.
  • An explicit cache state. "Warm" and "cold" results separately. For cold, on Linux echo 3 > /proc/sys/vm/drop_caches (needs root) or make the file larger than RAM. Whichever state is more common on prod is the one we treat as primary.
  • Equal durability. Both variants with the same fsync/force policy.
  • The environment. A laptop NVMe and a network disk in the cloud (with an IOPS limit) give completely different curves. On cloud disks, the result after the burst credit runs out matters.
  • A distribution, not an average. p50, p99, p99.9: in IO, tail latencies are the main problem.
  • Parallelism. Results with one thread and with 32 threads differ; test with the count that matches the prod load.

Diagnostic tools: iostat -x 1 (disk utilization, queue depth, await), vmstat (IO wait), async-profiler in wall-clock mode, which shows where threads are waiting, while a CPU profile doesn't see IO waits at all. It is useful to first measure the disk's own limit with fio: if the benchmark has already hit the disk limit, no library will speed it up.

And the last requirement: real metrics on prod through A/B or a canary. A 3x in a microbenchmark often turns into 5-10% on prod, because the time goes somewhere else entirely.