In this lesson · topic 1 of 7
Topic 1
Why the average lies
4 min read
The number on the dashboard
Every service has a latency chart, and the first line on it is usually the average. It is easy to compute, it is one number, and it goes up when things get worse. The trouble is what it hides.
Latency is not spread evenly around its average. Most requests are fast and a few are slow, and the slow ones are slow for different reasons than the fast ones are fast. A cache misses. A garbage collection pause lands on a request. A retry doubles the work. The result is a distribution with a long tail on the right, and the average sits somewhere in the gap between the bulk and the tail, describing neither.
A service with a small slow share
The lab in this lesson serves a stream of requests. On the fast path a request takes about 20 ms. On the slow path, which two percent of requests take, it takes twenty times longer. Nothing else is unusual.
For 20,000 requests from that stream the median is 19.3 msmeasured and the mean is 27.5 msmeasured. A reader of the average would say the service is a little slower than its median and leave it at that. Now look at the 99th percentile, the latency that one request in a hundred exceeds. It is 369 msmeasured, which is about 13 timesmeasured the mean.
Predict first
What a percentile is
Sort every latency from smallest to largest. The median, or p50, is the value half way along. The p99 is the value 99 percent of the way along: 99 percent of requests were faster, one percent were slower. The p99.9 is the value where only one request in a thousand is slower.
Looking further out
The p99 is only one cut. The same stream has a p95 of 33.0 msmeasured and a p99.9 of 724 msmeasured. The p95 is still inside the fast group, so it sits not far above the median. The p99.9 is deep in the slow group. Each percentile tells you how far into the distribution you have to go before the slow path shows up.
The next topic covers how a monitoring system actually computes these, and why the way it combines numbers from many hosts matters as much as which percentile you choose.