diff --git a/daemon/main.c b/daemon/main.c index 25957e838..0b40a273d 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -933,14 +933,8 @@ no_kernel: rtpe_config.max_sessions = -1; } - if (rtpe_config.redis_num_threads < 1) { -#ifdef _SC_NPROCESSORS_ONLN - rtpe_config.redis_num_threads = sysconf( _SC_NPROCESSORS_ONLN ); -#endif - if (rtpe_config.redis_num_threads < 1) { - rtpe_config.redis_num_threads = REDIS_RESTORE_NUM_THREADS; - } - } + if (rtpe_config.redis_num_threads < 1) + rtpe_config.redis_num_threads = num_cpu_cores(REDIS_RESTORE_NUM_THREADS); rtpe_tcp = NULL; if (rtpe_config.tcp_listen_ep.port) { @@ -1007,13 +1001,8 @@ no_kernel: rtpe_redis_write = rtpe_redis; } - if (rtpe_config.num_threads < 1) { -#ifdef _SC_NPROCESSORS_ONLN - rtpe_config.num_threads = sysconf( _SC_NPROCESSORS_ONLN ) + 3; -#endif - if (rtpe_config.num_threads <= 1) - rtpe_config.num_threads = 4; - } + if (rtpe_config.num_threads < 1) + rtpe_config.num_threads = num_cpu_cores(4); if (websocket_init()) die("Failed to init websocket listener"); diff --git a/daemon/rtpengine.pod b/daemon/rtpengine.pod index 716c54e27..4a4ec7800 100644 --- a/daemon/rtpengine.pod +++ b/daemon/rtpengine.pod @@ -312,7 +312,8 @@ sensitive and/or private information. Defaults to an empty string. How many worker threads to create, must be at least one. The default is to create as many threads as there are CPU cores available. -If the number of CPU cores cannot be determined, the default is four. +If the number of CPU cores cannot be determined or if it is less than four, +then the default is four. =item B<--num-media-threads=>I diff --git a/lib/auxlib.c b/lib/auxlib.c index 819750f82..a05cad0d3 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -410,3 +410,12 @@ void free_gbuf(char **p) { void free_gvbuf(char ***p) { g_strfreev(*p); } + +int num_cpu_cores(int minval) { +#ifdef _SC_NPROCESSORS_ONLN + int ret = sysconf(_SC_NPROCESSORS_ONLN); + if (ret >= 1 && ret >= minval) + return ret; +#endif + return minval; +} diff --git a/lib/auxlib.h b/lib/auxlib.h index bac6e33f5..294a6b4b7 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -57,6 +57,7 @@ unsigned int in6_addr_hash(const void *p); int in6_addr_eq(const void *a, const void *b); unsigned int uint32_hash(const void *p); int uint32_eq(const void *a, const void *b); +int num_cpu_cores(int); /*** HELPER MACROS ***/