pub struct AsyncPool { /* private fields */ }Expand description
A priority-queue–driven allocation pool with memory pressure callbacks.
Implementations§
Source§impl AsyncPool
impl AsyncPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Create a new AsyncPool from the given configuration.
Sourcepub fn enqueue(
&mut self,
req: AsyncAllocRequest,
) -> Result<RequestHandle, AllocError>
pub fn enqueue( &mut self, req: AsyncAllocRequest, ) -> Result<RequestHandle, AllocError>
Submit an allocation request to the queue.
Returns Err(AllocError::PoolFull) if the queue is at capacity.
Sourcepub fn process_queue(
&mut self,
max_allocations: usize,
) -> Vec<(RequestHandle, AllocationId)>
pub fn process_queue( &mut self, max_allocations: usize, ) -> Vec<(RequestHandle, AllocationId)>
Process up to max_allocations pending requests, highest-priority first.
Returns a Vec of (RequestHandle, AllocationId) pairs for every
request that completed successfully. Failed requests are recorded in
the result map and can be queried via get_result.
Sourcepub fn is_ready(&self, handle: RequestHandle) -> bool
pub fn is_ready(&self, handle: RequestHandle) -> bool
Return true if the given request has been processed (successfully or not).
Sourcepub fn get_result(&self, handle: RequestHandle) -> Option<AllocationId>
pub fn get_result(&self, handle: RequestHandle) -> Option<AllocationId>
Return the AllocationId for a successfully completed request, or None
if the request is still pending or failed.
Sourcepub fn get_error(&self, handle: RequestHandle) -> Option<&AllocError>
pub fn get_error(&self, handle: RequestHandle) -> Option<&AllocError>
Return the error for a failed request, or None if pending / successful.
Sourcepub fn register_pressure_callback(
&mut self,
threshold: f64,
cb: Box<dyn Fn(f64) + Send>,
)
pub fn register_pressure_callback( &mut self, threshold: f64, cb: Box<dyn Fn(f64) + Send>, )
Register a callback to be fired when the pool fragmentation exceeds threshold.
The callback receives the current fragmentation score.
Sourcepub fn check_pressure(&self)
pub fn check_pressure(&self)
Evaluate all registered pressure thresholds and fire callbacks if exceeded.
Sourcepub fn throughput_ops_per_sec(&mut self) -> f64
pub fn throughput_ops_per_sec(&mut self) -> f64
Return the allocation throughput in operations per second since the last call.
Sourcepub fn avg_alloc_latency_ns(&self) -> f64
pub fn avg_alloc_latency_ns(&self) -> f64
Return the average allocation latency in nanoseconds over the last
min(n_completed, 256) operations.
Sourcepub fn stats(&self) -> AllocationStats
pub fn stats(&self) -> AllocationStats
Return a snapshot of the arena statistics.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Return the number of pending (not-yet-processed) requests.
Sourcepub fn free(&mut self, id: AllocationId) -> Result<(), AllocError>
pub fn free(&mut self, id: AllocationId) -> Result<(), AllocError>
Free an allocation by id in the underlying arena.
Sourcepub fn arena(&self) -> &ArenaAllocator
pub fn arena(&self) -> &ArenaAllocator
Access the underlying arena (read-only).
Sourcepub fn arena_mut(&mut self) -> &mut ArenaAllocator
pub fn arena_mut(&mut self) -> &mut ArenaAllocator
Access the underlying arena (mutable).
Auto Trait Implementations§
impl Freeze for AsyncPool
impl !RefUnwindSafe for AsyncPool
impl Send for AsyncPool
impl !Sync for AsyncPool
impl Unpin for AsyncPool
impl UnsafeUnpin for AsyncPool
impl !UnwindSafe for AsyncPool
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.