shim: fetch sandbox stats without subprocesses#13711
Open
laotoutou wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
@zkoopmans Don't we already have something for this in flight? |
Contributor
|
Yes, we have this in flight for all commands and it will take a minute to develop and roll out. This CL will be redundant when that happens. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The containerd shim implements each
Runsc.Statsrequest by starting a newrunsc events --statsprocess. Kubernetes CRI stats collection calls this path once per sandbox container. On dense nodes, a singleListPodSandboxStatsrequest therefore creates hundreds of short-lived processes, and recurring kubelet and observability scrapes turn that into sustained fork/exec and context-switch overhead even when the sandboxes are idle.In a controlled deployment with 443 gVisor sandboxes on an 8-vCPU node, the existing path averaged 72.80% host CPU and repeatedly saturated the node. Client-side pacing reduced peak concurrency, but it did not reduce the number of stats subprocesses and made steady CPU worse. This makes the subprocess boundary, rather than request fan-out alone, the useful optimization point.
Related production investigation: sandbox0-ai/sandbox0#704
How it works
This change keeps the existing shim and CRI contracts, but makes
Runsc.Statsuse the sandbox control RPC directly:containerManager.Event, the same RPC used byrunsc events --stats.runsc events --statsCLI implementation when the direct path is unavailable or fails.The fallback keeps compatibility with unexpected state layouts or runtime conditions while removing recurring subprocess creation from the normal path.
Validation
bazel test //pkg/shim/v1/runsccmd:runsccmd_testmetrics-serverabsent, and ctld metrics enabled. The direct path reduced average host CPU from 60.68% to 16.70%, CPU p95 from 100% to 36.70%, and forks from 271.30/s to 17.18/s.runsc events --statsexecs in the baseline window and zero in the direct-path window.Assisted-by: OpenAI Codex