Repository navigation
perf(node-metrics): skip per-process scans without viewers, cache cgroup matches, slim pod decode - #1440
Merged
Conversation
…oup matches, slim pod decode - collect per-process cpu/memory stats only while a live stream listens: node-metrics checks PUBSUB NUMSUB every 2s; the monitors collect on request instead of reading /proc/$pid/stat and statm for every container process each second (cluster mode or errors keep the previous always-collect behavior) - run the cgroup regexes once per distinct cgroup content per pass instead of once per PID; the cache is keyed by content, so a reused PID cannot inherit a stale match - decode the pods on the node into a 7-field view instead of full v1.Pod objects every 5s (real pod: 47µs → 18µs, 19.5 KB → 0.4 KB, 194 → 5 allocations) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
beneiltis
force-pushed
the
perf/node-metrics-proc-scans
branch
from
November 13, 2026 11:41
c7a295e to
7088008
Compare
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.
Stacked on #1439 (both touch
nodemetricscollector.go); merge that one first, GitHub then retargets this PR tomain.Changes
Per-process stats only while someone watches (
nodemetricscollector.go,cpumonitor.go,rammonitor.go,dbstats.go)The per-process cpu/memory stats only feed the live streams (
live-stats:{cpu,memory}:proc:<node>, published, never stored). Until now every node read/proc/$pid/statand/proc/$pid/statmfor every container process each second and published the result, mostly to nobody. node-metrics now asksPUBSUB NUMSUBevery 2 s and skips the scan and the publish while there is no subscriber. The monitors collect on request instead of on their own 1 s ticker; the values are absolute counters, so nothing changes in the data. In Valkey cluster mode NUMSUB only counts one shard, so there (and on any error) it keeps collecting as before. A newly opened live view gets its first frame after at most ~2 s.cgroup regexes once per distinct content (
containerenumerator.go)Every 5 s the enumerator ran 10 regexes over the cgroup file of every PID on the node. All processes of a container share one cgroup file, so the result is now cached per distinct content and per pass. The key is the content, not the PID, so a reused PID cannot inherit a stale match. Applies to cluster mode as well.
Slim pod decode (
store/podsonnode.go)The enumerator decoded every pod on the node into a full
v1.Podevery 5 s and used seven fields. It now decodes into a view with just those fields (same per-node index, falls back to the full path when the index is empty). Measured on a real 9.7 KB pod JSON: 47 µs → 18 µs, 19.5 KB → 0.4 KB allocated, 194 → 5 allocations per pod.Verification
go build ./...,go vet, existing unit tests andgolangci-lintclean. Not yet deployed to a cluster; worth checking on a dev cluster that the pod/workspace CPU and memory live views still update.🤖 Generated with Claude Code