Skip to content

Document cpu limits configuration for Kubernetes (like) environments #3932

@gerardsn

Description

@gerardsn

To optimize performance on a system, the Go runtime starts as many threads as there are CPU cores available on the machine. This is done by setting GOMAXPROCS==CPU cores. If it creates more threads this leads to more overhead and performance reduction, less means that the system is not fully utilized. See https://www.ardanlabs.com/blog/2024/02/kubernetes-cpu-limits-go.html for a more detailed explanation.

As of Go 1.25, the GOMAXPROCS env variable is aware of resource limits set for a container. See https://go.dev/blog/container-aware-gomaxprocs. However, if there is no resource limit set for a container, and the host is shared with other containers (as you normally would), the Go runtime will default to the number CPU cores on the node and be throttled by the system. Note that resource requests are not taken into account, only limits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions