|
@@ -225,6 +225,7 @@ turn_params_t turn_params = {
|
|
|
|
|
|
///////////// CPUs //////////////////
|
|
|
DEFAULT_CPUS_NUMBER,
|
|
|
+ false, /* cpus_configured */
|
|
|
|
|
|
///////// Encryption /////////
|
|
|
"", /* secret_key_file */
|
|
@@ -1024,6 +1025,11 @@ static char Usage[] =
|
|
|
" In older systems (pre-Linux 3.9) the number of UDP relay threads "
|
|
|
"always equals\n"
|
|
|
" the number of listening endpoints (unless -m 0 is set).\n"
|
|
|
+ " --cpus <number> Override system CPU count detection. Use this number\n"
|
|
|
+ " instead of the auto-detected CPU count.\n"
|
|
|
+ " Useful in virtualized/containerized environments where\n"
|
|
|
+ " the system reports the host CPU count instead of\n"
|
|
|
+ " the allocated container CPUs.\n"
|
|
|
" --min-port <port> Lower bound of the UDP port range for relay endpoints "
|
|
|
"allocation.\n"
|
|
|
" Default value is 49152, according to RFC 5766.\n"
|
|
@@ -1506,7 +1512,8 @@ enum EXTRA_OPTS {
|
|
|
STUN_BACKWARD_COMPATIBILITY_OPT,
|
|
|
RESPONSE_ORIGIN_ONLY_WITH_RFC5780_OPT,
|
|
|
RESPOND_HTTP_UNSUPPORTED_OPT,
|
|
|
- VERSION_OPT
|
|
|
+ VERSION_OPT,
|
|
|
+ CPUS_OPT
|
|
|
};
|
|
|
|
|
|
struct myoption {
|
|
@@ -1652,6 +1659,7 @@ static const struct myoption long_options[] = {
|
|
|
{"respond-http-unsupported", optional_argument, NULL, RESPOND_HTTP_UNSUPPORTED_OPT},
|
|
|
{"version", optional_argument, NULL, VERSION_OPT},
|
|
|
{"syslog-facility", required_argument, NULL, SYSLOG_FACILITY_OPT},
|
|
|
+ {"cpus", required_argument, NULL, CPUS_OPT},
|
|
|
{NULL, no_argument, NULL, 0}};
|
|
|
|
|
|
static const struct myoption admin_long_options[] = {
|
|
@@ -2367,6 +2375,20 @@ static void set_option(int c, char *value) {
|
|
|
case RESPOND_HTTP_UNSUPPORTED_OPT:
|
|
|
turn_params.respond_http_unsupported = get_bool_value(value);
|
|
|
break;
|
|
|
+ case CPUS_OPT: {
|
|
|
+ int cpus = atoi(value);
|
|
|
+ if (cpus < 1) {
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "ERROR: cpus value must be positive\n");
|
|
|
+ } else if (cpus > MAX_NUMBER_OF_GENERAL_RELAY_SERVERS) {
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "WARNING: max number of cpus is %d.\n",
|
|
|
+ MAX_NUMBER_OF_GENERAL_RELAY_SERVERS);
|
|
|
+ turn_params.cpus = MAX_NUMBER_OF_GENERAL_RELAY_SERVERS;
|
|
|
+ turn_params.cpus_configured = true;
|
|
|
+ } else {
|
|
|
+ turn_params.cpus = (unsigned long)cpus;
|
|
|
+ turn_params.cpus_configured = true;
|
|
|
+ }
|
|
|
+ } break;
|
|
|
|
|
|
/* these options have been already taken care of before: */
|
|
|
case 'l':
|
|
@@ -3034,23 +3056,6 @@ int main(int argc, char **argv) {
|
|
|
// Zero pass apply the log options.
|
|
|
read_config_file(argc, argv, 0);
|
|
|
|
|
|
- {
|
|
|
- unsigned long cpus = get_system_active_number_of_cpus();
|
|
|
- if (cpus > 0) {
|
|
|
- turn_params.cpus = cpus;
|
|
|
- }
|
|
|
- if (turn_params.cpus < DEFAULT_CPUS_NUMBER) {
|
|
|
- turn_params.cpus = DEFAULT_CPUS_NUMBER;
|
|
|
- } else if (turn_params.cpus > MAX_NUMBER_OF_GENERAL_RELAY_SERVERS) {
|
|
|
- turn_params.cpus = MAX_NUMBER_OF_GENERAL_RELAY_SERVERS;
|
|
|
- }
|
|
|
-
|
|
|
- turn_params.general_relay_servers_number = (turnserver_id)turn_params.cpus;
|
|
|
-
|
|
|
- TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "System cpu num is %lu\n", get_system_number_of_cpus());
|
|
|
- TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "System enable num is %lu\n", get_system_active_number_of_cpus());
|
|
|
- }
|
|
|
-
|
|
|
// First pass read other config options
|
|
|
read_config_file(argc, argv, 1);
|
|
|
|
|
@@ -3063,6 +3068,25 @@ int main(int argc, char **argv) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // CPU detection and configuration
|
|
|
+ if (!turn_params.cpus_configured) {
|
|
|
+ unsigned long cpus = get_system_active_number_of_cpus();
|
|
|
+ if (cpus > 0) {
|
|
|
+ turn_params.cpus = cpus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (turn_params.cpus < DEFAULT_CPUS_NUMBER) {
|
|
|
+ turn_params.cpus = DEFAULT_CPUS_NUMBER;
|
|
|
+ } else if (turn_params.cpus > MAX_NUMBER_OF_GENERAL_RELAY_SERVERS) {
|
|
|
+ turn_params.cpus = MAX_NUMBER_OF_GENERAL_RELAY_SERVERS;
|
|
|
+ }
|
|
|
+
|
|
|
+ turn_params.general_relay_servers_number = (turnserver_id)turn_params.cpus;
|
|
|
+
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "System cpu num is %lu\n", get_system_number_of_cpus());
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "System enable num is %lu\n", get_system_active_number_of_cpus());
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Configured cpu num is %lu\n", turn_params.cpus);
|
|
|
+
|
|
|
// Second pass read -u options
|
|
|
read_config_file(argc, argv, 2);
|
|
|
|