diff --git a/common/src/config.rs b/common/src/config.rs index c9f2e0bcc7..91bb4d4782 100644 --- a/common/src/config.rs +++ b/common/src/config.rs @@ -243,7 +243,7 @@ impl Default for Metrics { #[derive(Serialize, Deserialize, Debug)] #[serde(default)] struct Limits { - /// How many requests can be sent concurrently before Relay starts buffering. + /// How many requests can be sent concurrently from Relay to the upstream before Relay starts buffering. max_concurrent_requests: usize, /// The maximum payload size for events. max_event_payload_size: ByteSize, @@ -261,6 +261,13 @@ struct Limits { /// The maximum number of seconds a query is allowed to take across retries. Individual requests /// have lower timeouts. Defaults to 30 seconds. query_timeout: u64, + /// The maximum number of connections to Relay that can be created at once. + max_connection_rate: usize, + /// The maximum number of pending connects to Relay. This corresponds to the backlog param of + /// `listen(2)` in POSIX. + max_pending_connections: i32, + /// The maximum number of open connections to Relay. + max_connections: usize, } impl Default for Limits { @@ -273,6 +280,9 @@ impl Default for Limits { max_api_chunk_upload_size: ByteSize::from_megabytes(100), max_thread_count: num_cpus::get(), query_timeout: 30, + max_connection_rate: 256, + max_pending_connections: 2048, + max_connections: 25_000, } } } @@ -822,6 +832,21 @@ impl Config { Duration::from_secs(self.values.limits.query_timeout) } + /// The maximum number of open connections to Relay. + pub fn max_connections(&self) -> usize { + self.values.limits.max_connections + } + + /// The maximum number of connections to Relay that can be created at once. + pub fn max_connection_rate(&self) -> usize { + self.values.limits.max_connection_rate + } + + /// The maximum number of pending connects to Relay. + pub fn max_pending_connections(&self) -> i32 { + self.values.limits.max_pending_connections + } + /// Returns the number of cores to use for thread pools. pub fn cpu_concurrency(&self) -> usize { self.values.limits.max_thread_count diff --git a/server/src/service.rs b/server/src/service.rs index 7b1ba4e293..8133e5fe83 100644 --- a/server/src/service.rs +++ b/server/src/service.rs @@ -288,6 +288,9 @@ pub fn start(state: ServiceState) -> Result, Serve server = server .workers(config.cpu_concurrency()) .shutdown_timeout(SHUTDOWN_TIMEOUT) + .maxconn(config.max_connections()) + .maxconnrate(config.max_connection_rate()) + .backlog(config.max_pending_connections()) .disable_signals(); let connector = ClientConnector::default()