Which percentile belongs in a latency budget?
A replay scheduler reserves time before the next job can start. Each unused millisecond costs one unit of idle capacity. Each millisecond of overrun costs four units of delay. Given a forecast distribution of runtime, how much time should the scheduler reserve? The answer follows from asking which jobs would benefit from one extra millisecond.
Underestimation costs depend on quantile
One observed 150 ms latency; pinball loss penalizes being under budget nine times as much as being over.
Move the reservation a little to the right
Let be the reservation and the runtime. Pay if the job overruns and if it finishes early. Assume positive constant costs, a finite mean runtime, and that all reservations in the relevant range are feasible. For a tiny increase in , an early job costs a little more while a late job costs a little less. At a point of continuity of the runtime distribution , expected cost has slope
Set the slope to zero. The target cumulative probability is . Four units of overrun versus one of idle capacity selects the 80th percentile. With atoms in the distribution the slope can jump over zero. Every satisfying minimizes the convex expected cost.
You can have more than one best reservation
Consider five equally likely workloads taking 2, 3, 4, 8 and 13 ms. Four finish within 8 ms, so 8 meets the 80th-percentile condition. Look at what happens as the reservation moves across the gap before the longest job.
| Reservation | Total unused ms | Total overrun ms | Mean cost per job |
|---|---|---|---|
| 4 ms | 3 | 13 | |
| 8 ms | 15 | 5 | |
| 10 ms | 23 | 3 | |
| 13 ms | 35 | 0 |
Every extra millisecond from 8 to 13 charges four early jobs one unit each and saves four units on the remaining job. The empirical optimum is a whole interval. Different conventions for reporting a sample quantile can return different points in that interval.
Score a quantile forecast without a full distribution
Divide the cost by . The normalized loss for residual is called pinball loss,
At , the 8 ms reservation has mean pinball loss ms. The units are milliseconds because the penalty scales linearly with the size of the miss. To evaluate time-varying forecasts, pair each forecast with its own realized runtime before averaging.
Coverage alone can hide a costly assignment. Suppose two jobs last 1 and 10 ms. Forecasts of 2 and 9 cover one of the two and incur mean loss ms. Swapping the forecasts also covers one of the two, but now the early and late misses are both 8 ms. Mean loss rises to 4 ms. Compare forecasts on the same jobs, at the same quantile level, using a horizon chosen before observing their outcomes.
from fractions import Fraction as F
def pinball(y, q, tau):
return tau * max(y - q, 0) + (1 - tau) * max(q - y, 0)
times = [2, 3, 4, 8, 13]
loss = lambda q: sum(pinball(y, q, F(4, 5)) for y in times) / len(times)
assert all(loss(q) == F(7, 5) for q in range(8, 14))
assert loss(7) > loss(8) and loss(14) > loss(13)
Practice
Cost ratioWhat cost assumption is implicit in reserving the 99th percentile under this model?Show answer
The ratio must equal . A millisecond of overrun has to cost 99 times a millisecond of idle capacity. A fixed charge triggered by any breach would add a different loss term and change this calculation.
Evaluation targetCan a forecaster always minimize tomorrow's cost by reserving the 80th percentile of the entire historical archive?Show answer
That single reservation is fitted to the historical mix. If the scheduler knows the incoming workload size, the relevant target is the conditional runtime quantile for that size. Estimate it on earlier runs and score it on subsequent jobs, including the small and large jobs in the proportions the scheduler actually sees.