Skip to content
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

Thread count should default to *ONLINE* CPU count #1468

Open
staticglobal opened this issue Apr 4, 2024 · 1 comment
Open

Thread count should default to *ONLINE* CPU count #1468

staticglobal opened this issue Apr 4, 2024 · 1 comment

Comments

@staticglobal
Copy link

Background:
In apputils.c we have get_system_number_of_cpus() which returns sysconf(_SC_NPROCESSORS_CONF)); (number of "configured" processors) and get_system_active_number_of_cpus() which returns sysconf(_SC_NPROCESSORS_ONLN); (number of "online/available" processors)

Then mainrelay.c sets turn_params.cpus to get_system_number_of_cpus() (capped at 128) and then also defaults general_relay_servers_number to this value.

Issue:
On most systems in most situations configured == online so the difference is meaningless. However, when running in some virtualized environments, the difference can be significant.

In one scenario when running under HyperV a VM configured for 2 CPUs, the hardware always reports a total of 240 total CPUs, with only the first 2 CPUs being online and the other 238 offline. Presumably this is how the host implements virtualized CPU hotplugging. From dmesg:

[    0.033154] smpboot: Allowing 240 CPUs, 238 hotplug CPUs

And getconf:

localhost ~ # getconf _NPROCESSORS_CONF
240
localhost ~ # getconf _NPROCESSORS_ONLN
2

coturn correctly logs both the total (capped) and enabled CPU counts

0: (2341): INFO: System cpu num is 128
0: (2341): INFO: System enable num is 2

...but then proceeds with setting up 128 worker threads despite the system only having 2 CPUs. I believe this behavior is incorrect and instead turn_params.cpus should be set from get_system_active_number_of_cpus() instead.

@jonesmz
Copy link
Contributor

jonesmz commented Apr 5, 2024

This seems like a good improvement to me.

Have you considered making a PR to change it in the way you suggested?

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

No branches or pull requests

2 participants