pub struct AdaptiveGate { /* private fields */ }Expand description
A resizable concurrency permit pool shared by both transfer backends.
The pool starts at start permits and can be retuned live with
set_limit anywhere in [1, ceiling]. It serves
two access paths over one shared logical limit:
- async (
acquire) for the futures/tokio transfer loop, backed bytokio::sync::Semaphore; - blocking (
acquire_blocking) for the rayon store-to-store sync path, backed by a zero-dependency mutex+condvar counting semaphore (mirrors the token-bucket style incrate::transfer).
Both return an RAII guard that releases its permit on drop. set_limit
grows the async pool with add_permits and shrinks it by acquiring and
forgetting permits (the standard
resizable-semaphore technique); for the blocking pool it adjusts the
available count and notifies waiters. Shrinking never revokes a permit
already held — it only reduces how many new permits can be handed out, so
in-flight work drains naturally and shrinking can never deadlock held
permits.
The gate is Clone (cloning shares the same underlying pools via Arc).
Implementations§
Source§impl AdaptiveGate
impl AdaptiveGate
Sourcepub fn new(start: usize, ceiling: usize) -> Self
pub fn new(start: usize, ceiling: usize) -> Self
Builds a gate whose limit starts at start and can be retuned anywhere in
[1, ceiling]. Both start and ceiling are clamped to at least 1, and
start is clamped to ceiling.
Sourcepub fn ceiling(&self) -> usize
pub fn ceiling(&self) -> usize
The construction-time ceiling (the maximum the limit can ever reach).
Sourcepub fn set_limit(&self, n: usize) -> usize
pub fn set_limit(&self, n: usize) -> usize
Retunes the effective concurrency limit live, clamped to [1, ceiling].
Grows the async pool with add_permits; shrinks it by reserving (and
forgetting) the surplus permits so the semaphore’s effective capacity
drops without revoking permits already in flight. Adjusts the blocking
pool’s available count symmetrically and wakes waiters when growing.
Returns the new (clamped) limit.
Sourcepub async fn acquire(&self) -> GatePermit
pub async fn acquire(&self) -> GatePermit
Acquires one async permit, awaiting if the pool is at its current limit.
The returned GatePermit releases the permit on drop.
§Panics
Never under normal use; the semaphore is only closed when the gate is
dropped, which cannot happen while a caller holds an &self.
Sourcepub fn acquire_blocking(&self) -> BlockingGatePermit
pub fn acquire_blocking(&self) -> BlockingGatePermit
Blocking sibling of acquire: parks the calling
OS thread until a permit is free, then returns a guard that releases it
on drop. Used by the rayon store-to-store sync path.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Best-effort count of async permits currently available (for tests/metrics).
Trait Implementations§
Source§impl Clone for AdaptiveGate
impl Clone for AdaptiveGate
Source§fn clone(&self) -> AdaptiveGate
fn clone(&self) -> AdaptiveGate
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 AdaptiveGate
impl RefUnwindSafe for AdaptiveGate
impl Send for AdaptiveGate
impl Sync for AdaptiveGate
impl Unpin for AdaptiveGate
impl UnsafeUnpin for AdaptiveGate
impl UnwindSafe for AdaptiveGate
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