Skip to content

perf(node-metrics): skip per-process scans without viewers, cache cgroup matches, slim pod decode - #1440

Merged
beneiltis merged 1 commit into
mainfrom
perf/node-metrics-proc-scans
Nov 13, 2026
Merged

beneiltis merged 1 commit into
mainfrom
perf/node-metrics-proc-scans

Conversation

@beneiltis

Copy link
Copy Markdown
Contributor

Stacked on #1439 (both touch nodemetricscollector.go); merge that one first, GitHub then retargets this PR to main.

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/stat and /proc/$pid/statm for every container process each second and published the result, mostly to nobody. node-metrics now asks PUBSUB NUMSUB every 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.Pod every 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 and golangci-lint clean. 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

Base automatically changed from perf/node-metrics-snoopy-per-pod to main November 13, 2026 11:40
…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
beneiltis force-pushed the perf/node-metrics-proc-scans branch from c7a295e to 7088008 Compare November 13, 2026 11:41
@beneiltis
beneiltis merged commit a8ba3f8 into main Nov 13, 2026
3 checks passed
@beneiltis
beneiltis deleted the perf/node-metrics-proc-scans branch November 13, 2026 11:43
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

Successfully merging this pull request may close these issues.

1 participant