Skip to main content

PoolConfig

Struct PoolConfig 

Source
pub struct PoolConfig {
    pub max_connections: u32,
    pub min_connections: u32,
    pub acquire_timeout: Duration,
    pub idle_timeout: Option<Duration>,
    pub max_lifetime: Option<Duration>,
    pub test_before_acquire: bool,
}
Expand description

Tuning for the connection pool a native executor opens. The defaults suit a long-running server; use PoolConfig::serverless for per-instance serverless environments.

Fields§

§max_connections: u32

Hard ceiling on open connections. On serverless this should be tiny (the proxy does the real pooling); on a server, size it to the database’s connection budget divided by the number of app processes.

§min_connections: u32

Connections kept open even while idle. 0 lets the pool drain fully between bursts.

§acquire_timeout: Duration

How long acquire waits for a free connection before erroring.

§idle_timeout: Option<Duration>

Close a connection idle for longer than this. None keeps idle connections indefinitely.

§max_lifetime: Option<Duration>

Recycle a connection older than this regardless of use — guards against server-side timeouts and load-balancer connection caps. None disables.

§test_before_acquire: bool

Ping a connection before handing it out. Costs a round-trip but guarantees liveness — worth it on serverless where sockets get frozen.

Implementations§

Source§

impl PoolConfig

Source

pub fn serverless() -> Self

A single-connection pool tuned for a serverless instance: max=1, short idle timeout, and test_before_acquire so a frozen-then-thawed socket is caught. Pair this with a server-side pooler (RDS Proxy / PgBouncer / Hyperdrive) that fans many instances onto a bounded set of real database connections. See the module docs for why.

Source

pub fn in_memory() -> Self

The only configuration an in-memory SQLite database survives.

Such a database exists only as long as the connection holding it, so a pool must keep exactly one and must never reap it:

  • max_connections: 1, or the second connection is a second, empty database;
  • min_connections: 1 and no idle timeout, or the pool closes the connection while nothing is happening and takes the schema with it.

That second half is the one that bites. serverless looks right — it is a pool of one — and works for the length of a test, then drops the tables two seconds after the last query. The symptom is a server that migrates cleanly at boot and answers no such table to the first request a human makes.

Source

pub fn with_max_connections(self, n: u32) -> Self

Builder-style override of max_connections.

Trait Implementations§

Source§

impl Clone for PoolConfig

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 PoolConfig

Source§

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

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

impl Default for PoolConfig

Source§

fn default() -> Self

Long-running-server defaults: up to 10 connections, drain when idle, recycle hourly, no per-acquire ping.

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, 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.