Skip to content

Commit

Permalink
Make connection pool options configurable (#2285)
Browse files Browse the repository at this point in the history
Also changes the default connection pool size from 10 to 25
  • Loading branch information
jbearer authored Nov 15, 2024
1 parent 6d85bce commit 187f337
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sequencer/api/public-env-vars.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ variables = [
"ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS",
"ESPRESSO_SEQUENCER_MAX_CONNECTIONS",
"ESPRESSO_SEQUENCER_ORCHESTRATOR_URL",
"ESPRESSO_SEQUENCER_POSTGRES_CONNECTION_TIMEOUT",
"ESPRESSO_SEQUENCER_POSTGRES_DATABASE",
"ESPRESSO_SEQUENCER_POSTGRES_HOST",
"ESPRESSO_SEQUENCER_POSTGRES_IDLE_CONNECTION_TIMEOUT",
"ESPRESSO_SEQUENCER_POSTGRES_MAX_CONNECTIONS",
"ESPRESSO_SEQUENCER_POSTGRES_MIN_CONNECTIONS",
"ESPRESSO_SEQUENCER_POSTGRES_PORT",
"ESPRESSO_SEQUENCER_POSTGRES_PRUNE",
"ESPRESSO_SEQUENCER_POSTGRES_USE_TLS",
Expand Down
39 changes: 39 additions & 0 deletions sequencer/src/persistence/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,45 @@ pub struct Options {
/// fetching from peers.
#[clap(long, env = "ESPRESSO_SEQUENCER_ARCHIVE", conflicts_with = "prune")]
pub(crate) archive: bool,

/// The maximum idle time of a database connection.
///
/// Any connection which has been open and unused longer than this duration will be
/// automatically closed to reduce load on the server.
#[clap(long, env = "ESPRESSO_SEQUENCER_POSTGRES_IDLE_CONNECTION_TIMEOUT", value_parser = parse_duration, default_value = "10m")]
pub(crate) idle_connection_timeout: Duration,

/// The maximum lifetime of a database connection.
///
/// Any connection which has been open longer than this duration will be automatically closed
/// (and, if needed, replaced), even if it is otherwise healthy. It is good practice to refresh
/// even healthy connections once in a while (e.g. daily) in case of resource leaks in the
/// server implementation.
#[clap(long, env = "ESPRESSO_SEQUENCER_POSTGRES_CONNECTION_TIMEOUT", value_parser = parse_duration, default_value = "30m")]
pub(crate) connection_timeout: Duration,

/// The minimum number of database connections to maintain at any time.
///
/// The database client will, to the best of its ability, maintain at least `min` open
/// connections at all times. This can be used to reduce the latency hit of opening new
/// connections when at least this many simultaneous connections are frequently needed.
#[clap(
long,
env = "ESPRESSO_SEQUENCER_POSTGRES_MIN_CONNECTIONS",
default_value = "0"
)]
pub(crate) min_connections: u32,

/// The maximum number of database connections to maintain at any time.
///
/// Once `max` connections are in use simultaneously, further attempts to acquire a connection
/// (or begin a transaction) will block until one of the existing connections is released.
#[clap(
long,
env = "ESPRESSO_SEQUENCER_POSTGRES_MAX_CONNECTIONS",
default_value = "25"
)]
pub(crate) max_connections: u32,
}

impl TryFrom<Options> for Config {
Expand Down

0 comments on commit 187f337

Please sign in to comment.