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
impl Config
Sourcepub fn max_size(self, n: usize) -> Self
pub fn max_size(self, n: usize) -> Self
Maximum live connections per runtime thread. Must be non-zero.
Sourcepub fn min_idle(self, n: usize) -> Self
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.
Sourcepub fn acquire_timeout(self, t: impl Into<Option<Duration>>) -> Self
pub fn acquire_timeout(self, t: impl Into<Option<Duration>>) -> Self
How long Pool::acquire waits before returning
Error::Timeout. None waits forever.
Sourcepub fn max_lifetime(self, t: impl Into<Option<Duration>>) -> Self
pub fn max_lifetime(self, t: impl Into<Option<Duration>>) -> Self
Hard age cap; a connection older than this is closed instead of reused.
Sourcepub fn idle_timeout(self, t: impl Into<Option<Duration>>) -> Self
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.
Sourcepub fn max_uses(self, n: impl Into<Option<u64>>) -> Self
pub fn max_uses(self, n: impl Into<Option<u64>>) -> Self
Retire a connection after this many checkouts.
Sourcepub fn reap_interval(self, t: Duration) -> Self
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.