DEV Community

Quinn Li
Quinn Li

Posted on

Bill the Slot, Not Just the Token

A discounted model request can hold a worker slot while a paid request waits. Whether it does depends on the implementation: an asynchronous job that releases its permit before backoff does not occupy that slot during the sleep. Instrument the resource whose scarcity you actually want to understand.

Build a slot-seconds ledger

Record each permit acquisition and release, its worker pool and lane. Record queue arrival separately. For a fixed pool of two exclusive slots over a ten-second window, nominal capacity is 20 slot-seconds. Suppose one slot is occupied from second 3 to second 12 and another from second −1 to second 5. After clipping both intervals to the observation window, occupancy is 7 + 5 = 12 slot-seconds. Eight slot-seconds are idle. Counting each request's full duration would charge time outside the window.

For a changing pool, integrate the available slot count over time. Distinguish an idle available slot from a worker taken offline. An attempt holding a permit through a timeout consumes slot-seconds even if no bill arrives; one that releases the permit and waits in a queue accumulates queue delay instead. Record both classes by outcome, including cancellations and timeouts.

Test a proposed lane cap

Replay the measured arrivals with several caps on the discounted lane and document the queue discipline and service-time assumptions. Compare paid-lane wait, completed tasks and deadline misses for both lanes. A cap of zero disables the discounted lane and is meaningful only as a counterfactual. It says little about a policy required to deliver that work. Record what happens if high-priority work arrives while slots are already busy, since a cap is not preemption.

Label the result as a simulation. If service times change with concurrency, outages correlate with arrivals or retries feed a shared queue, a replay with fixed recorded times can mispredict the result. A measured rollout can check the chosen cap. Slot-seconds help attribute contention; converting them to currency requires a separate price or capacity model.

This article was created with AI assistance.

Top comments (0)