Repository navigation
Conversation
on a LXC node with 8 CPU. _SC_NPROCESSORS_ONLN gives 8 CPU. the correct number. _SC_NPROCESSORS_CONF gives 256 CPU, which is the hardware on the hypervisor. this is not correct and cannot be used by the application. Signed-off-by: morotti <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request provides a critical fix for correctly detecting the number of CPUs in containerized environments like LXC. By changing sysconf(_SC_NPROCESSORS_CONF) to sysconf(_SC_NPROCESSORS_ONLN), it ensures that the application uses the number of available online processors rather than the total configured processors of the host machine. This correctly resolves the out-of-memory issues described. The change is accurate and well-justified.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
please review the pull request, it's a simple fix |
|
I’m not able to reproduce this on my devbox. However, according to the man page https://man7.org/linux/man-pages/man3/get_nprocs.3.html this behavior makes sense:
On my devbox, I’m unable to reproduce a difference between these two values, even when using LXC with a cpuset restriction: (venv) (base) ubuntu@devbox:~/ray$ getconf _NPROCESSORS_ONLN
48
(venv) (base) ubuntu@devbox:~/ray$ getconf _NPROCESSORS_CONF
48
(venv) (base) ubuntu@devbox:~/ray$ sudo cat /var/lib/lxc/cpu-test/config
# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template:
# For additional config options, please look at lxc.container.conf(5)
# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = linux64
# Container specific configuration
lxc.rootfs.path = dir:/var/lib/lxc/cpu-test/rootfs
lxc.uts.name = cpu-test
# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:f6:04:ea
lxc.cgroup.cpuset.cpus = 0-1
lxc.cgroup2.cpuset.cpus = 0-1
(venv) (base) ubuntu@devbox:~/ray$
(venv) (base) ubuntu@devbox:~/ray$
(venv) (base) ubuntu@devbox:~/ray$
(venv) (base) ubuntu@devbox:~/ray$
(venv) (base) ubuntu@devbox:~/ray$ sudo lxc-attach -n cpu-test
root@cpu-test:/#
root@cpu-test:/#
root@cpu-test:/#
root@cpu-test:/# getconf _NPROCESSORS_ONLN
48
root@cpu-test:/# getconf _NPROCESSORS_CONF
48 |
|
@morotti Could you please update your PR description with a screenshot showing the diff? Otherwise, LGTM. |
|
@Yicheng-Lu-llll screenshot attached
|
|
@morotti Thanks! |
|
So this has been open a while. My honest opinion on this is that we should absolutely change the variable IFF grpc also takes the change. Looking at the top of trunk version here: https://github.com/grpc/grpc/blob/ce8dc971ecd9451f8a462bd3d91b5c4a652a1f5c/src/core/util/linux/cpu.cc#L4 It seems they're using _SC_NPROCESSORS_CONF. It makes me nervous enough that we're patching this library, I'd rather not introduce additional delta. Once GRPC has taken this change we can make the tweak as well so we're as aligned as possible. But I'd prefer not to do that before. I know that's annoying, but you do already have an out here. Setting RAY_num_grpc_internal_threads will set the cap on the threads in the mean time. |

Hello,
On a LXC node with 8 CPU.
This bug keeps crashing my ray cluster out of memory because each ray worker is trying to create large number of threads and running out of memory.
see discussion in #54988
I've raised the patch upstream too. grpc/grpc#41144
Regards.