Skip to content

manager: limit concurrent housekeeping cgroupfs reads with GOMAXPROCS semaphore - #3932

Open
yunzhao-cf wants to merge 1 commit into
google:masterfrom
yunzhao-cf:housekeeping-semaphore
Open

manager: limit concurrent housekeeping cgroupfs reads with GOMAXPROCS semaphore#3932
yunzhao-cf wants to merge 1 commit into
google:masterfrom
yunzhao-cf:housekeeping-semaphore

Conversation

@yunzhao-cf

Copy link
Copy Markdown

Add a process-wide semaphore (sized to GOMAXPROCS) around updateStats() in housekeepingTick() to limit concurrent cgroupfs reads. This prevents kernel lock contention on cgroup_rstat_lock when thousands of per-cgroup housekeeping goroutines flush cgroup stats simultaneously.

The semaphore is initialized lazily (via sync.Once) so that it captures the effective GOMAXPROCS after setMaxProcs() / --max_procs has been applied.

Also fix setMaxProcs() to respect the GOMAXPROCS environment variable when --max_procs is not explicitly set. Previously, setMaxProcs() unconditionally overrode GOMAXPROCS with runtime.NumCPU(), which on high-core-count machines (e.g. 192 cores) would create an oversized semaphore that provided no throttling.

Benchmark on a 192-core host with ~400 cgroups, GOMAXPROCS=2, CPUQuota=200%, ondemand scrape mode, 11 scrapes at 53s intervals:

Without semaphore: 75.05s total CPU, 3066ms p50 latency
With semaphore: 9.32s total CPU, 363ms p50 latency (0.124x)

Reviewed-by: Daniel Dao dqminh89@gmail.com
Signed-off-by: Yunzhao Li yunzhao@cloudflare.com

… semaphore

Add a process-wide semaphore (sized to GOMAXPROCS) around updateStats()
in housekeepingTick() to limit concurrent cgroupfs reads. This prevents
kernel lock contention on cgroup_rstat_lock when thousands of
per-cgroup housekeeping goroutines flush cgroup stats simultaneously.

The semaphore is initialized lazily (via sync.Once) so that it captures
the effective GOMAXPROCS after setMaxProcs() / --max_procs has been
applied.

Also fix setMaxProcs() to respect the GOMAXPROCS environment variable
when --max_procs is not explicitly set. Previously, setMaxProcs()
unconditionally overrode GOMAXPROCS with runtime.NumCPU(), which on
high-core-count machines (e.g. 192 cores) would create an oversized
semaphore that provided no throttling.

Benchmark on a 192-core host with ~400 cgroups, GOMAXPROCS=2,
CPUQuota=200%, ondemand scrape mode, 11 scrapes at 53s intervals:

  Without semaphore: 75.05s total CPU, 3066ms p50 latency
  With semaphore:     9.32s total CPU,  363ms p50 latency  (0.124x)

Reviewed-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Yunzhao Li <yunzhao@cloudflare.com>
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