Skip to content

Commit

Permalink
pkg/thread: use GOMAXPROCS instead of NumCPU (bufbuild#912)
Browse files Browse the repository at this point in the history
In modern production environments, NumCPU is a poor estimate of the
actual parallelism available: it does consult the population count of
the cpuset mask (if any), but doesn't account for cgroups v1 or v2. Both
are commonly used in containerized environments.

The intention of this code is (I think?) to prevent us from burning
memory on initial stacks for zillions of goroutines, so we should
just use GOMAXPROCS: by definition, it's the maximum number of
goroutines that can run in parallel.
  • Loading branch information
akshayjshah authored Feb 3, 2022
1 parent 50bf39f commit 9d768ef
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion private/pkg/thread/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var (
globalParallelism = runtime.NumCPU()
globalParallelism = runtime.GOMAXPROCS(0)
globalLock sync.RWMutex
)

Expand Down

0 comments on commit 9d768ef

Please sign in to comment.