diff --git a/config.toml b/config.toml index 8b5afe9..cda3199 100644 --- a/config.toml +++ b/config.toml @@ -78,6 +78,9 @@ reject_future_seconds = 1800 # defaults to unlimited (subject to subscription limits). #db_conns_per_client = 0 +# Limit blocking threads used for database connections. Defaults to 64. +#max_blocking_threads = 64 + # Limit the maximum size of an EVENT message. Defaults to 128 KB. # Set to 0 for unlimited. #max_event_bytes = 131072 diff --git a/src/config.rs b/src/config.rs index 75011b0..a4388d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,7 +54,8 @@ pub struct Limits { pub messages_per_sec: Option, // Artificially slow down event writing to limit disk consumption (averaged over 1 minute) pub subscriptions_per_min: Option, // Artificially slow down request (db query) creation to prevent abuse (averaged over 1 minute) pub db_conns_per_client: Option, // How many concurrent database queries (not subscriptions) may a client have? - pub max_event_bytes: Option, // Maximum size of an EVENT message + pub max_blocking_threads: usize, + pub max_event_bytes: Option, // Maximum size of an EVENT message pub max_ws_message_bytes: Option, pub max_ws_frame_bytes: Option, pub broadcast_buffer: usize, // events to buffer for subscribers (prevents slow readers from consuming memory) @@ -218,6 +219,7 @@ impl Default for Settings { messages_per_sec: None, subscriptions_per_min: None, db_conns_per_client: None, + max_blocking_threads: 64, max_event_bytes: Some(2 << 17), // 128K max_ws_message_bytes: Some(2 << 17), // 128K max_ws_frame_bytes: Some(2 << 17), // 128K diff --git a/src/server.rs b/src/server.rs index 5309669..29953a7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -245,6 +245,14 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result let rt = Builder::new_multi_thread() .enable_all() .thread_name("tokio-ws") + // limit concurrent SQLite blocking threads + .max_blocking_threads(settings.limits.max_blocking_threads) + .on_thread_start(|| { + debug!("started new thread"); + }) + .on_thread_stop(|| { + debug!("stopping thread"); + }) .build() .unwrap(); // start tokio