liveBook · Manning

Rate limit

As explained in 100 Go Mistakes and How to Avoid Them

CPU throttling is the deliberate reduction of processor execution capacity in response to resource limits, thermal conditions, or power policies.

A common deployment mistake is assuming that Go derives GOMAXPROCS from a container’s CPU limit. It does not: on an eight-core node, a container limited to 4,000 millicpu can still start with GOMAXPROCS set to eight. Kubernetes enforces the limit separately through the Completely Fair Scheduler (CFS), so concurrent execution can consume the quota quickly and trigger throttling. section 12.10

A four-core limit on an eight-core node

With a 100 ms CFS period and a four-core limit, the quota is 400 ms of CPU time per period. Four busy threads can consume all 400 ms during that period; CFS then throttles the application instead of allowing continued execution. The observable result is reduced CPU progress even though the host has additional cores. section 12.10

spec:
  containers:
  - name: myapp
    image: myapp
    resources:
      limits:
        cpu: 4000m

Use the Kubernetes resource declaration to relate a 4,000-millicpu limit to the CFS quota enforced at runtime. section 12.10

Reduce or diagnose the problem by:

  • Treating the container CPU limit and GOMAXPROCS as separate settings rather than assuming Go is CFS-aware. section 12.11
  • Bounding concurrent work when the goal is resource utilization control; a channel used for rate limiting should have a capacity tied to the limit, not an unexplained magic number. section 9.7

How 100 Go Mistakes and How to Avoid Them covers it

How deep it goes
Explains GOMAXPROCS, CFS periods, quotas, and exhaustion scenarios, then stops at deployment guidance rather than prescribing a CFS-aware implementation.
Examples
Uses an eight-core node, a 4,000-millicpu limit, four busy threads, and 100 ms CFS periods to trace quota exhaustion.
What it assumes
Assumes familiarity with Go services, goroutines, Kubernetes containers, and basic CPU-resource configuration.
What you can do after
Diagnose/debug with CFS periods, quotas, GOMAXPROCS, and deployment limits when Go workloads become CPU-throttled.
How it connects
Connects CPU throttling with GOMAXPROCS, Kubernetes resource limits, Docker, CFS, concurrency, and channel-based rate limiting.

Also explained in

Compare how 14 books explain rate limit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Go Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.