mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-28 03:06:29 +00:00
Make queue strategy configurable and default to Fifo (#463)
* Change idle timeout default to 10 minutes * Revert lifo for now while we investigate connection thrashing issues * Make queue strategy configurable * test revert idle time out * Add pgcat start to python test
This commit is contained in:
@@ -292,6 +292,9 @@ pub struct General {
|
|||||||
#[serde(default = "General::default_server_lifetime")]
|
#[serde(default = "General::default_server_lifetime")]
|
||||||
pub server_lifetime: u64,
|
pub server_lifetime: u64,
|
||||||
|
|
||||||
|
#[serde(default = "General::default_server_round_robin")] // False
|
||||||
|
pub server_round_robin: bool,
|
||||||
|
|
||||||
#[serde(default = "General::default_worker_threads")]
|
#[serde(default = "General::default_worker_threads")]
|
||||||
pub worker_threads: usize,
|
pub worker_threads: usize,
|
||||||
|
|
||||||
@@ -352,7 +355,7 @@ impl General {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_idle_timeout() -> u64 {
|
pub fn default_idle_timeout() -> u64 {
|
||||||
60000 // 1 minute
|
600000 // 10 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_shutdown_timeout() -> u64 {
|
pub fn default_shutdown_timeout() -> u64 {
|
||||||
@@ -390,6 +393,10 @@ impl General {
|
|||||||
pub fn default_prometheus_exporter_port() -> i16 {
|
pub fn default_prometheus_exporter_port() -> i16 {
|
||||||
9930
|
9930
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_server_round_robin() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for General {
|
impl Default for General {
|
||||||
@@ -424,7 +431,8 @@ impl Default for General {
|
|||||||
auth_query: None,
|
auth_query: None,
|
||||||
auth_query_user: None,
|
auth_query_user: None,
|
||||||
auth_query_password: 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,
|
validate_config: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -983,6 +991,7 @@ impl Config {
|
|||||||
"Default max server lifetime: {}ms",
|
"Default max server lifetime: {}ms",
|
||||||
self.general.server_lifetime
|
self.general.server_lifetime
|
||||||
);
|
);
|
||||||
|
info!("Sever round robin: {}", self.general.server_round_robin);
|
||||||
match self.general.tls_certificate.clone() {
|
match self.general.tls_certificate.clone() {
|
||||||
Some(tls_certificate) => {
|
Some(tls_certificate) => {
|
||||||
info!("TLS certificate: {}", tls_certificate);
|
info!("TLS certificate: {}", tls_certificate);
|
||||||
|
|||||||
@@ -389,6 +389,11 @@ impl ConnectionPool {
|
|||||||
.min()
|
.min()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let queue_strategy = match config.general.server_round_robin {
|
||||||
|
true => QueueStrategy::Fifo,
|
||||||
|
false => QueueStrategy::Lifo,
|
||||||
|
};
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"[pool: {}][user: {}] Pool reaper rate: {}ms",
|
"[pool: {}][user: {}] Pool reaper rate: {}ms",
|
||||||
pool_name, user.username, reaper_rate
|
pool_name, user.username, reaper_rate
|
||||||
@@ -401,7 +406,7 @@ impl ConnectionPool {
|
|||||||
.idle_timeout(Some(std::time::Duration::from_millis(idle_timeout)))
|
.idle_timeout(Some(std::time::Duration::from_millis(idle_timeout)))
|
||||||
.max_lifetime(Some(std::time::Duration::from_millis(server_lifetime)))
|
.max_lifetime(Some(std::time::Duration::from_millis(server_lifetime)))
|
||||||
.reaper_rate(std::time::Duration::from_millis(reaper_rate))
|
.reaper_rate(std::time::Duration::from_millis(reaper_rate))
|
||||||
.queue_strategy(QueueStrategy::Lifo)
|
.queue_strategy(queue_strategy)
|
||||||
.test_on_check_out(false);
|
.test_on_check_out(false);
|
||||||
|
|
||||||
let pool = if config.general.validate_config {
|
let pool = if config.general.validate_config {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ def cleanup_conn(conn: psycopg2.extensions.connection, cur: psycopg2.extensions.
|
|||||||
|
|
||||||
|
|
||||||
def test_normal_db_access():
|
def test_normal_db_access():
|
||||||
|
pgcat_start()
|
||||||
conn, cur = connect_db(autocommit=False)
|
conn, cur = connect_db(autocommit=False)
|
||||||
cur.execute("SELECT 1")
|
cur.execute("SELECT 1")
|
||||||
res = cur.fetchall()
|
res = cur.fetchall()
|
||||||
|
|||||||
Reference in New Issue
Block a user