Skip to content

Percentiles instead of averages: how to read p95 and p99 response times

B2Bnetwork team · · 6 min

System performance

In brief

The p95 percentile is the time within which 95% of requests complete; p99 is the time within which 99% complete. The average blends fast and very slow responses into one number that often matches no real request and hides customers waiting several seconds. Performance requirements are therefore written in percentiles: the median describes the typical experience, p95 and p99 the worst cases that customers remember and report.

Why the average misleads: an example with 20 measurements

The average is sensitive to a few extreme values and at the same time does not say how many such values there were. Take an explicit example: 20 response times of one operation from a test, sorted ascending, in milliseconds:

120, 125, 130, 130, 135, 140, 140, 145, 150, 150, 155, 160, 165, 170, 180, 190, 210, 260, 900, 2400

MeasureValueHow computed
Average308 mssum of 6,155 ms divided by 20
Median (p50)150 msthe 10th value of 20
p90260 msthe 18th value of 20
p95900 msthe 19th value of 20
p992,400 msthe 20th value of 20, i.e. the maximum

An average of 308 ms is higher than 18 of the 20 measurements, so it describes the typical request poorly. At the same time it does not reveal that two customers waited 0.9 s and 2.4 s. The median shows the typical experience, while p95 and p99 show the tail of the distribution, where problems usually sit: database locks, garbage collection, connection retries.

How a percentile is computed and why tools differ

The simplest method, nearest rank, sorts the measurements and takes the value at the position equal to the percentile times the number of measurements, rounded up. For p95 of 20 measurements that is 0.95 × 20 = 19, so the 19th value. This is how the table above was computed.

Tools also use other methods: interpolation between adjacent values, or approximation from a histogram when there are millions of measurements and they cannot all be stored. With a small sample, two tools can report different p99 for the same data. When comparing results from two tests, or from a test and production, you therefore need to know how each one computes it and compare results from the same tool.

How many measurements you need for p99 to mean anything

A percentile makes sense only when several measurements remain above it. In the example of 20 requests, p99 is simply the maximum, the result of one, possibly random request. A practical rule:

  • for p95 you need at least hundreds of measurements of a given operation in the evaluated window,
  • for p99 at least thousands, so that a few dozen values remain above the threshold,
  • for p99.9 tens of thousands.

That is why percentiles are evaluated for each operation separately and in time windows in which there are enough of these operations. A rare operation, e.g. generating a statement once every few minutes, needs a longer test or an evaluation of the maximum and median instead of p99.

You must not average percentiles

The average of the p95 of two servers is not the p95 of the whole system. If one server handled 90% of traffic with p95 = 200 ms and the other 10% of traffic with p95 = 3 s, the average of the two percentiles is 1.6 s and has nothing to do with the real distribution. The same applies to averaging p95 over consecutive minutes to get the p95 for an hour.

The correct way is to collect histograms, that is, request counts in time buckets, and compute the percentile from their sum. This is how histograms work in Prometheus, among others: the project's documentation explicitly describes that quantiles computed on the client side (the summary type) cannot be meaningfully aggregated, while histograms can.

The tail of the distribution in a distributed system

In an architecture where one page or one transaction calls many services, the tail of a single service becomes the typical case for the customer. A simple calculation: if a page calls 100 services and each of them responds slowly in 1% of cases, the probability that at least one responds slowly is 1 minus 0.99 to the power of 100, or about 63%.

The practical conclusion: requirements for internal services are set at a higher percentile than the requirement for the customer, and in tests you look at traces of individual slow requests, not only at aggregate charts. How to collect such traces is described in the article Observability: logs, metrics and traces.

The second trap concerns the measurement itself. A load generator that sends the next request only after receiving a response simply stops sending when the system stalls. The results contain a few slow requests instead of the hundreds that real customers would have sent in that time, and p99 looks better than it really is. That is why internet traffic is modeled with a constant request arrival rate.

How to write a requirement with a percentile

A good performance requirement states the operation, percentile, threshold, load, measurement window and acceptable error rate. An example for internet banking, explicitly just an example:

  • operation: a domestic transfer from clicking “Send” to confirmation,
  • p50 ≤ 400 ms, p95 ≤ 1.2 s, p99 ≤ 2.5 s,
  • at 120 transfers per second and full traffic of the other operations,
  • evaluated in every 5-minute window after 10 minutes of warm-up,
  • error rate below 0.1%.

A requirement written this way can be checked in a test, carried over to production monitoring and turned into a service objective. How to set such an objective together with the business is described in the article SLOs and error budgets. How such requirements are checked before a sales campaign is shown by the case study Performance testing of the calculator and online sales before a motor third-party liability campaign.

Questions and answers

How does p95 differ from p99?

p95 is the time that 95% of requests do not exceed, and p99 is the time that 99% do not exceed. With a million requests a day, p95 leaves out the 50,000 slowest and p99 only 10,000. The higher the percentile, the better it describes customers' worst experiences, but the more measurements you need for the result to be stable.

Is the median the same as the average?

No. The median (p50) is the middle value: half of requests are faster, half slower. The average is the sum of times divided by the number of requests. With a long-tailed distribution, typical of response times, the average is clearly higher than the median, because individual very slow requests pull it up.

Which percentile should we choose for requirements?

Usually two or three at once: the median for the typical experience, p95 as the main criterion and p99 for critical operations such as payment or login. Higher percentiles, e.g. p99.9, make sense at very high traffic and for internal services that are called many times within one customer transaction.

Why does p99 from a test differ from p99 from production?

Most often for three reasons: the test has a different mix of operations than production, the two systems compute percentiles with different methods or in different time windows, and a load generator in a closed model understates the tail. When comparing, fix the same operation, the same window and the same way of computing.

What it looks like in a project

Your system slows down under load? We'll find where it loses time.

Let's talk

Read more: System performance