In this lesson · topic 6 of 7
Topic 6
Turning latency into a good-events ratio
7 min read
Teams often write a latency target as “p99 under 500 ms”. It reads well and it is awkward to run. The same target has a second form that behaves much better with the tools in this lesson.
Two ways to say the same thing
“The p99 is under 500 ms” means that at least 99 percent of requests finished in under 500 ms. Flip the sentence around and it becomes a ratio: good events are requests under 500 ms, valid events are all requests, and the target is a good-to-valid ratio of 0.99.
The two forms agree for any single window. They differ in what you can do with them. Counts can be summed: add the good and total counts from fifty hosts, or sixty minutes, and divide once. Percentiles cannot. The ratio also feeds error budgets and burn rates directly, because the bad share is exactly what an SLO budget spends.
Reading it from buckets
Prometheus-style histograms store cumulative counts. Each bucket, labelled le for “less than or equal”, counts every request at or below its boundary. Suppose a window of 10,000 requests produced this:
Bucket (le) |
Cumulative requests |
|---|---|
| 0.1 s | 7,000 |
| 0.25 s | 9,000 |
| 0.5 s | 9,900 |
| 1 s | 9,990 |
| +Inf | 10,000 |
For a target of 99 percent under 500 ms, the good count is the le=0.5 bucket: 9,900. The ratio is 9,900 over 10,000, or 99.0 percent. The target is met with nothing to spare. For a target of 99.9 percent under one second, the le=1 bucket gives 9,990 over 10,000, which is 99.9 percent. Reading the SLI is one division of two counters, with no interpolation.
Predict first
When the threshold falls between buckets
With the threshold at 300 ms, 9,000 requests are certainly good and 100 are certainly bad. The 900 in between are unknown. Interpolation assumes they are spread evenly inside the bucket, which puts 20 percent of them, or 180, under 300 ms. That gives 9,180 good requests, or 91.8 percent: a precise-looking number resting on an assumption. If those requests really sit near 280 ms, the share is almost 99 percent. If they sit near 450 ms, it is 90 percent.
The fix is to choose bucket boundaries from your objectives instead of the other way round. If the SLO says 300 ms, make 0.3 a boundary. If you also keep a warning threshold at 200 ms, add 0.2. A small set of boundaries placed at the numbers you promise is more accurate for SLOs than a large set spread evenly.
What the budget looks like
A 99 percent under 500 ms objective leaves a budget of one percent slow requests. In the table, 100 of 10,000 are slow, so the window sits exactly on the budget rate and the burn rate is 1. If a bad release pushes another 300 requests past 500 ms, the bad share is 4 percent, the burn rate is 4, and a 30-day budget would last about a week at that rate. The multi-window alert from the SLO lesson works on this number without change, which is the real payoff of the ratio form.
Sources
- Histograms and summaries, Prometheus documentation, on cumulative buckets and the error of quantile estimation.
- Betsy Beyer, Niall Richard Murphy, David K. Rensin, Kent Kawahara and Stephen Thorne (eds.), The Site Reliability Workbook, chapter “Implementing SLOs”, O’Reilly, 2018.