Skip to content

Commit 0876589

Browse files
committed
Set configurable message_threads
1 parent 420220e commit 0876589

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

janus.plugin.sfu.cfg.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ max_room_size = 30
1010

1111
# If present, the maximum number of concurrent users allowed to join any room on the server. Zero means no limit.
1212
max_ccu = 1000
13+
14+
# Number of threads to run message processing on. If zero, use the # of logical CPUs.
15+
message_threads = 0

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Config {
1111
pub auth_key: Option<Vec<u8>>,
1212
pub max_room_size: usize,
1313
pub max_ccu: usize,
14+
pub message_threads: usize,
1415
}
1516

1617
impl Default for Config {
@@ -19,6 +20,7 @@ impl Default for Config {
1920
auth_key: None,
2021
max_room_size: usize::max_value(),
2122
max_ccu: usize::max_value(),
23+
message_threads: 0,
2224
}
2325
}
2426
}
@@ -45,6 +47,7 @@ impl Config {
4547
auth_key: auth_key,
4648
max_room_size: section.get("max_room_size").and_then(|x| x.parse().ok()).unwrap_or(defaults.max_room_size),
4749
max_ccu: section.get("max_ccu").and_then(|x| x.parse().ok()).unwrap_or(defaults.max_ccu),
50+
message_threads: section.get("message_threads").and_then(|x| x.parse().ok()).unwrap_or(defaults.message_threads),
4851
})
4952
}
5053
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,13 @@ extern "C" fn init(callbacks: *mut PluginCallbacks, config_path: *const c_char)
242242
Config::default()
243243
}
244244
};
245+
let message_threads = config.message_threads;
245246
CONFIG.set(config).expect("Big problem: config already initialized!");
246247
match unsafe { callbacks.as_ref() } {
247248
Some(c) => {
248249
unsafe { CALLBACKS = Some(c) };
249250
let mut senders = Vec::new();
250-
let cpus = num_cpus::get(); // Run one thread per logical CPU
251+
let cpus = if message_threads == 0 { num_cpus::get() } else { message_threads };
251252

252253
for i in 0..cpus {
253254
let (messages_tx, messages_rx) = mpsc::sync_channel(0);

0 commit comments

Comments
 (0)