pub struct RateLimitedBackend { /* private fields */ }Expand description
Token-bucket rate limiter wrapping any BlockBackend.
tower::Layer-shaped (without the actual tower dependency — the
trait surface here is sync, not request/response): construct via
RateLimitedBackend::new with a wrapped backend and a RateLimit
budget. Every read_at / write_at calls acquire(buf.len()) first;
if the bucket is empty the call blocks (std::thread::sleep) until
enough tokens replenish.
Per 14 § 4.1 and
the D7-adjacent rate-limiter requirement: bound aggregate throughput
within ±5 % of the configured rate. The bucket is refilled
continuously based on wall-clock elapsed time since the last drain,
which gives a smooth ±n % envelope at any rate.
Implementations§
Source§impl RateLimitedBackend
impl RateLimitedBackend
Sourcepub fn new(inner: Arc<dyn BlockBackend>, config: RateLimit) -> Self
pub fn new(inner: Arc<dyn BlockBackend>, config: RateLimit) -> Self
Wrap inner with a rate-limit gate. inner is held by Arc so
the same backend can sit behind several rate-limit slices.