-
Notifications
You must be signed in to change notification settings - Fork 2.2k
CPUs number as config var #1640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
CPUs number as config var #1640
Conversation
| break; | ||
| case CPUS_NUMBER_OPT: | ||
| if (atoi(value) > MAX_CPUS_NUMBER) { | ||
| TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "max number of cpus is 128.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "Max number of cpus is %lu\n", MAX_CPUS_NUMBER);
?
| DEFAULT_GENERAL_RELAY_SERVERS_NUMBER, /*general_relay_servers_number*/ | ||
| 0, /*udp_relay_servers_number*/ | ||
| NULL, /*external_ip*/ | ||
| 255, /*general_relay_servers_number*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cause we need to distinguish between explicitly set relay-threads to 0 and not set.
| 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, "Will be used %lu\n", turn_params.cpus); | ||
|
|
||
| if (turn_params.general_relay_servers_number == 255) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change does nothing - if will always be executed as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we are checking general_relay_servers_number after first pass of reading config, so if it is set we dont wanna override it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a configurable CPUs number feature as described in issue #1628. Key changes include redefining CPU-related macros in mainrelay.h, adding a new command-line option ("--cpus-num") in mainrelay.c, and refactoring how the CPU count is determined from system values versus user input.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/apps/relay/mainrelay.h | Replaces DEFAULT_CPUS_NUMBER with MAX_CPUS_NUMBER and MIN_CPUS_NUMBER, supporting new CPU config |
| src/apps/relay/mainrelay.c | Removes redundant CPU initialization code, adds the CPUS_NUMBER_OPT option, and updates logging |
| if (atoi(value) > MAX_CPUS_NUMBER) { | ||
| TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "max number of cpus is 128.\n"); | ||
| turn_params.cpus = MAX_CPUS_NUMBER; | ||
| } else if (atoi(value) <= MIN_CPUS_NUMBER) { | ||
| turn_params.cpus = 0; | ||
| } else { | ||
| turn_params.cpus = atoi(value); |
Copilot
AI
May 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider storing the result of atoi(value) in a local variable to avoid repeated conversions and improve readability.
| if (atoi(value) > MAX_CPUS_NUMBER) { | |
| TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "max number of cpus is 128.\n"); | |
| turn_params.cpus = MAX_CPUS_NUMBER; | |
| } else if (atoi(value) <= MIN_CPUS_NUMBER) { | |
| turn_params.cpus = 0; | |
| } else { | |
| turn_params.cpus = atoi(value); | |
| int cpu_count = atoi(value); | |
| if (cpu_count > MAX_CPUS_NUMBER) { | |
| TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "max number of cpus is 128.\n"); | |
| turn_params.cpus = MAX_CPUS_NUMBER; | |
| } else if (cpu_count <= MIN_CPUS_NUMBER) { | |
| turn_params.cpus = 0; | |
| } else { | |
| turn_params.cpus = cpu_count; |
| if (atoi(value) > MAX_CPUS_NUMBER) { | ||
| TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "max number of cpus is 128.\n"); | ||
| turn_params.cpus = MAX_CPUS_NUMBER; | ||
| } else if (atoi(value) <= MIN_CPUS_NUMBER) { |
Copilot
AI
May 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify the intended behavior in a comment: values less than or equal to MIN_CPUS_NUMBER trigger automatic CPU detection, ensuring the logic is clear to future maintainers.
Implemented feature mentioned in #1628