Five Eligible CPUs, a Four-CPU Quota: What Runtimes Report and What It Costs

· Octri ·

7 min read Original article ↗

The executor attributes above are internal and shown only to inspect the defaults; application code should configure its worker counts through the public max_workers argument.

Python 3.13 introduced os.process_cpu_count() to report logical processors usable by the calling thread. On Linux, it takes CPU affinity into account. Our five-CPU affinity mask therefore produced a count of five, despite the lower cgroup bandwidth quota.

The process pool inherited that number. The thread pool's default was nine because Python 3.13 uses min(32, (os.process_cpu_count() or 1) + 4) as its default upper bound. That extra room is intentional: thread pools often overlap I/O. Nine threads is not a claim that nine CPU-bound Python functions would run efficiently in parallel, and it is not a count of threads started immediately.

This difference is already a recognized question in CPython. A May 2026 issue proposes accounting for cgroup CPU quotas in os.process_cpu_count(); its reproducer shows a container limited to two CPU-equivalents reporting 20 eligible CPUs. We saw a smaller instance of the same distinction.

Go 1.23.2 made a related decision, although through a different mechanism:

runtime.NumCPU() reports the logical processors available to the process. In Go 1.23, the default GOMAXPROCS followed that count. GOMAXPROCS is not a worker-pool size: it caps how many goroutines may execute Go code simultaneously. In our environment, the old default allowed five-way parallel execution against a four-CPU-equivalent budget.

Node.js 22.16.0 returned four through its dedicated parallelism API:

That distinction is reflected in Node.js's own documentation. os.cpus() enumerates CPU information, while os.availableParallelism() is the API intended to estimate an appropriate amount of parallelism. It delegates to libuv, which can take Linux cgroup bandwidth limits into account. This is an estimate for application sizing, not an automatic resizing of every Node.js worker pool.

Finally, OpenJDK 21 reported four:

The JVM's container support considers CPU limits when determining the processors available to the VM. That value influences runtime ergonomics, including some thread pool sizing decisions. Java's container support documentation also describes -XX:ActiveProcessorCount as an explicit override.

These calls were all behaving according to the policies of their particular versions and APIs. Some were answering an affinity question; others were estimating a suitable execution budget. The next question was whether the distinction changed the work we observed.

Four waterfront dispatch kiosks display Python five, Go five, Node.js four, and Java four against the same harbor resource limit.

The reported CPU count depends on which system constraints a runtime considers.

A CPU count is only useful if it helps make the right scheduling decision. To test that, we ran a small CPU-bound workload in Python with either four or five worker processes.

Each run executed 80 jobs. Every job performed a busy loop until it had accumulated approximately 50 milliseconds of CPU time, measured inside its own worker process with time.process_time(). We recorded the elapsed time of each job from inside the worker, the total batch duration, and the change in cgroup throttling counters over the run. We warmed the process pool before starting the measurements.

One pair of runs produced:

CPU-bound worker processes Batch time, 80 jobs 95th-percentile job execution time Throttled cgroup periods
4 1.014 s 50.4 ms 0 of 10
5 1.000 s 70.9 ms 9 of 10

Adding the fifth process made almost no difference to total throughput. It did increase the measured 95th-percentile duration of an individual job by about 41%. The cgroup's nr_throttled counter increased during nine of the ten periods in that five-worker run.

We repeated the four-versus-five comparison. The second pair gave 50.3 ms versus 70.6 ms at the 95th percentile, with one throttled period for four workers and nine for five. A further run showed some background throttling even at four workers, but the per-job duration remained close to 50 ms; five workers again approached 71 ms.

These figures describe a small controlled workload, not a general claim that five workers are 41% slower in all containerized services. We measured time spent executing a job inside a worker, not end-to-end request latency including time waiting in the process pool's queue. The cpu.stat counters belong to the cgroup as a whole, so other processes in the cgroup can affect them. Run-to-run scheduling noise also matters.

Still, the mechanism behind the result was visible. With four busy processes, the workload could use roughly the available CPU budget throughout each scheduling period. With five, the processes could exhaust that budget earlier and wait for the next period. The same total amount of CPU work finished in about the same wall time, but individual jobs experienced more uneven progress.

This is why CPU bandwidth throttling is especially relevant to latency-sensitive services. A pool can create more simultaneous work without making the container capable of executing more total work.

Four workboats flow through a Gulf marina while five boats experience congestion under the same quota, reflecting measured job execution times.

An additional worker can increase contention without delivering a corresponding improvement in throughput.

Ten Gulf harbor signals show zero throttled periods with four workers, and nine throttled periods with five workers.

In the measured run, the container was throttled in nine of ten periods with five workers, versus none with four.

Why newer Go versions behave differently

Our Go measurement used version 1.23.2. The version is important.

Go 1.25, released in August 2025, changed the default behavior of GOMAXPROCS on Linux. When no explicit override is active, the runtime can consider cgroup CPU bandwidth limits as well as the available logical processors. It can also periodically update the default when the limits change.

In the environment used for our experiment, a Go program using the new container-aware default would ordinarily select four instead of five. runtime.NumCPU() would still describe the processor availability; it is GOMAXPROCS that changes its default policy.

The Go team's release notes and its explanation of container-aware GOMAXPROCS are explicit about the motivation: a cgroup quota limits aggregate CPU time, while GOMAXPROCS limits simultaneous Go execution. Bringing those values closer reduces the chances of a runtime exhausting its quota early and experiencing abrupt throttling.

There is a compatibility detail worth checking when upgrading. The new behavior depends on the Go version declared by the main module, as well as GODEBUG settings and whether GOMAXPROCS has been explicitly set. A newer toolchain does not automatically guarantee that every older module uses the new default. The runtime documentation describes those conditions and the special handling of small or fractional quotas.

Python's position is different. Its affinity-aware CPU count is useful in many situations, but it does not by itself tell a CPU-bound process pool how much CPU bandwidth a container has been allocated. Python 3.13 provides PYTHON_CPU_COUNT and -X cpu_count so deployments can override the reported value, or applications can supply max_workers explicitly.

Node.js's os.availableParallelism() and Java's container-aware availableProcessors() happen to align with the quota in our test. That does not mean every pool in those runtimes automatically follows those values, nor that the estimates will always be right. The process may sit under multiple cgroups with different limits, have an I/O-bound workload, or be constrained by resources other than CPU time.

These details make it risky to carry a single hard-coded rule across languages. The number worth using depends both on the environment and on what the runtime does with it.

Choosing a worker count in a container

For a CPU-bound pool, an effective parallelism estimate based on the smaller of eligible CPUs and the available CPU bandwidth is a reasonable starting point. It is not a universal optimum. Fractional quotas require a rounding policy, memory limits can dominate, and operations that frequently wait for I/O may benefit from much higher concurrency.

In this environment, an explicit Python process pool limit avoids the five-process default: