feat: configurable blocking threads

This commit is contained in:
Greg Heartsfield 2022-12-18 09:14:04 -06:00
parent 8598e443d8
commit d10348f7e1
3 changed files with 14 additions and 1 deletions

View File

@ -78,6 +78,9 @@ reject_future_seconds = 1800
# defaults to unlimited (subject to subscription limits). # defaults to unlimited (subject to subscription limits).
#db_conns_per_client = 0 #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. # Limit the maximum size of an EVENT message. Defaults to 128 KB.
# Set to 0 for unlimited. # Set to 0 for unlimited.
#max_event_bytes = 131072 #max_event_bytes = 131072

View File

@ -54,7 +54,8 @@ pub struct Limits {
pub messages_per_sec: Option<u32>, // Artificially slow down event writing to limit disk consumption (averaged over 1 minute) pub messages_per_sec: Option<u32>, // Artificially slow down event writing to limit disk consumption (averaged over 1 minute)
pub subscriptions_per_min: Option<u32>, // Artificially slow down request (db query) creation to prevent abuse (averaged over 1 minute) pub subscriptions_per_min: Option<u32>, // Artificially slow down request (db query) creation to prevent abuse (averaged over 1 minute)
pub db_conns_per_client: Option<u32>, // How many concurrent database queries (not subscriptions) may a client have? pub db_conns_per_client: Option<u32>, // How many concurrent database queries (not subscriptions) may a client have?
pub max_event_bytes: Option<usize>, // Maximum size of an EVENT message pub max_blocking_threads: usize,
pub max_event_bytes: Option<usize>, // Maximum size of an EVENT message
pub max_ws_message_bytes: Option<usize>, pub max_ws_message_bytes: Option<usize>,
pub max_ws_frame_bytes: Option<usize>, pub max_ws_frame_bytes: Option<usize>,
pub broadcast_buffer: usize, // events to buffer for subscribers (prevents slow readers from consuming memory) 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, messages_per_sec: None,
subscriptions_per_min: None, subscriptions_per_min: None,
db_conns_per_client: None, db_conns_per_client: None,
max_blocking_threads: 64,
max_event_bytes: Some(2 << 17), // 128K max_event_bytes: Some(2 << 17), // 128K
max_ws_message_bytes: Some(2 << 17), // 128K max_ws_message_bytes: Some(2 << 17), // 128K
max_ws_frame_bytes: Some(2 << 17), // 128K max_ws_frame_bytes: Some(2 << 17), // 128K

View File

@ -245,6 +245,14 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result
let rt = Builder::new_multi_thread() let rt = Builder::new_multi_thread()
.enable_all() .enable_all()
.thread_name("tokio-ws") .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() .build()
.unwrap(); .unwrap();
// start tokio // start tokio