Skip to content

Commit

Permalink
Added configurable property to put a cap to task threads (see #2964)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed May 5, 2022
1 parent bbe4120 commit 204ef17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions conf/janus.jcfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ general: {
# only if allow_loop_indication is set to true;
# it's set to false by default to avoid abuses.
# Don't change if you don't know what you're doing!
#task_pool_size = 100 # By default, while the Janus core is single thread
# when it comes to processing incoming messages, it
# also uses a task pool with an indefinite amount
# of helper threads spawned on demand to handle
# messages addressed to plugins. If you want to
# limit this task pool size with a maximum number
# of concurrent threads, set the 'task_pool_size'
# property accordingly: a value of '0' means
# 'indefinite' and is the default. Notice that
# threads are automatically destroyed when unused
# for a while, so whatever value you choose simply
# puts a cap on the maximum concurrency.
# Don't change if you don't know what you're doing!
#opaqueid_in_api = true # Opaque IDs set by applications are typically
# only passed to event handlers for correlation
# purposes, but not sent back to the user or
Expand Down
10 changes: 9 additions & 1 deletion src/janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4982,6 +4982,14 @@ gint main(int argc, char *argv[]) {
loops_api = janus_is_true(item->value);
janus_ice_set_static_event_loops(loops, loops_api);
}
/* Also check if we need a cap on the size of the task pool (default is no limit) */
int task_pool_size = -1;
item = janus_config_get(config, config_general, janus_config_type_item, "task_pool_size");
if(item && item->value) {
task_pool_size = atoi(item->value);
if(task_pool_size <= 0)
task_pool_size = -1;
}
/* Initialize the ICE stack now */
janus_ice_init(ice_lite, ice_tcp, full_trickle, ignore_mdns, ipv6, ipv6_linklocal, rtp_min_port, rtp_max_port);
if(janus_ice_set_stun_server(stun_server, stun_port) < 0) {
Expand Down Expand Up @@ -5226,7 +5234,7 @@ gint main(int argc, char *argv[]) {
}
/* Create a thread pool to handle asynchronous requests, no matter what the transport */
error = NULL;
tasks = g_thread_pool_new(janus_transport_task, NULL, -1, FALSE, &error);
tasks = g_thread_pool_new(janus_transport_task, NULL, task_pool_size, FALSE, &error);
if(error != NULL) {
/* Something went wrong... */
JANUS_LOG(LOG_FATAL, "Got error %d (%s) trying to launch the request pool task thread...\n",
Expand Down

0 comments on commit 204ef17

Please sign in to comment.