This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 21 · May 19 – 25, 2025

runtime: CPU limit‑aware GOMAXPROCS default

Worth knowingruntime

What changed
The runtime on Linux now uses CPU cgroup quota limits to set the default value of GOMAXPROCS.
Production impact
The source does not say.
Try it
Run a program inside a cgroup with a CPU quota and observe the value of runtime.GOMAXPROCS().
Source
github.com/golang/go/issues/73193

Understand it, then run it

The Go runtime now looks at the CPU limits that a container or cgroup imposes on the process. Before, the default value of GOMAXPROCS was simply the number of logical CPUs that the machine reports. If a program ran inside a container that was allowed only a fraction of the host’s CPUs, the runtime would still think it could use all of them, which could cause the program to be throttled by the kernel. With the change, the runtime reads the cgroup quota and sets GOMAXPROCS to that value instead. This means a Go program automatically respects the CPU limits that the operating system or container runtime has applied to it.

Run it now

Todaygo
// This program prints the default GOMAXPROCS value that the runtime has chosen.
// On Linux, the runtime now uses the CPU cgroup quota to set this value.
// If the program is not running inside a cgroup with a quota, the value will
// be the number of logical CPUs or the affinity mask, whichever is lower.
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Printf("GOMAXPROCS default: %d\n", runtime.GOMAXPROCS(0))
}

What it printed when we ran it on Go 1.27.1

GOMAXPROCS default: 2

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed