Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@shavnevnikita
Copy link

Implemented feature mentioned in #1628

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");
Copy link

@uninvited uninvited Jan 31, 2025

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*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this code?

Copy link
Author

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) {
Copy link
Collaborator

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

Copy link
Author

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.

@ggarber ggarber requested a review from Copilot May 21, 2025 11:18
Copy link
Contributor

Copilot AI left a 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

Comment on lines +2366 to +2372
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);
Copy link

Copilot AI May 21, 2025

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
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) {
Copy link

Copilot AI May 21, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants