pub struct PoolOpts { /* private fields */ }
Expand description
Connection pool options.
let pool_opts = PoolOpts::default()
.with_constraints(PoolConstraints::new(15, 30).unwrap())
.with_reset_connection(false);
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 the 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 require re-authentication for older servers)
The purpose of the reset procedure is to:
- rollback any opened transactions
- 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 increase 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 crate::PooledConn::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.get_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_check_health(self, check_health: bool) -> Self
pub fn with_check_health(self, check_health: bool) -> Self
Sets whether to check connection health upon retrieving it from a pool (defaults to true
).
If true
, then Conn::ping
will be invoked on a non-fresh pooled connection.
§Connection URL
Use check_health
URL parameter to set this value. E.g.
let opts = Opts::from_url("mysql://localhost/db?check_health=false")?;
assert_eq!(opts.get_pool_opts().check_health(), false);