Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsc: Add config var for max number of pool connections #1653

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading