Skip to content

Commit

Permalink
rsc: Add config var for max number of pool connections (#1653)
Browse files Browse the repository at this point in the history
* rsc: Add config var for max number of pool connections

* comments
  • Loading branch information
V-FEXrt authored Sep 25, 2024
1 parent 52eb7bb commit 4faf576
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions rust/rsc/.config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions rust/rsc/src/bin/rsc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion rust/rsc/src/bin/rsc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ async fn connect_to_database(
config: &config::RSCConfig,
) -> Result<DatabaseConnection, Box<dyn std::error::Error>> {
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?;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4faf576

Please sign in to comment.