In this lesson · topic 4 of 7
Topic 4
When an averaged p99 is half the real one
7 min read
The simulator produced every number here with a fixed seed, and a test in the repository pins each one. Hover a value to see its setup.
Averaging the host percentiles
Four hosts, with the busiest one carrying 58%measured of the traffic and also the highest share of slow requests. Each host’s p99 ranges from 38 msmeasured on the healthiest to 432 msmeasured on the sickest. The average of the four is 194 msmeasured. The p99 of all requests merged is 369 msmeasured.
A dashboard that averaged the host numbers would show a p99 about half the real one, in a service where one request in fifty is slow. The average is not an approximation of the right answer that is off by a small amount. It answers a different question.
With identical hosts the problem goes away, for a boring reason. Four hosts that look alike average to 377 msmeasured, against a merged value of 376 msmeasured. Averaging looks like it works in tests, where every host is the same, and fails in production, where they are not.
Coarse buckets blur the body
With 10 ms buckets the lab reads a median of 19.1 msmeasured against a true 19.3 msmeasured. Widen the buckets to 100 ms and the same median is reported as 51 msmeasured. Almost every request falls in the first bucket, so the system can only interpolate inside it, and the interpolation has no idea that the real distribution bunches up near 20 ms.
The p95 suffers the same way: 97 msmeasured reported against a true 33 msmeasured. The p99 comes through nearly intact (367 msmeasured against 376 msmeasured), because the slow group is spread over many hundreds of milliseconds and a 100 ms bucket is narrow next to that. Error depends on how wide the bucket is compared with the spread of the values around the percentile, not on the percentile alone.
A generator that waits
One worker takes a request at a time. One request in 500 hits a stall, and the generator runs the worker at half load. The generator that waits for each reply records a p99 of 441 msmeasured. The one that keeps its schedule records 882 msmeasured, which is 2.0 timesmeasured higher. The medians are close (19 msmeasured and 22 msmeasured). The mean tells the story best: 30 msmeasured for the generator that waits and 113 msmeasured for the other.
The gap is not only about stalls. With the stall switched off, the waiting generator still reports a p99 of 392 msmeasured against 799 msmeasured, because every slow request holds up the ones behind it. Raise the load to 80 percent and the open-loop median becomes 76 msmeasured against 19 msmeasured. Queueing, not service time, is what the waiting generator never sees.
Rare slowness hides from the p99
Make the slow share half a percent. The mean is 21.7 msmeasured and the p99 is 41 msmeasured, still on the fast path, while the p99.9 is 527 msmeasured. Raise the slow share to three percent and the p99 becomes 441 msmeasured while the mean is only 31.5 msmeasured. A percentile is blind to anything rarer than the rest of its tail, so the p99 cannot warn you about a problem that touches fewer than one request in a hundred. If you have traffic enough for it to matter, watch the p99.9 as well.
A percentile also needs enough requests behind it. The p99.9 of a thousand requests is decided by a single request, and the number will jump around from one window to the next.
What two clean groups leave out
Real latency does not come in two clean groups, and real slow requests are not independent of load or of each other. The host model here is also very simple: it ties the sick hosts to the busy ones and does not simulate queues inside a host. The lessons carry over, since they come from how percentiles combine and how tests send traffic, but do not expect the exact sizes to match your own system.