pub struct BackendIdlePool { /* private fields */ }Expand description
A bounded set of idle, authenticated backend connections, partitioned by
connection identity. Cheap to clone-share behind an Arc.
Implementations§
Source§impl BackendIdlePool
impl BackendIdlePool
Sourcepub fn new(max_idle_per_key: usize, max_total_idle: usize) -> Self
pub fn new(max_idle_per_key: usize, max_total_idle: usize) -> Self
Create a pool that parks at most max_idle_per_key connections per
(node,user,db) identity and max_total_idle across all identities.
A floor of 1 is enforced on each so the pool always retains at least one
reusable connection.
Sourcepub fn checkout(&self, key: &str) -> Option<TcpStream>
pub fn checkout(&self, key: &str) -> Option<TcpStream>
Take a live idle connection for key, or None if the pool has no
usable one (caller then dials a fresh connection). Dead/stale parked
connections are evicted in passing.
Sourcepub fn checkin(&self, key: &str, stream: TcpStream) -> bool
pub fn checkin(&self, key: &str, stream: TcpStream) -> bool
Park a (freshly reset) connection for reuse under key. Returns false
when an idle cap (per-key OR global) is already reached — in that case
the connection is dropped (closed) by being moved in and discarded,
shedding excess capacity.
Sourcepub fn reap_idle(&self, max_age: Duration) -> usize
pub fn reap_idle(&self, max_age: Duration) -> usize
Drop parked connections that have been idle longer than max_age so a
connection the backend has (or will) close on its own idle timeout is
not handed out stale, and idle capacity is released back to the OS.
Returns the number reaped. Intended to be called periodically by a
background task.
Sourcepub fn idle_count(&self) -> usize
pub fn idle_count(&self) -> usize
Total idle connections currently parked across all identities (O(1)).
Sourcepub fn max_total_idle(&self) -> usize
pub fn max_total_idle(&self) -> usize
Global ceiling on parked idle connections.
Sourcepub fn reuses(&self) -> u64
pub fn reuses(&self) -> u64
Number of checkout hits (connections reused rather than dialed fresh).
Sourcepub fn over_capacity(&self) -> u64
pub fn over_capacity(&self) -> u64
Number of check-ins refused for exceeding the per-key idle cap.
Sourcepub fn stale_evicted(&self) -> u64
pub fn stale_evicted(&self) -> u64
Number of stale connections evicted at checkout.
Auto Trait Implementations§
impl !Freeze for BackendIdlePool
impl !RefUnwindSafe for BackendIdlePool
impl Send for BackendIdlePool
impl Sync for BackendIdlePool
impl Unpin for BackendIdlePool
impl UnsafeUnpin for BackendIdlePool
impl UnwindSafe for BackendIdlePool
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> 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 more