Skip to main content

Reservoir

Struct Reservoir 

Source
pub struct Reservoir<M: Detach> { /* private fields */ }
Expand description

A bounded, lock-free pool of detached connections shared by every thread.

Idle connections beyond a shard’s min_idle are detached into this queue, where any thread may claim them. Both ends are wait-free in the common case: ArrayQueue is a fixed-size ring, so parking and stealing never allocate and never take a lock. The only async step, Detach::attach, runs after the entry is already out of the queue.

§Platform support

Only construct this where Detach is sound: io_uring and poll drivers treat attach as a no-op, so fds move freely. Under IOCP a handle is bound to one completion port for life. See Detach for the details.

Implementations§

Source§

impl<M: Detach> Reservoir<M>

Source

pub fn new(capacity: usize) -> Self

Creates a reservoir holding at most capacity connections.

Source

pub fn capacity(&self) -> usize

The most connections this reservoir will hold.

Source

pub fn len(&self) -> usize

Connections currently parked and claimable.

Source

pub fn is_empty(&self) -> bool

True when nothing is parked.

Trait Implementations§

Source§

impl<M: Detach> Debug for Reservoir<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: Detach> Default for Reservoir<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M: Detach> Exchange<M> for Reservoir<M>

Source§

fn park(&self, conn: M::Connection, meta: SlotMeta) -> Parked<M>

Offers an idle connection to other threads. Must not block.
Source§

async fn unpark(&self) -> Unparked<M>

Tries to claim a connection parked by another thread and reattach it to this one.
Source§

fn parked(&self) -> u64

Connections currently parked and claimable.
Source§

fn clear(&self)

Drops every parked connection. Called by Pool::close.

Auto Trait Implementations§

§

impl<M> !Freeze for Reservoir<M>

§

impl<M> RefUnwindSafe for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: RefUnwindSafe,

§

impl<M> Send for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: Send,

§

impl<M> Sync for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: Sync,

§

impl<M> Unpin for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: Unpin,

§

impl<M> UnsafeUnpin for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: UnsafeUnpin,

§

impl<M> UnwindSafe for Reservoir<M>
where ArrayQueue<Entry<<M as Detach>::Parked>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more