[BE] Set limits on DB connection lifetime
This commit is contained in:
parent
fc411f4ec2
commit
3827605a36
@ -80,6 +80,20 @@ pub async fn init_db() -> Result<(), String> {
|
||||
let start = Instant::now();
|
||||
let pool = MySqlPoolOptions::new()
|
||||
.max_connections(5)
|
||||
/*
|
||||
On some afternoons for some god forsaken reason the idle connections
|
||||
to the db stay alive, but stop responding.
|
||||
|
||||
When this happens, we must restart the server, or wait for all
|
||||
the active connections to timeout.
|
||||
|
||||
Here are some measures to circumvent that:
|
||||
*/
|
||||
// Set the maximum wait time for connections to 10 seconds
|
||||
// In practice, the slowest connections take 1.5 seconds to connect
|
||||
.acquire_timeout(std::time::Duration::from_secs(10))
|
||||
// Set the maximum idle time for connections to 10 minutes
|
||||
.idle_timeout(std::time::Duration::from_secs(10 * 60))
|
||||
.connect(db_url.as_str())
|
||||
.await;
|
||||
log::info!("DB Pool connection took: {:?} ms", start.elapsed().as_millis());
|
||||
|
Loading…
Reference in New Issue
Block a user