From 4faf576a0abb313d786c0ef0a6e0713e3807644a Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Wed, 25 Sep 2024 16:44:46 -0600 Subject: [PATCH] rsc: Add config var for max number of pool connections (#1653) * rsc: Add config var for max number of pool connections * comments --- rust/rsc/.config.json | 1 + rust/rsc/src/bin/rsc/config.rs | 3 +++ rust/rsc/src/bin/rsc/main.rs | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/rsc/.config.json b/rust/rsc/.config.json index 5bc1ded25..effaf3aba 100644 --- a/rust/rsc/.config.json +++ b/rust/rsc/.config.json @@ -1,6 +1,7 @@ { "database_url": "postgres://localhost:5433/test", "server_address": "0.0.0.0:3002", + "connection_pool_max_connect": 90, "connection_pool_timeout": 60, "standalone": false, "active_store": "5eed6ba4-d65f-46ca-b4a6-eff98b00857d", diff --git a/rust/rsc/src/bin/rsc/config.rs b/rust/rsc/src/bin/rsc/config.rs index cbdb3f502..bebbf336a 100644 --- a/rust/rsc/src/bin/rsc/config.rs +++ b/rust/rsc/src/bin/rsc/config.rs @@ -67,6 +67,9 @@ pub struct RSCConfig { pub database_url: String, // The address the that server should bind to pub server_address: String, + // The max number of connnections to open in the connection pool. Value must consider the + // postgres server max + pub connection_pool_max_connect: u32, // The amount of time a query should wait for a connection before timing out in seconds pub connection_pool_timeout: u64, // The blob store that new blobs should be written into diff --git a/rust/rsc/src/bin/rsc/main.rs b/rust/rsc/src/bin/rsc/main.rs index fffe51bbc..a16cc173f 100644 --- a/rust/rsc/src/bin/rsc/main.rs +++ b/rust/rsc/src/bin/rsc/main.rs @@ -202,11 +202,14 @@ async fn connect_to_database( config: &config::RSCConfig, ) -> Result> { let timeout = config.connection_pool_timeout; + let max_connect = config.connection_pool_max_connect; let mut opt = ConnectOptions::new(&config.database_url); opt.sqlx_logging_level(tracing::log::LevelFilter::Debug) - .acquire_timeout(std::time::Duration::from_secs(timeout)); + .acquire_timeout(std::time::Duration::from_secs(timeout)) + .max_connections(max_connect); tracing::info!(%timeout, "Max seconds to wait for connection from pool"); + tracing::info!(%max_connect, "Max number of connections in pool"); let connection = Database::connect(opt).await?; let pending_migrations = Migrator::get_pending_migrations(&connection).await?; @@ -491,6 +494,7 @@ mod tests { database_url: "test:0000".to_string(), server_address: "".to_string(), active_store: store_id.to_string(), + connection_pool_max_connect: 10, connection_pool_timeout: 10, log_directory: None, blob_eviction: config::RSCBlobTTLConfig {