Moving State and Reserving Capacity

Lesson 3 of 4

Reserve Capacity for Critical Work

Estimated time: 10 minutes

Not all work should share one pool

When every task draws on one shared pool, a burst of ordinary work can consume the room that a task which cannot wait needs. The critical task is then delayed by traffic that matters far less, and the delay is invisible until someone traces the queue.

Name the work that cannot wait

A reservation protects a named class of work, not a particular task. Without a name there is nothing to reserve against, and the slice drifts into general use.

Hold the slice back, let others borrow when idle

The slice belongs to the named work, but others may borrow it while it is idle. The borrow must be revocable: when the named work arrives, the borrowed slot returns and the ordinary task is queued.

def grant(slice_name, task):
    if task.klass == slice_name:
        return True
    return slice_is_idle(slice_name)

Alert when the slice is spent by others

If ordinary work runs in the reserved slice for long stretches, the guarantee has quietly stopped existing. Measure the slice's use by class and alert on the drift.