diff --git a/conf/janus.jcfg.sample.in b/conf/janus.jcfg.sample.in index af28e1c6de..c628b87a36 100644 --- a/conf/janus.jcfg.sample.in +++ b/conf/janus.jcfg.sample.in @@ -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 diff --git a/src/janus.c b/src/janus.c index 295025ef47..c15626020d 100644 --- a/src/janus.c +++ b/src/janus.c @@ -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) { @@ -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",