This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new db7566c7 fix(arrow/compute): respect GOMAXPROCS for default
NumParallel (#1384)
db7566c7 is described below
commit db7566c7dddea78445befca296dd83dda0e4b77f
Author: Samuele Resca <[email protected]>
AuthorDate: Mon Oct 19 22:12:00 2026 +0100
fix(arrow/compute): respect GOMAXPROCS for default NumParallel (#1384)
### Rationale for this change
Since Go 1.25+, `runtime.GOMAXPROCS(0)` is cgroup-aware. See [Release
notes](https://go.dev/doc/go1.25#runtime).
`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:
```go
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:
```bash
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.
---
arrow/compute/executor.go | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arrow/compute/executor.go b/arrow/compute/executor.go
index f666fcae..cb1dfee4 100644
--- a/arrow/compute/executor.go
+++ b/arrow/compute/executor.go
@@ -93,7 +93,7 @@ var (
// - PreallocContiguous = true
// - Registry = GetFunctionRegistry()
// - ExecChannelSize = 10
-// - NumParallel = runtime.NumCPU()
+// - NumParallel = runtime.GOMAXPROCS(0)
func DefaultExecCtx() ExecCtx { return defaultExecCtx }
func init() {
@@ -101,9 +101,10 @@ func init() {
defaultExecCtx.PreallocContiguous = true
defaultExecCtx.Registry = GetFunctionRegistry()
defaultExecCtx.ExecChannelSize = 10
- // default level of parallelism
+ // default level of parallelism, bounded by GOMAXPROCS so that cgroup
CPU
+ // limits (Go 1.25+) and explicit GOMAXPROCS settings are respected.
// set to 1 to disable parallelization
- defaultExecCtx.NumParallel = runtime.NumCPU()
+ defaultExecCtx.NumParallel = runtime.GOMAXPROCS(0)
}
// SetExecCtx returns a new child context containing the passed in ExecCtx