Skip to content

fix(arrow/compute): respect GOMAXPROCS for default NumParallel - #1384

Merged
zeroshade merged 1 commit into
apache:mainfrom
samueleresca:cgroup-aware
Oct 19, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
samueleresca:cgroup-aware

Conversation

@samueleresca

@samueleresca samueleresca commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Since Go 1.25+, runtime.GOMAXPROCS(0) is cgroup-aware. See Release notes.
runtime.NumCPU() reflects the number of CPUs on the host without taking into account cgroup limits.

The issue has an impact in any containerised environment (e.g., k8s) when setting limits.

What changes are included in this PR?

Switching from NumParallel = runtime.NumCPU() to NumParallel = runtime.GOMAXPROCS(0)

Are these changes tested?

Tested manually using:

package compute_test

import (
	"runtime"
	"testing"

	"github.com/apache/arrow-go/v18/arrow/compute"
)

func TestCgroupDemo(t *testing.T) {
	t.Logf("NumCPU=%d GOMAXPROCS=%d DefaultExecCtx.NumParallel=%d",
		runtime.NumCPU(), runtime.GOMAXPROCS(0), compute.DefaultExecCtx().NumParallel)
}

and running with and without the change:

go test -c -o /tmp/c.test ./arrow/compute                                       
systemd-run --user --scope -q -p CPUQuota=200% /tmp/c.test -test.run CgroupDemo -test.v

Are there any user-facing changes?

Yes, a small behavioural change to the default:

  • When GOMAXPROCS is lower than the CPU count, whether set by the environment variable, set by a cgroup limit on Go 1.25 or later, or set in code before package init, the default NumParallel is now lower than before.
  • The deault is read once at package init. A later call to runtime.GOMAXPROCS(n) won't change it.
  • Callers can still override it with SetExecCtx or ExecCtx.NumParallel.
  • There are no API or signature changes.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. This is a sensible default now that Go 1.25+ makes GOMAXPROCS cgroup-aware, and go.mod already requires 1.26. I checked it locally: with GOMAXPROCS=2 the default NumParallel is 2, and under systemd-run -p CPUQuota=300% it's 3, where both runs previously gave 22 on this host. Callers can still override it through ExecCtx. One small thing: the title should follow the conventional-commit format in CONTRIBUTING.md; I'll adjust it on merge.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.

@zeroshade zeroshade changed the title Make default NumParallel cgroup-aware. fix(arrow/compute): respect GOMAXPROCS for default NumParallel Oct 19, 2026
@zeroshade
zeroshade merged commit db7566c into apache:main Oct 19, 2026
40 of 41 checks passed
Asthenia0412 pushed a commit to Asthenia0412/arrow-go that referenced this pull request Oct 20, 2026
The runtime.NumCPU() vs runtime.GOMAXPROCS(0) change in DefaultExecCtx
is out of scope for this PR (it was already addressed separately in
apache#1384). Revert to upstream/main's runtime.GOMAXPROCS(0)
to keep the PR diff focused on datum ownership semantics.
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.

2 participants