pub struct BlockingRateLimiter { /* private fields */ }Expand description
A synchronous token-bucket rate limiter for the store-to-store sync path.
This is the blocking sibling of RateLimiter. The
StreamStore methods are synchronous and
drive their backends’ async SDK calls on an internal runtime via block_on,
so the store-to-store sync orchestrator parallelizes them across a rayon
thread pool of plain OS threads — it cannot use the async RateLimiter
(awaiting inside a block_on-ing rayon worker would nest tokio runtimes).
acquire_blocking therefore parks
the calling OS thread with std::thread::sleep instead of .await.
When max_bytes_per_sec is None (or Some(0)), the limiter is unlimited
and acquire_blocking returns
immediately. Otherwise tokens refill at max_bytes_per_sec per second,
allowing a burst of up to ~1 second’s worth of budget. The token math
mirrors RateLimiter::acquire exactly.
The limiter is Arc-shareable and Clone (cloning shares the same
underlying bucket), so every rayon worker throttles against one aggregate
budget.
Implementations§
Source§impl BlockingRateLimiter
impl BlockingRateLimiter
Sourcepub fn new(max_bytes_per_sec: Option<u64>) -> Self
pub fn new(max_bytes_per_sec: Option<u64>) -> Self
Builds a synchronous limiter. None (or Some(0)) yields an unlimited,
no-op limiter whose
acquire_blocking never waits.
Sourcepub fn set_rate(&self, bytes_per_sec: Option<u64>)
pub fn set_rate(&self, bytes_per_sec: Option<u64>)
Retunes the limiter’s aggregate byte-rate cap live (the synchronous
sibling of RateLimiter::set_rate). Same semantics: None/Some(0)
switches to unlimited and empties the bucket; Some(r > 0) installs a
bucket refilling at r bytes/sec (priming a full burst when switching
from unlimited).
Sourcepub fn acquire_blocking(&self, n: u64)
pub fn acquire_blocking(&self, n: u64)
Blocks the calling OS thread until n bytes of budget are available,
refilling the bucket at the configured rate. Unlimited limiters return
immediately.
A single request larger than the bucket capacity is still satisfied: the
bucket is allowed to go negative and the caller waits out the deficit,
so throttling is correct even for objects bigger than one second’s worth
of budget. Mirrors RateLimiter::acquire, but parks the thread with
std::thread::sleep instead of awaiting.
Trait Implementations§
Source§impl Clone for BlockingRateLimiter
impl Clone for BlockingRateLimiter
Source§fn clone(&self) -> BlockingRateLimiter
fn clone(&self) -> BlockingRateLimiter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BlockingRateLimiter
impl RefUnwindSafe for BlockingRateLimiter
impl Send for BlockingRateLimiter
impl Sync for BlockingRateLimiter
impl Unpin for BlockingRateLimiter
impl UnsafeUnpin for BlockingRateLimiter
impl UnwindSafe for BlockingRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request