Understanding the latency percentiles calculator — concept and principle
Response-time data is almost never symmetric: most requests are fast and a few are very slow. Percentiles describe that shape far better than an average. This calculator takes a list of latency samples and reports the median (p50), the tail percentiles p95 and p99, the mean and the maximum. Engineers use these numbers to write service-level objectives (SLOs), compare releases and spot slow outliers.
How it is calculated
The samples are sorted from smallest to largest: x₁ ≤ x₂ ≤ … ≤ xₙ. For a percentile p (as a fraction), the position is h = (n − 1) × p, counted from 0. If h falls between two samples, the value is interpolated linearly: Q = x₍⌊h⌋₎ + (h − ⌊h⌋) × (x₍⌊h⌋+1₎ − x₍⌊h⌋₎). This is the "type 7" definition of Hyndman and Fan, the default in R, NumPy and spreadsheet PERCENTILE functions. The mean is the sum divided by n; the max is the largest sample. Units are whatever you enter, usually milliseconds.
The principle
A percentile answers "what latency do p percent of requests stay at or below?". The median splits the data in half and ignores how extreme the slow requests are. The mean, by contrast, is pulled up by every slow outlier, so it can describe almost no real request. Tail percentiles matter because users and systems feel the slow cases: a page that makes many backend calls is likely to hit at least one p99 response, so the tail of each service becomes the typical experience of the whole page.
Worked example
- Sorted samples (n = 12): 12, 13, 14, 14, 15, 15, 16, 17, 18, 22, 95, 210.
- p50: h = 11 × 0.5 = 5.5, between 15 and 16 (positions 5 and 6), so 15 + 0.5 × 1 = 15.5 ms.
- p95: h = 11 × 0.95 = 10.45, between 95 and 210, so 95 + 0.45 × 115 = 146.75 ms.
- p99: h = 10.89, so 95 + 0.89 × 115 = 197.35 ms.
- Mean: 461 ÷ 12 = 38.42 ms; max = 210 ms.
How to read the result
Here the median is 15.5 ms, but the mean is more than twice that because of two slow requests. That gap is a sign of a heavy tail worth investigating (garbage collection, cold caches, lock contention, retries). SLOs are usually written on p95 or p99, for example "p99 under 300 ms over 30 days".
Common mistakes
- Averaging percentiles from several servers; percentiles must be computed from the combined data or a mergeable histogram.
- Quoting p99 from a dozen samples; with 12 values it is interpolated between the top two points and is very unstable.
- Comparing results from tools that use different percentile definitions.
Frequently asked questions
Why not just use the average?
Latency distributions are skewed, so the average is moved by rare outliers and hides what typical and worst-case users see.
Is p50 the same as the median?
Yes, p50 is the median.
How many samples do I need for a reliable p99?
Enough that well over 100 samples lie beyond it; many teams want thousands of requests per window.
Sources: R. J. Hyndman and Y. Fan, "Sample Quantiles in Statistical Packages", The American Statistician 50(4), 1996 · J. Dean and L. A. Barroso, "The Tail at Scale", Communications of the ACM 56(2), 2013