Skip to content

Commit aca9738

Browse files
authored
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
1 parent 0bc453a commit aca9738

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/config.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ pub struct General {
292292
#[serde(default = "General::default_server_lifetime")]
293293
pub server_lifetime: u64,
294294

295+
#[serde(default = "General::default_server_round_robin")] // False
296+
pub server_round_robin: bool,
297+
295298
#[serde(default = "General::default_worker_threads")]
296299
pub worker_threads: usize,
297300

@@ -352,7 +355,7 @@ impl General {
352355
}
353356

354357
pub fn default_idle_timeout() -> u64 {
355-
60000 // 1 minute
358+
600000 // 10 minutes
356359
}
357360

358361
pub fn default_shutdown_timeout() -> u64 {
@@ -390,6 +393,10 @@ impl General {
390393
pub fn default_prometheus_exporter_port() -> i16 {
391394
9930
392395
}
396+
397+
pub fn default_server_round_robin() -> bool {
398+
true
399+
}
393400
}
394401

395402
impl Default for General {
@@ -424,7 +431,8 @@ impl Default for General {
424431
auth_query: None,
425432
auth_query_user: None,
426433
auth_query_password: None,
427-
server_lifetime: 1000 * 3600 * 24, // 24 hours,
434+
server_lifetime: Self::default_server_lifetime(),
435+
server_round_robin: false,
428436
validate_config: true,
429437
}
430438
}
@@ -983,6 +991,7 @@ impl Config {
983991
"Default max server lifetime: {}ms",
984992
self.general.server_lifetime
985993
);
994+
info!("Sever round robin: {}", self.general.server_round_robin);
986995
match self.general.tls_certificate.clone() {
987996
Some(tls_certificate) => {
988997
info!("TLS certificate: {}", tls_certificate);

src/pool.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ impl ConnectionPool {
389389
.min()
390390
.unwrap();
391391

392+
let queue_strategy = match config.general.server_round_robin {
393+
true => QueueStrategy::Fifo,
394+
false => QueueStrategy::Lifo,
395+
};
396+
392397
debug!(
393398
"[pool: {}][user: {}] Pool reaper rate: {}ms",
394399
pool_name, user.username, reaper_rate
@@ -401,7 +406,7 @@ impl ConnectionPool {
401406
.idle_timeout(Some(std::time::Duration::from_millis(idle_timeout)))
402407
.max_lifetime(Some(std::time::Duration::from_millis(server_lifetime)))
403408
.reaper_rate(std::time::Duration::from_millis(reaper_rate))
404-
.queue_strategy(QueueStrategy::Lifo)
409+
.queue_strategy(queue_strategy)
405410
.test_on_check_out(false);
406411

407412
let pool = if config.general.validate_config {

tests/python/tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def cleanup_conn(conn: psycopg2.extensions.connection, cur: psycopg2.extensions.
6363

6464

6565
def test_normal_db_access():
66+
pgcat_start()
6667
conn, cur = connect_db(autocommit=False)
6768
cur.execute("SELECT 1")
6869
res = cur.fetchall()

0 commit comments

Comments
 (0)