Go Apps Throttled in Kubernetes Due to GOMAXPROCS Misconfiguration — Here's the Fix
Go applications running in Kubernetes pods can suffer intermittent P99 latency spikes because the Go runtime defaults to reading the physical node's CPU count via runtime.NumCPU(), ignoring the container's CPU limits enforced by Linux cgroups. On a 32-core node with a pod limit of 2 CPUs, the runtime spawns 32 OS threads, causing the Linux CFS scheduler to throttle the entire application when cgroup quota is exceeded within its 100ms window. Uber's open-source package go.uber.org/automaxprocs solves this by reading cgroup values at startup and setting GOMAXPROCS to match the actual container quota. Alternatively, developers can set GOMAXPROCS manually at init, though this risks falling out of sync if the pod spec changes. Starting with Go 1.25, scheduled for August 2025, the runtime will natively read cgroup CPU quotas on Linux and adjust GOMAXPROCS automatically, eliminating the need for any external dependency.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in