From 075b8a8e276fc464e1f3cc076765a644c6dd49bc Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Wed, 31 May 2023 13:13:16 -0400 Subject: [PATCH 1/5] Change idle timeout default to 10 minutes --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 4468f739..3df14d48 100644 --- a/src/config.rs +++ b/src/config.rs @@ -352,7 +352,7 @@ impl General { } pub fn default_idle_timeout() -> u64 { - 60000 // 1 minute + 600000 // 10 minutes } pub fn default_shutdown_timeout() -> u64 { From 01e9145fea19a93d652e3f5b35897f8415aba0f0 Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Wed, 31 May 2023 19:10:50 -0400 Subject: [PATCH 2/5] Revert lifo for now while we investigate connection thrashing issues --- src/pool.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pool.rs b/src/pool.rs index dff7b8e6..4fa27753 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,6 +1,6 @@ use arc_swap::ArcSwap; use async_trait::async_trait; -use bb8::{ManageConnection, Pool, PooledConnection, QueueStrategy}; +use bb8::{ManageConnection, Pool, PooledConnection}; use bytes::{BufMut, BytesMut}; use chrono::naive::NaiveDateTime; use log::{debug, error, info, warn}; @@ -401,7 +401,6 @@ impl ConnectionPool { .idle_timeout(Some(std::time::Duration::from_millis(idle_timeout))) .max_lifetime(Some(std::time::Duration::from_millis(server_lifetime))) .reaper_rate(std::time::Duration::from_millis(reaper_rate)) - .queue_strategy(QueueStrategy::Lifo) .test_on_check_out(false); let pool = if config.general.validate_config { From ddaab1aba56a5575b9c12140666ee5ba6d0bf13b Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Wed, 31 May 2023 21:11:42 -0400 Subject: [PATCH 3/5] Make queue strategy configurable --- src/config.rs | 11 ++++++++++- src/pool.rs | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3df14d48..7573d39b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -292,6 +292,9 @@ pub struct General { #[serde(default = "General::default_server_lifetime")] pub server_lifetime: u64, + #[serde(default = "General::default_server_round_robin")] // False + pub server_round_robin: bool, + #[serde(default = "General::default_worker_threads")] pub worker_threads: usize, @@ -390,6 +393,10 @@ impl General { pub fn default_prometheus_exporter_port() -> i16 { 9930 } + + pub fn default_server_round_robin() -> bool { + true + } } impl Default for General { @@ -424,7 +431,8 @@ impl Default for General { auth_query: None, auth_query_user: None, auth_query_password: None, - server_lifetime: 1000 * 3600 * 24, // 24 hours, + server_lifetime: Self::default_server_lifetime(), + server_round_robin: false, validate_config: true, } } @@ -983,6 +991,7 @@ impl Config { "Default max server lifetime: {}ms", self.general.server_lifetime ); + info!("Sever round robin: {}", self.general.server_round_robin); match self.general.tls_certificate.clone() { Some(tls_certificate) => { info!("TLS certificate: {}", tls_certificate); diff --git a/src/pool.rs b/src/pool.rs index 4fa27753..b9293521 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,6 +1,6 @@ use arc_swap::ArcSwap; use async_trait::async_trait; -use bb8::{ManageConnection, Pool, PooledConnection}; +use bb8::{ManageConnection, Pool, PooledConnection, QueueStrategy}; use bytes::{BufMut, BytesMut}; use chrono::naive::NaiveDateTime; use log::{debug, error, info, warn}; @@ -389,6 +389,11 @@ impl ConnectionPool { .min() .unwrap(); + let queue_strategy = match config.general.server_round_robin { + true => QueueStrategy::Fifo, + false => QueueStrategy::Lifo, + }; + debug!( "[pool: {}][user: {}] Pool reaper rate: {}ms", pool_name, user.username, reaper_rate @@ -401,6 +406,7 @@ impl ConnectionPool { .idle_timeout(Some(std::time::Duration::from_millis(idle_timeout))) .max_lifetime(Some(std::time::Duration::from_millis(server_lifetime))) .reaper_rate(std::time::Duration::from_millis(reaper_rate)) + .queue_strategy(queue_strategy) .test_on_check_out(false); let pool = if config.general.validate_config { From 3d15710e24a5bf3e9b66395679c952d17f60141a Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Wed, 31 May 2023 21:24:32 -0400 Subject: [PATCH 4/5] test revert idle time out --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 7573d39b..8fb6b2e9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -355,7 +355,7 @@ impl General { } pub fn default_idle_timeout() -> u64 { - 600000 // 10 minutes + 60000 // 10 minutes } pub fn default_shutdown_timeout() -> u64 { From 9b6b6c5cf5191353792c7875f0b4221fd6259996 Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Wed, 31 May 2023 22:10:16 -0400 Subject: [PATCH 5/5] Add pgcat start to python test --- src/config.rs | 2 +- tests/python/tests.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 8fb6b2e9..7573d39b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -355,7 +355,7 @@ impl General { } pub fn default_idle_timeout() -> u64 { - 60000 // 10 minutes + 600000 // 10 minutes } pub fn default_shutdown_timeout() -> u64 { diff --git a/tests/python/tests.py b/tests/python/tests.py index 6108ff21..cd54081f 100644 --- a/tests/python/tests.py +++ b/tests/python/tests.py @@ -63,6 +63,7 @@ def cleanup_conn(conn: psycopg2.extensions.connection, cur: psycopg2.extensions. def test_normal_db_access(): + pgcat_start() conn, cur = connect_db(autocommit=False) cur.execute("SELECT 1") res = cur.fetchall()