Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Tunables for a Pool.

§Sizing is per-shard

compio is a thread-per-core runtime, so this pool keeps one independent shard per runtime thread (see the crate docs). Config::max_size and Config::min_idle therefore apply per shard, not to the process. A pool with max_size = 8 running on 4 compio threads can hold up to 32 connections in total.

This is deliberate: a global cap requires a cross-thread semaphore on the acquire fast path, which is exactly the contention thread-per-core runtimes exist to avoid.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Starts from the defaults.

Source

pub fn max_size(self, n: usize) -> Self

Maximum live connections per runtime thread. Must be non-zero.

Source

pub fn min_idle(self, n: usize) -> Self

Idle connections each shard keeps thread-locally. Clamped to max_size.

This doubles as the split point between local caching and sharing: with a Reservoir installed, returned connections beyond min_idle are parked for other threads to claim. Leaving it at 0 therefore means every connection goes back to the shared stack and each checkout pays a mutex. Set it to your steady-state per-thread concurrency to keep the hot path lock-free and share only the surplus.

Source

pub fn acquire_timeout(self, t: impl Into<Option<Duration>>) -> Self

How long Pool::acquire waits before returning Error::Timeout. None waits forever.

Source

pub fn max_lifetime(self, t: impl Into<Option<Duration>>) -> Self

Hard age cap; a connection older than this is closed instead of reused.

Source

pub fn idle_timeout(self, t: impl Into<Option<Duration>>) -> Self

How long a connection may sit unused in the free list before being reaped.

Source

pub fn max_uses(self, n: impl Into<Option<u64>>) -> Self

Retire a connection after this many checkouts.

Source

pub fn reap_interval(self, t: Duration) -> Self

How often each shard’s background reaper runs.

The reaper is what actually enforces idle_timeout and max_lifetime on connections nobody is asking for, and what refills min_idle.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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