Struct PoolOpts

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

Connection pool options.

let pool_opts = PoolOpts::default()
    .with_constraints(PoolConstraints::new(15, 30).unwrap())
    .with_inactive_connection_ttl(Duration::from_secs(60));

Implementations§

Source§

impl PoolOpts

Source

pub fn new() -> Self

Calls Self::default.

Source

pub fn with_constraints(self, constraints: PoolConstraints) -> Self

Creates the default PoolOpts with the given constraints.

Source

pub fn constraints(&self) -> PoolConstraints

Returns pool constraints.

Source

pub fn with_reset_connection(self, reset_connection: bool) -> Self

Sets whether to reset connection upon returning it to a pool (defaults to true).

Default behavior increases reliability but comes with cons:

  • reset procedure removes all prepared statements, i.e. kills prepared statements cache
  • connection reset is quite fast but requires additional client-server roundtrip (might also requires requthentication for older servers)

The purpose of the reset procedure is to:

  • rollback any opened transactions (mysql_async is able to do this without explicit reset)
  • reset transaction isolation level
  • reset session variables
  • delete user variables
  • remove temporary tables
  • remove all PREPARE statement (this action kills prepared statements cache)

So to encrease overall performance you can safely opt-out of the default behavior if you are not willing to change the session state in an unpleasant way.

It is also possible to selectively opt-in/out using Conn::reset_connection.

§Connection URL

You can use reset_connection URL parameter to set this value. E.g.

let opts = Opts::from_url("mysql://localhost/db?reset_connection=false")?;
assert_eq!(opts.pool_opts().reset_connection(), false);
Source

pub fn reset_connection(&self) -> bool

Returns the reset_connection value (see PoolOpts::with_reset_connection).

Source

pub fn with_abs_conn_ttl(self, ttl: Option<Duration>) -> Self

Sets an absolute TTL after which a connection is removed from the pool. This may push the pool below the requested minimum pool size and is indepedent of the idle TTL. The absolute TTL is disabled by default. Fractions of seconds are ignored.

Source

pub fn with_abs_conn_ttl_jitter(self, jitter: Option<Duration>) -> Self

Optionally, the absolute TTL can be extended by a per-connection random amount bounded by jitter. Setting abs_conn_ttl_jitter without abs_conn_ttl has no effect. Fractions of seconds are ignored.

Source

pub fn abs_conn_ttl(&self) -> Option<Duration>

Returns the absolute TTL, if set.

Source

pub fn abs_conn_ttl_jitter(&self) -> Option<Duration>

Returns the absolute TTL’s jitter bound, if set.

Source

pub fn with_inactive_connection_ttl(self, ttl: Duration) -> Self

Pool will recycle inactive connection if it is outside of the lower bound of the pool and if it is idling longer than this value (defaults to DEFAULT_INACTIVE_CONNECTION_TTL).

Note that it may, actually, idle longer because of PoolOpts::ttl_check_interval.

§Connection URL

You can use inactive_connection_ttl URL parameter to set this value (in seconds). E.g.

let opts = Opts::from_url("mysql://localhost/db?inactive_connection_ttl=60")?;
assert_eq!(opts.pool_opts().inactive_connection_ttl(), Duration::from_secs(60));
Source

pub fn inactive_connection_ttl(&self) -> Duration

Returns a inactive_connection_ttl value.

Source

pub fn with_ttl_check_interval(self, interval: Duration) -> Self

Pool will check idling connection for expiration with this interval (defaults to DEFAULT_TTL_CHECK_INTERVAL).

If interval is less than one second, then DEFAULT_TTL_CHECK_INTERVAL will be used.

§Connection URL

You can use ttl_check_interval URL parameter to set this value (in seconds). E.g.

let opts = Opts::from_url("mysql://localhost/db?ttl_check_interval=60")?;
assert_eq!(opts.pool_opts().ttl_check_interval(), Duration::from_secs(60));
Source

pub fn ttl_check_interval(&self) -> Duration

Returns a ttl_check_interval value.

Trait Implementations§

Source§

impl Clone for PoolOpts

Source§

fn clone(&self) -> PoolOpts

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PoolOpts

Source§

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

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

impl Default for PoolOpts

Source§

fn default() -> Self

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

impl Hash for PoolOpts

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PoolOpts

Source§

fn eq(&self, other: &PoolOpts) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PoolOpts

Source§

impl StructuralPartialEq for PoolOpts

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T