Skip to content

Commit

Permalink
feat: More concurrency options (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker authored Nov 11, 2019
1 parent 348e14b commit eb6c8e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 26 additions & 1 deletion common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ pub fn start(state: ServiceState) -> Result<Recipient<server::StopServer>, 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()
Expand Down

0 comments on commit eb6c8e0

Please sign in to comment.