Skip to content

perf: override GOMAXPROCS to use all available CPUs#215

Closed
joshfriend wants to merge 1 commit intomainfrom
jfriend/gomaxprocs-override
Closed

perf: override GOMAXPROCS to use all available CPUs#215
joshfriend wants to merge 1 commit intomainfrom
jfriend/gomaxprocs-override

Conversation

@joshfriend
Copy link
Copy Markdown
Contributor

Container environments often set GOMAXPROCS to a low value (e.g. 2) based on cgroup CPU limits. With only 2 OS threads available, the Go scheduler can't run the zstd decoder, tar reader, and file-write goroutines concurrently — they time-slice, and the tar reader (the single-threaded funnel feeding the pipeline) gets starved.

Overriding to runtime.NumCPU() lets all goroutines actually run in parallel. Benchmarked on r8id.metal-48xlarge, this alone accounted for 3.7s of a 5.7s total improvement on a 334K-file 2.4 GB cache restore.

Container environments often set GOMAXPROCS to a low value (e.g. 2)
based on cgroup CPU limits. With only 2 OS threads available, the Go
scheduler can't run the zstd decoder, tar reader, and file-write
goroutines concurrently — they time-slice, and the tar reader (the
single-threaded funnel feeding the pipeline) gets starved.

Overriding to runtime.NumCPU() lets all goroutines actually run in
parallel. Benchmarked on r8id.metal-48xlarge, this alone accounted for
3.7s of a 5.7s total improvement on a 334K-file 2.4 GB cache restore.
@joshfriend joshfriend requested a review from a team as a code owner March 23, 2026 18:17
@joshfriend joshfriend requested review from stuartwdouglas and removed request for a team March 23, 2026 18:17
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c170c5fc30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/cachewd/main.go
// Go scheduler can't run the zstd decoder, tar reader, and file-write
// goroutines concurrently — they time-slice, and the pipeline stalls.
// Using all available CPUs lets all goroutines actually run in parallel.
runtime.GOMAXPROCS(runtime.NumCPU())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid bypassing quota-aware GOMAXPROCS defaults

Calling runtime.GOMAXPROCS(runtime.NumCPU()) here overrides both Go 1.25’s container-aware default and any operator-provided GOMAXPROCS value, which can over-subscribe CPU in quota-limited containers (for example, a pod limited to 2 CPUs on a 64-core node) and cause cgroup throttling/latency regressions under load; the same pattern is also introduced in cmd/cachew/main.go. Please keep the runtime default (or gate this behind an explicit opt-in) so deployments that rely on CPU limits are not penalized.

Useful? React with 👍 / 👎.

@joshfriend joshfriend closed this Mar 23, 2026
@joshfriend joshfriend deleted the jfriend/gomaxprocs-override branch March 23, 2026 18:34
@joshfriend joshfriend requested review from jrobotham-square and removed request for jrobotham-square and stuartwdouglas March 23, 2026 18:37
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