Module limits
Expand description
Concurrency and rate limits for steps.
engine.limit("stripe", LimitSpec { concurrent: 10, per_second: 100.0 })
defines a limit; a step run with StepOptions::limit("stripe") takes a
permit before its function runs and returns it when the attempt ends.
A step waiting for a permit holds nothing else (its gate is already
durable). After a crash a new attempt requests a fresh permit.
Waiting steps form a WaitQueue: the highest Priority::level is
served first; within a level, steps are grouped by
Priority::fairness_key and the groups take turns, each taking up to
Priority::fairness_weight permits per turn, so one key with a deep
backlog cannot starve the others. Within a key, arrival order. With the
default priority every step is in one group at one level: plain arrival
order.
The priority is not journaled. It comes from the step’s options, which the code passes again when it reaches the step after a crash, so the request is made again with the same priority and key.
In one process every shard shares one LocalLimits: a counting
semaphore and a token bucket per limit in front of one wait queue. In
server mode the limit lives on the server and permits are leases (see
fusee_server::RemoteLimits), so a crashed holder’s permits come back
when its lease expires; the server keeps the wait queue and decides with
the same WaitQueue.
Modules§
- answer
- The replicated limit ledger answers an acquire with one number:
0queued,1the asked ticket granted,2 + delayask again afterdelayms (the rate limit refills then), or the top bit plus the zigzag distance to another ticket of the same session that was granted instead (the one the wait queue serves next).
Structs§
- Limit
Info - A limit and its permits right now (
crate::Engine::limits). - Limit
Spec - A limit’s size.
- Local
Limits - Limits shared by every shard of one process.
- Priority
- Where a step waiting for a permit stands. The default (level 0, no key, weight 1) is plain arrival order.
- Wait
Queue - Waiters for one limit’s permits: highest level first, then the levels’ fairness keys in turn (weighted round-robin), then arrival order within a key. Deterministic, so a replicated server can apply it as a state machine. A queue of default-priority waiters only saves as the plain arrival-order list queues always saved as; any other as its levels.
Enums§
- Acquire
- The answer to an acquire.
Traits§
- Limit
Backend - Where limits live.