Definition · Nearest-rank percentileFor a sample of n values sorted ascending and a fraction q between 0 and 1, the q-th percentile by nearest rank is the value at position r = ⌈q · n⌉. It is one of the observed values, always. Other definitions exist that interpolate between neighbours and can return a number nobody measured; this course uses nearest rank throughout and prints the rank beside the value.
The lab’s preset is twenty measurements in milliseconds, already sorted: 12, 13, 14, 14, 15, 15, 16, 17, 18, 19, 21, 22, 24, 27, 31, 38, 52, 96, 180, 420. The ranks are the whole computation.
n = 20
p50 r = ⌈0.50 × 20⌉ = ⌈10.0⌉ = 10 10th value = 19 ms
p90 r = ⌈0.90 × 20⌉ = ⌈18.0⌉ = 18 18th value = 96 ms
p95 r = ⌈0.95 × 20⌉ = ⌈19.0⌉ = 19 19th value = 180 ms
p99 r = ⌈0.99 × 20⌉ = ⌈19.8⌉ = 20 20th value = 420 ms
mean (12 + 13 + … + 420) / 20 = 1064 / 20 = 266/5 = 53.2 ms
Four numbers describing one sample: 19, 96, 180, 420. The median is 19 ms and the p99 is twenty-two times that. A single summary figure cannot carry that spread, and choosing which single figure to carry is the decision this lesson is about.
Why the mean cannot be repaired
The mean is 53.2 ms. Seventeen of the twenty requests were faster than the mean, and no request in the sample took anything near 53 ms — the values on either side of it are 52 and 96. The mean has landed in a gap. This is not a defect of this sample; it is what happens to an average whenever a few large values are pulled far out, which is the normal shape of a latency distribution.
Example · “The average user sees 53 ms”No user saw 53 ms. The claim, read as a claim about a typical experience, is false in this sample by construction: 85% of the requests were faster and 15% were much slower, and the number in the middle belongs to neither group. What is true of the mean is that twenty requests consumed 20 × 53.2 = 1064 ms of service time in total — a fact about load, which is exactly what a capacity calculation needs and exactly what a latency report does not.
Notice what removing one measurement does. Delete the 420 from the sample in the lab and the p99 of the remaining nineteen becomes 180 ms, less than half of what it was, because at n = 19 the rank ⌈0.99 × 19⌉ = 19 now selects the new maximum. A high percentile of a small sample is a claim resting on one or two observations, and moving one of them moves the answer by a factor of two. The fix is more measurements, not a different formula.
The rank definition also says something about how the value is found. Sorting is the obvious method and it is what the lab shows, because seeing the sorted list is the point. It is not the only method: “Quickselect” on the Algorithms path finds the r-th smallest value without sorting the rest, which is how a system with millions of measurements a second computes the same number. The definition does not change; only the work does.