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

[Backport release-thehounds] Make connection pool options configurable #2290

Merged
merged 1 commit into from
Nov 15, 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
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 @@ -116,6 +116,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