Skip to content

Commit

Permalink
feat: add an actix_max_connections setting
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 8f6e03e commit ec4846a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
11 changes: 6 additions & 5 deletions autoconnect/autoconnect-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ pub struct Settings {
/// Maximum allowed number of backlogged messages. Exceeding this number will
/// trigger a user reset because the user may have been offline way too long.
pub msg_limit: u32,
/// Maximum number of pending notifications for individual UserAgent handlers.
/// (if a given [autoconnect-common::RegisteredClient] receives more than this number, the calling
/// thread will lock.)
pub max_pending_notification_queue: u32,
/// Sets the maximum number of concurrent connections per actix-web worker.
///
/// All socket listeners will stop accepting connections when this limit is
/// reached for each worker.
pub actix_max_connections: Option<usize>,
}

impl Default for Settings {
Expand Down Expand Up @@ -133,7 +134,7 @@ impl Default for Settings {
megaphone_poll_interval: Duration::from_secs(30),
human_logs: false,
msg_limit: 100,
max_pending_notification_queue: 10,
actix_max_connections: None,
}
}
}
Expand Down
25 changes: 14 additions & 11 deletions autoconnect/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ async fn main() -> Result<()> {

let port = settings.port;
let router_port = settings.router_port;
let actix_max_connections = settings.actix_max_connections;
let app_state = AppState::from_settings(settings)?;
app_state.init_and_spawn_megaphone_updater().await?;

info!(
"Starting autoconnect on port {} (router_port: {})",
port, router_port
"Starting autoconnect on port: {} router_port: {} (available_parallelism: {:?})",
port,
router_port,
std::thread::available_parallelism()
);

let router_app_state = app_state.clone();
Server::build()
let mut builder = Server::build()
.bind("autoconnect", ("0.0.0.0", port), move || {
let app = build_app!(app_state, config);
HttpService::build()
Expand All @@ -99,12 +102,12 @@ async fn main() -> Result<()> {
// XXX:
.finish(map_config(app, |_| AppConfig::default()))
.tcp()
})?
.run()
.await
.map_err(|e| e.into())
.map(|v| {
info!("Shutting down autoconnect");
v
})
})?;
if let Some(max_connections) = actix_max_connections {
builder = builder.max_concurrent_connections(max_connections);
}
builder.run().await?;

info!("Shutting down autoconnect");
Ok(())
}
8 changes: 6 additions & 2 deletions autoendpoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
let server = server::Server::with_settings(settings)
.await
.expect("Could not start server");
info!("Server started: {}", host_port);
info!(
"Starting autoendpoint on port: {} (available_parallelism: {:?})",
host_port,
std::thread::available_parallelism()
);
server.await?;

// Shutdown
info!("Server closing");
info!("Shutting down autoendpoint");
logging::reset_logging();
Ok(())
}

0 comments on commit ec4846a

Please sign in to comment.