Repository navigation
[core][sandbox] Run runsc CLI calls with GOMAXPROCS=2 - #67075
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a runsc_env() helper function to limit the GOMAXPROCS environment variable to 2 (unless already set) for all runsc CLI subprocesses in the gVisor sandbox backend. This change prevents excessive CPU consumption on multi-core systems during concurrent CLI calls. The helper is integrated into various subprocess invocations across gvisor.py and image_manager.py, and corresponding unit tests have been added to verify its behavior. There are no review comments, and the implementation looks solid with no additional feedback to provide.
57ace48 to
8b6c3f5
Compare
|
@pcmoritz Rebased onto master, with one change after your approval: master added three runsc calls since this was written (the exec-timeout |
Every runsc CLI call (run, state, exec, kill, delete, spec) is a short-lived Go process, and Go sizes its scheduler to every CPU it can see. On a many-core node, dozens of concurrent `runsc exec` calls then spend most of their CPU in the kernel rather than in the call. Run them with GOMAXPROCS=2 unless the worker's environment sets it, as gVisor's containerd shim does. runsc doesn't pass the variable on to the sandbox and gofer processes it starts, so a sandbox's own CPU is unaffected. Signed-off-by: xyuzh <[email protected]>
8b6c3f5 to
991c41d
Compare
Signed-off-by: xyuzh <[email protected]>
Master's checkpoint/restore (ray-project#66471) added `runsc pause`, `resume` and `checkpoint` calls, which ran with Go's default GOMAXPROCS. They get runsc_env() like every other runsc call. A restore's launch already does, since it shares `runsc run`'s Popen. Signed-off-by: xyuzh <[email protected]>
|
@pcmoritz I merged master in 4b68467. On top of that, 0ae359f changes code you'd already approved: #66471 added Real gVisor in a privileged container (aarch64, runsc release-20261026.0): |
…bundles Write an owner file that no live owner holds or names, rather than lock one with _own_bundle and close it: the bundle reads as unowned whether owners lock their owner files (now) or a lock that the file names (ray-project#67731). Signed-off-by: xyuzh <[email protected]>
Signed-off-by: xyuzh <[email protected]>
Signed-off-by: xyuzh <[email protected]> ray-project#65898's runsc --version and runsc nvproxy list-supported-drivers calls came in with master and ran with every CPU's worth of GOMAXPROCS, like no other runsc call.
|
@pcmoritz, two changes since your approval: I merged master (0a0587f, a one-line conflict with #67876's |
Premerge build 76502 failed in its init step: downloads from GitHub failed during GitHub's incident on 2026-11-09. Signed-off-by: xyuzh <[email protected]>
The jobs that failed in premerge build 76504 failed only on downloads from GitHub during GitHub's incident on 2026-11-09. Signed-off-by: xyuzh <[email protected]>
premerge build 76506 failed before running tests: GitHub's incident on 2026-11-09 still blocked downloads from CI then. It's resolved now. Signed-off-by: xyuzh <[email protected]>
## Description A gVisor sandbox create polls `runsc state` every 0.1 s until the container runs. Each poll is a Go process, so a create returns up to 0.1 s after its 30-40 ms boot, and a burst of creates spends CPU on polling. `network="public"` sandboxes also wait in 0.1 s steps for the namespace holder and slirp4netns. This PR changes the waits in `backend/gvisor.py`: - `runsc run --pid-file <bundle>/sandbox.pid` writes the file once the container exists. The start loop stats it every 10 ms and calls `runsc state` only after that, every 50 ms. - The public wrapper checks for the holder and slirp4netns every 10 ms instead of 0.1 s, still for up to 10 s. Measured on 2026-10-14 against base 00a3adb, on a CoreWeave node pinned to 16 cores, creating `python:3.12-slim` sandboxes from a cached image; medians of 5 alternating runs per side. Every create succeeded, and CPU per create fell by up to 29%. | | master | this PR | | --- | --- | --- | | One create, `network="none"` (p50) | 114 ms | 41 ms | | One create, `network="host"` (p50) | 115 ms | 31 ms | | One create, `network="public"` (p50) | 324 ms | 71 ms | | 96 creates at once, `none` | 98/s | 116/s | | 96 creates at once, `public` | 48/s | 70/s | ## Related issues Split out of #66821. ## Additional information - Not a duplicate: no open PR changes how a create waits (I searched for "runsc state", "pid-file" and "sandbox boot"). #66471's restore path has its own copy of the 0.1 s loop. #67075 edits the same `runsc state` call; whichever lands second needs a one-line merge. - Tests: `test_restore_in_place_waits_for_a_new_pid_file` checks that a restore in place doesn't start from the stopped launch's pid file, and #67688's `test_backend_applies_oom_priority_to_start_exec_and_file_io` now writes the pid file its fake launch stands in for. The run-command tests now expect `--pid-file` and fail on master; every test that boots a sandbox goes through the new wait. `test_create_times_out_when_runsc_state_hangs` checks that a `runsc state` call that never returns can't hold a create past its deadline. - Tested at a04985a (master a83e55e merged in), in a privileged container (aarch64, runsc release-20261026.0, erofs-utils 1.9.4): `TEST_SANDBOX=1 pytest tests/test_{gvisor_backend,checkpoint_restore,image_manager,image_utils,sandbox_runtime,overlayfs,sandbox_config,cgroup,resource_limits}.py`: 474 passed, 25 skipped, and the same two GPU tests fail as on master (473 passed), since that container's Ray predates `get_cdi_kind`. As on master that hour, `test_netns_owner_interrupt_leaves_its_sandbox_running` failed because example.com answered the sandbox's `wget` with 403. pre-commit passes. - I used Claude Code to help write and test this change. --------- Signed-off-by: xyuzh <[email protected]> Co-authored-by: Philipp Moritz <[email protected]>
Signed-off-by: xyuzh <[email protected]> ray-project#67074 rewrote the start loop's runsc state call; it keeps runsc_env().
Description
Every runsc CLI call the gVisor backend makes (
run,state,exec,kill,delete,spec) is a Go process, and Go sizes its runtime to every CPU it can see. On a 64-core node without a CPU limit, 64 concurrentrunsc execcalls cost 0.023 CPU-s each. gVisor's containerd shim runs runsc withGOMAXPROCS=2for this reason.This PR runs those calls with
GOMAXPROCS=2too (runsc_env()inbackend/gvisor.py), unless the worker's environment sets it. runsc doesn't pass the variable on to the sandbox or the gofer, sonprocin a sandbox still reports every CPU.Measured on 2026-10-14 against base 00a3adb, on a 64-core CoreWeave node: 64 sandboxes each ran 20
trueexecs back to back, all at once; medians of 5 alternating runs per side.taskset)In pods with CPU limits, Go already sizes itself to the limit and the gain is small: 2-4% more execs and creates through the gRPC facade on four 30-CPU pods, with
GOMAXPROCS=2set in the Ray workers' environment (runsc inherits it).Related issues
Split out of #66821.
Additional information
GOMAXPROCSfor runsc (I searched for "sandbox GOMAXPROCS" and "runsc spec"). [core][sandbox] Enforce CPU and memory limits with host cgroups #66932 and [core][sandbox] Stop a sandbox with its owner, and reclaim what it leaves #67022 add runsc calls, which should passenv=runsc_env()if this lands first. [core][sandbox] Wait for gVisor boots with runsc's pid file #67074 and [core][sandbox] Skip repeated work on each sandbox create #67076 edit the samerunsc stateandrunsc speccalls; one-line merges.test_runsc_env_caps_gomaxprocs_unless_setchecks the default and an override;test_runsc_run_starts_with_gomaxprocsboots a sandbox and reads itsrunsc run's environment. Both fail on master.test_gpu_checks_run_runsc_with_runsc_envcovers the two GPU checks' runsc calls that came in with [core][sandbox] Add GPU support to Ray Sandboxes via CDI #65898.TEST_SANDBOX=1 pytest tests/test_{gvisor_backend,checkpoint_restore,image_manager,image_utils,sandbox_runtime,overlayfs,sandbox_config,cgroup,resource_limits}.py: 480 passed, 25 skipped, and the same two GPU tests fail as on master (473 passed), since that container's Ray predatesget_cdi_kind. pre-commit passes.