Section 18.1.10

Tail percentiles with a small sample

Definition

A tail percentile §11.16 is a high percentile of a set of measurements, such as p99, the 99th percentile: the value that at least 99% of the measurements do not exceed. It summarizes the slow end, called the tail, of a latency distribution §11.36. A small sample supports a tail percentile with very few measurements. The sample p99 of 30 measurements is simply the largest one, and it estimates the true p99 of the measured process only loosely.

Where it fits

Main entry: Quantile and percentile (§11.16).

The quantile and percentile entry defines percentiles and the rules for computing them from data. Under the nearest-rank rule, the sample percentile at level pp, a fraction between 0 and 1, is the measurement at position ⌈np⌉\lceil np \rceil in the sorted list of nn measurements, where ⌈x⌉\lceil x \rceil means xx rounded up to a whole number. For n=30n = 30 and p=0.99p = 0.99, 30×0.99=29.730 \times 0.99 = 29.7 rounds up to 30, so the sample p99 is the largest measurement. This holds for every nn below 100, because 0.99n0.99n then exceeds n−1n - 1.

The linear rule of the quantile entry instead places the p99 of 30 measurements at position 1+0.99×29=29.711 + 0.99 \times 29 = 29.71 and gives x(29)+0.71(x(30)−x(29))x_{(29)} + 0.71\,(x_{(30)} - x_{(29)}), where x(j)x_{(j)} is the jjth smallest measurement: a value between the two largest measurements, decided by those two alone. On an ECDF §11.17 (empirical cumulative distribution function, the curve of the fraction of measurements at or below each value), each of 30 measurements is a step of 1/301/30, about 3.33 percentage points, too coarse to separate the 97th, 98th and 99th percentiles.

How far a sample p99 can miss follows from counting. Assume that the measurements are independent and identically distributed §11.5 (IID), each drawn separately from the same process, and that the durations have a continuous distribution, in which every single exact value has probability zero. Each measurement then lies below the true p99 with probability 0.99, and all 30 lie below it with probability 0.9930≈0.7400.99^{30} \approx 0.740; then even the largest measurement, the reported p99, is below the true p99. The largest of nn measurements is at least the true p99 with probability 1−0.99n1 - 0.99^{n}, which first reaches 0.95 at n=299n = 299, since 0.99298≈0.050040.99^{298} \approx 0.05004 and 0.99299≈0.049540.99^{299} \approx 0.04954.

Limits and common mistakes

A sample p99, and even a sample maximum §18.5.9, is not a worst-case bound: a rare slow event that did not occur during the measurements leaves no trace in either.

More rows are not more independent measurements. If a slow condition, such as start-up work at the beginning of each run, affects a whole run at once, 3000 timings taken as 100 from each of 30 runs tell about as much about that condition as 30 measurements. Treating them as 3000 independent measurements is pseudoreplication §11.6.

The count of 299 gives only a one-sided statement: the largest measurement is at least the true p99 with probability 0.95. It says nothing about how far above the true p99 that measurement lies, and no count makes a p99 precise for every distribution.

Questions answered

How many samples support this p99?

Very few: only the largest few of the nn measurements, or samples, decide a sample p99, the 99th percentile. Under the nearest-rank rule it is the measurement at position ⌈0.99n⌉\lceil 0.99n \rceil of the sorted list, where ⌈x⌉\lceil x \rceil means xx rounded up, so at most n/100n / 100 measurements lie above it. For any nn below 100 it is the single largest measurement; with 30 measurements, a p99 marker rests on one value.

Suppose the measurements are independent and drawn from one continuous distribution, in which no exact duration has positive probability. The largest of nn measurements is then at least the true p99 with probability 1−0.99n1 - 0.99^{n}: only 1−0.740=0.2601 - 0.740 = 0.260 for 30 measurements, and it first reaches 0.95 at 299 measurements. A figure should therefore state the count, the percentile rule and what counts as one independent measurement.

Related entries: Pseudoreplication (§11.6), Latency distribution and tail (§11.36), Central limit theorem (§15.45), Empirical cumulative distribution function (ECDF) (§11.17), Independent and identically distributed samples (§11.5).