Definition
The latency of a request is the time from a defined start event, such as sending the request, to a defined completion event, such as receiving the reply. Latencies vary from request to request; the latency distribution describes how often each duration occurs. Its tail is the slow end: the rare requests that take much longer than typical. High percentiles §11.16 summarize the tail; p99, the 99th percentile, is the latency that at least 99% of requests do not exceed. The mean and the median §11.13 say little about the tail.
The idea
A service answers 99 of every 100 requests in 1 millisecond and the remaining one in 100 milliseconds, because that request waits behind a slow operation such as a write to flash memory §6.6. The median is 1 millisecond and the mean is under 2 milliseconds, yet one request in a hundred takes a hundred times longer than typical. Whether the service is good enough depends on that request: in a control loop it is a missed deadline, in a user interface a visible pause.
The tail matters more than its size suggests when one task waits for many requests. Suppose a web page needs replies from 100 servers, and each reply independently takes more than 1 second with probability 0.01. The page is fast only if all 100 replies are fast, which happens with probability . So about 63% of page loads wait at least 1 second, although each server is slow only 1% of the time. Jeffrey Dean and Luiz André Barroso used this example in their article “The Tail at Scale” (2013) [480].
Estimating the tail is hard for the same reason that it matters: tail events are rare. Of requests, only about fall above the true p99, so an estimate of p99 rests on those few observations, not on all . The support of a tail estimate is the number of observations beyond it.
How it works
Define the measurement. Name the start event, the completion event and the clock. Name the population: every request sent, or only the requests that succeeded. A request that fails or never completes has a latency of at least the time already waited, and dropping it removes exactly the slowest cases. Recording it as “at least this long” is called censoring §11.28.
Generate the load the question is about. A load generator that sends the next request only after the previous reply arrives sends nothing during a stall, so a 1-second stall delays one recorded request instead of the many requests that independent clients would have sent during that second. This error is called coordinated omission. Avoid it by sending requests on a fixed schedule and timing each one from its scheduled send time.
Look at the whole distribution. Plot the ECDF §11.17 (empirical cumulative distribution function), which gives for each latency the fraction of requests that took at most ; a logarithmic latency axis keeps the tail visible.
Report summary values with their basis: the median, the tail percentiles and the maximum; the rule used to compute a percentile from a sample; the number of requests; and the number of observations beyond each tail percentile.
Attach uncertainty. A confidence interval §11.18 for a percentile follows from counting how many sorted observations lie below it, with no assumption about the shape of the distribution. Resampling methods such as the bootstrap §11.19 are unreliable for extreme percentiles of small samples, because a resample never contains a value above the observed maximum.
Count independent evidence. One stall delays every request in flight, so count stall episodes as well as slow requests.
Worked example
One slow request among 100. Take 99 latencies of 1 millisecond and one of 100 milliseconds. The median is 1 millisecond, the mean is milliseconds, and the maximum is 100 milliseconds. The nearest-rank rule takes the th smallest value as p99, where is rounded up to a whole number; that value is 1 millisecond. The linear-interpolation rule, the default in the statistics software R and NumPy §12.29, uses position in the sorted list: the 99th value plus 0.01 of the gap to the 100th, milliseconds. Both rules report a p99 under 2 milliseconds for a sample that contains a 100-millisecond request, and they disagree with each other.
How often a sample misses the tail. Suppose the true p99 is 20 milliseconds, so each request independently exceeds 20 milliseconds with probability 0.01. With requests, the expected number above 20 milliseconds is , and the probability that none is above is . In about 37% of such runs, then, all 100 observations, the maximum included, lie below the true p99, and every percentile estimate from the run is too low. With the expected number above is 10, and the probability of none is .
What 1000 requests support. With , the nearest-rank estimate of p99 is the th smallest value. The interval from the 983rd to the 996th smallest value contains the true p99 with probability 0.957, so it is a 95% confidence interval: the true p99 lies between the 18th-largest and the 5th-largest observation. With , the sample cannot give a 95% upper bound for p99 at all, because even the largest value exceeds the true p99 only with probability . The maximum first becomes a 95% upper bound for p99 at , since is below 0.05 while is not.
Stated precisely
Let be the latency of one request, with cumulative distribution function , the probability that a request takes at most . Let be the quantile of at level , the smallest with ; p99 is . Let be the latencies of requests, and let be the same values sorted, so that , called the th order statistic, is the th smallest. The nearest-rank estimate of is .
Assume (A1) the latencies are independent of one another; (A2) they all have the same distribution ; (A3) is continuous, so that no observation equals exactly; and (A4) every request in the population is recorded with its full latency. Then the number of observations at or below has the binomial distribution with trials and success probability : where is the number of ways to choose of the requests. Three consequences follow.
The expected number of observations above is : one per 100 requests for p99.
The sample maximum §18.5.9 lies below with probability .
For whole numbers , holds exactly when , and holds exactly when . Hence so the interval from to is a confidence interval with that coverage for every continuous .
If (A1) fails because slow requests come in bursts, the number of independent tail events is smaller than the number of slow requests, and the binomial calculation overstates the evidence. If (A4) fails because slow requests are dropped, every estimate of a tail percentile is biased low.
Limits and common mistakes
The sample maximum is not a worst case. A longer run, a different input or rarer interference can exceed it. A guaranteed bound comes from analysis, as in worst-case execution time §9.33 (WCET) analysis, not from a sample.
Slow requests are not always independent observations. A 50-millisecond pause delays every request in flight, so 30 slow requests caused by 3 pauses carry about 3 independent pieces of evidence; treating them as 30 is pseudoreplication §11.6.
Dropping failures and timeouts §9.34 removes the tail, a form of survivorship bias §11.30. An ECDF that reaches 1 describes the recorded requests only. Record requests that never completed as censored observations instead.
Percentiles cannot be averaged. The mean of the p99 values of ten runs is not the p99 of all their requests together; combine the raw latencies, or histograms with identical bins, and compute the percentile once.
Percentiles do not add. The p99 of a two-step operation can be larger or smaller than the sum of the two steps’ p99 values, because the slow cases of the two steps need not fall in the same requests.
The measurement can change the tail. Recording every request adds work (instrumentation overhead §11.32), and the first requests after a start, before caches and buffers settle, often follow a different distribution from the rest.
Questions answered
How many observations support an estimated p99?
Only the observations above an estimated p99 support it, and they are about 1 in 100 of the sample. The 99th percentile, p99, is the latency that at least 99% of requests do not exceed, so its estimate is set by the slowest 1%: about of independent requests, which is one observation out of 100 and ten out of 1000. With 100 requests the estimate is essentially the second-largest value, and even the largest value exceeds the true p99 only with probability , so 100 requests cannot give a 95% upper bound for p99. The largest value becomes a 95% upper bound only from 299 independent requests on. With 1000 requests, the 983rd to 996th smallest values form a 95% confidence interval for p99.
Count independent evidence, not rows: requests delayed by the same stall are one piece of evidence, and dropped failures and timeouts remove exactly the tail. Report the number of requests, the number of observations beyond the estimate, the rule used to compute the percentile, and a confidence interval.
Related entries: Quantile and percentile (§11.16), Censoring (§11.28), Outlier handling (§11.31), Empirical cumulative distribution function (ECDF) (§11.17), Pseudoreplication (§11.6), Worst-case execution time (WCET) (§9.33). Further reading: [480].