Skip to content

Commit

Permalink
feat: add actix_max_connections/workers settings
Browse files Browse the repository at this point in the history
and print the available_parallelism on startup

SYNC-4005
  • Loading branch information
pjenvey committed Nov 9, 2023
1 parent ec4846a commit 4f1d611
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions autoconnect/autoconnect-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ pub struct Settings {
/// How long to wait for a response Pong before being timed out and connection drop
#[serde(deserialize_with = "deserialize_f64_to_duration")]
pub auto_ping_timeout: Duration,
/// Max number of websocket connections to allow
pub max_connections: u32,
/// How long to wait for the initial connection handshake.
#[serde(deserialize_with = "deserialize_u32_to_duration")]
pub open_handshake_timeout: Duration,
Expand Down Expand Up @@ -104,6 +102,10 @@ pub struct Settings {
/// All socket listeners will stop accepting connections when this limit is
/// reached for each worker.
pub actix_max_connections: Option<usize>,
/// Sets number of actix-web workers to start (per bind address).
///
/// By default, the number of available physical CPUs is used as the worker count.
pub actix_workers: Option<usize>,
}

impl Default for Settings {
Expand All @@ -116,7 +118,6 @@ impl Default for Settings {
router_hostname: None,
auto_ping_interval: Duration::from_secs(300),
auto_ping_timeout: Duration::from_secs(4),
max_connections: 0,
open_handshake_timeout: Duration::from_secs(5),
close_handshake_timeout: Duration::from_secs(0),
endpoint_scheme: "http".to_owned(),
Expand All @@ -135,6 +136,7 @@ impl Default for Settings {
human_logs: false,
msg_limit: 100,
actix_max_connections: None,
actix_workers: None,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions autoconnect/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async fn main() -> Result<()> {
let port = settings.port;
let router_port = settings.router_port;
let actix_max_connections = settings.actix_max_connections;
let actix_workers = settings.actix_workers;
let app_state = AppState::from_settings(settings)?;
app_state.init_and_spawn_megaphone_updater().await?;

Expand Down Expand Up @@ -106,6 +107,9 @@ async fn main() -> Result<()> {
if let Some(max_connections) = actix_max_connections {
builder = builder.max_concurrent_connections(max_connections);
}
if let Some(workers) = actix_workers {
builder = builder.workers(workers);
}
builder.run().await?;

info!("Shutting down autoconnect");
Expand Down

0 comments on commit 4f1d611

Please sign in to comment.