pub struct AdaptiveLimiter { /* private fields */ }Expand description
Shared concurrency gate with additive-increase, multiplicative-decrease backoff.
TypeSafe’s rate limit is a sustained token budget with no quota headers, and several processes may share one key. So on a throttled reply every thread pauses briefly and the allowed concurrency halves; each success grows it back by roughly one slot per round.
A Client owns one and wraps every attempt in acquire
and release. The type is public so that the gate can be inspected, and so
that other transports can share the policy.
Implementations§
Source§impl AdaptiveLimiter
impl AdaptiveLimiter
Sourcepub fn new(max_concurrency: usize, pause: Duration) -> Self
pub fn new(max_concurrency: usize, pause: Duration) -> Self
max_concurrency is the ceiling the limit grows back to (at least one). pause is how
long every thread waits after a throttled reply, scaled by a random factor in [1, 2).
Sourcepub fn limit(&self) -> f64
pub fn limit(&self) -> f64
The current concurrency limit. Starts at the ceiling, halves on throttling, grows back on success; never below one. Fractional, because it grows by a fraction of a slot per reply; the whole part is the number of attempts allowed at once.
Sourcepub fn acquire(&self)
pub fn acquire(&self)
Blocks until there is a free slot under the current limit and no pause is in effect.
Every acquire must be matched by one release.
Sourcepub fn release(&self, throttled: bool)
pub fn release(&self, throttled: bool)
Frees the slot. throttled reports a rate-limited reply (HTTP 429 or 529): the limit
halves and every thread pauses, once per throttling episode rather than once per reply.
Any other outcome grows the limit by about one slot per round of requests. A release
without an acquire frees nothing.