Zum Hauptinhalt springen

Your p99 Is Lying: Coordinated Omission in Latency Benchmarks

· 11 Minuten Lesezeit
Clustron Team
Engineering für verteilte Systeme

Here is a result that should make you suspicious of every latency benchmark you have ever trusted. A load generator pushes ten thousand requests per second at a cache, records the latency of each, and reports a p99 of two milliseconds and a p99.9 of four. The numbers are stable across runs. The SLA asks for ten milliseconds at p99, so there is comfortable margin. The change ships. In production, at the very same throughput, the p99 is two hundred milliseconds and the pager goes off.

Nothing about the server changed between the benchmark and production. What changed is that the benchmark was allowed to look away at the exact moment the latency happened. The generator was closed-loop: it sent a request, waited for the response, and only then sent the next one. That one design choice — wait for the reply before issuing the next request — is enough to delete almost the entire tail from the measurement, and it does so in a way that gets worse the worse the stall is.

The name for this is coordinated omission, a term Gil Tene gave it, and the word coordinated is the whole insight: the system under test quietly coordinates with the measurement system, pausing the measurer at precisely the moments the measurer most needs to be taking samples. The requests that go missing are not a random sample of the workload. They are the slow ones, and they go missing because they would have been slow.

How a stall erases its own evidence​

Picture a generator that intends to send one request every tenth of a millisecond — ten thousand a second, evenly spaced. For most of the run the server answers in under a millisecond, the generator keeps pace, and each request is recorded at its true, small latency. Then the server stalls: a GC pause, a lock convoy, a buffer flush, a failover — for one hundred milliseconds it answers nothing.

In a closed-loop generator, exactly one request is in flight when the stall hits. That request blocks for the full hundred milliseconds and is eventually recorded as a single slow sample. And then — this is the part that corrupts the statistics — the generator sends nothing else for the whole hundred milliseconds, because it is still waiting on the reply to the request it already sent. The next request goes out only after the stall clears.

But a system actually taking ten thousand requests a second does not stop sending when the server freezes. Clients keep arriving. During that hundred-millisecond window, a steady arrival rate would have issued roughly a thousand more requests, and every one of them would have had to wait: the first for nearly the full hundred milliseconds, the next for a hair less, down to the last one that just missed the stall. A correct measurement contains a thousand slow samples fanning from ~100ms down to ~0. The closed-loop benchmark contains one. It recorded the stall as a single unlucky request instead of a thousand-request pileup, and your p99 — computed over samples that are 99% fast because the slow ones were never taken — comes out beautiful.

Closed-loop: the generator waits, so the stall's victims are never sentserver stalled 100 ms1 slow sample recordedintended sends during the stall — never issued (dashed) → p99 looks fineConstant arrival rate: every omitted request is a real slow sample~1000 slow samplesfanning 100 ms → 0the true tail the benchmark was supposed to find

Seeing it in your own numbers​

You do not need special tooling to catch coordinated omission; you need one comparison. Run your workload once closed-loop (send, wait, send) and once at a genuinely fixed arrival rate, both at the same target throughput, and compare the high percentiles. If the closed-loop p99.9 is close to the open-loop p99.9, your system has no stalls worth worrying about. If the closed-loop number is a fraction of the open-loop one, the gap is the omitted tail — and the open-loop number is the one production will experience.

A second tell is the shape of the histogram. A closed-loop run against a system that stalls produces a suspiciously clean distribution: a tight cluster of fast samples and a thin, short tail. Real latency under load has a fat tail, because a stall does not delay one request, it delays everyone who arrives while it lasts. If your tail looks too tidy to be true, it usually is — the samples that would have made it fat were never taken.

The two corrections​

The root cause is that a closed-loop generator measures latency from the moment it actually sent a request, and it only sends once the previous reply is in. Both corrections follow from refusing that coupling.

// Closed-loop — silently omits the slow samples.
while (clock.Now() < end) {
var t0 = clock.Now();
var resp = client.Get(key); // BLOCKS here through any server stall
hist.Record(clock.Now() - t0); // one sample, timed from the ACTUAL send
}
// During a 100 ms stall at 10k rps, ~1000 requests are never sent —
// and those are exactly the ones that would have been slow.

// Corrected — time against the INTENDED schedule, and back-fill the gap.
var interval = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / targetRps);
var intended = start;
while (intended < end) {
var resp = client.Get(key);
var latency = clock.Now() - intended; // vs intended, not actual
hist.RecordWithExpectedInterval(latency, interval); // synthesize the omitted samples
intended += interval; // schedule never waits on the server
}

The first correction is to time each request against when it was supposed to start, not when it got to start. If a request was scheduled for t but the generator was still blocked and only issued it at t + 90ms, its latency is at least 90ms before the server does a thing — because a real client with that arrival time would have been waiting that whole time. Measuring from the intended send time charges the queueing delay to the request that suffered it.

The second correction is to back-fill the samples the stall swallowed. This is what HdrHistogram's "expected interval" recording does: when a sample's latency exceeds the interval at which you intended to send, it synthesizes the additional samples that a steady schedule would have produced during the gap, each at the appropriate decreasing latency. One 100ms sample at a 0.1ms interval becomes the ~1000-sample staircase the bottom of the diagram shows. The histogram ends up containing the tail that actually happened rather than the single sample the generator happened to catch.

The cleanest fix of all is to not couple in the first place: drive load from a fixed schedule — an open-loop generator that issues requests at their appointed times regardless of whether earlier replies are back — and the omission never occurs, because nothing ever pauses the sender. The trade is that an open-loop generator can build an unbounded backlog against a server that cannot keep up, which is itself worth knowing: a server that falls behind a fixed arrival rate is a server whose queue is growing without bound, and that is a capacity finding, not a measurement artifact to paper over.

Wrap-up​

Coordinated omission is the quiet reason benchmark latency and production latency disagree: a closed-loop load generator waits for each reply before sending the next, so when the server stalls the generator stalls too, records the one in-flight request as a lone slow sample, and never issues the hundreds of requests a real arrival rate would have piled up behind the stall — the exact requests that would have been slow. The missing samples are not random; they are the tail, deleted because it was slow. You can catch it by comparing a closed-loop run to a fixed-rate run at the same throughput and watching the high percentiles diverge, and you can correct it by timing each request against its intended send time and back-filling the samples the stall swallowed, or avoid it entirely by driving load open-loop from a fixed schedule. The latency floor you measure and the tail you fan out across only mean something if the measurement kept taking samples while the system was slow. A p99 that looked away during the stall is not a p99 — it is the average of the moments nothing went wrong.