Struct mysql_async::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
impl PoolOpts
sourcepub fn with_constraints(self, constraints: PoolConstraints) -> Self
pub fn with_constraints(self, constraints: PoolConstraints) -> Self
Creates the default PoolOpts
with the given constraints.
sourcepub fn constraints(&self) -> PoolConstraints
pub fn constraints(&self) -> PoolConstraints
Returns pool constraints.
sourcepub fn with_reset_connection(self, reset_connection: bool) -> Self
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);
sourcepub fn reset_connection(&self) -> bool
pub fn reset_connection(&self) -> bool
Returns the reset_connection
value (see PoolOpts::with_reset_connection
).
sourcepub fn with_abs_conn_ttl(self, ttl: Option<Duration>) -> Self
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.
sourcepub fn with_abs_conn_ttl_jitter(self, jitter: Option<Duration>) -> Self
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.
sourcepub fn abs_conn_ttl(&self) -> Option<Duration>
pub fn abs_conn_ttl(&self) -> Option<Duration>
Returns the absolute TTL, if set.
sourcepub fn abs_conn_ttl_jitter(&self) -> Option<Duration>
pub fn abs_conn_ttl_jitter(&self) -> Option<Duration>
Returns the absolute TTL’s jitter bound, if set.
sourcepub fn with_inactive_connection_ttl(self, ttl: Duration) -> Self
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));
sourcepub fn inactive_connection_ttl(&self) -> Duration
pub fn inactive_connection_ttl(&self) -> Duration
Returns a inactive_connection_ttl
value.
sourcepub fn with_ttl_check_interval(self, interval: Duration) -> Self
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));
sourcepub fn ttl_check_interval(&self) -> Duration
pub fn ttl_check_interval(&self) -> Duration
Returns a ttl_check_interval
value.
Trait Implementations§
impl Eq for PoolOpts
impl StructuralPartialEq for PoolOpts
Auto Trait Implementations§
impl Freeze for PoolOpts
impl RefUnwindSafe for PoolOpts
impl Send for PoolOpts
impl Sync for PoolOpts
impl Unpin for PoolOpts
impl UnwindSafe for PoolOpts
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.