When remediating nr_throttled spikes, keep CPU requests, drop fractional limits, and set -XX:ActiveProcessorCount.
TL;DR30-second simplified summary▾
nr_throttled drops to 0% and p99 returns to 14ms.
Confirming CFS Throttling in cpu.stat.
Check nr_throttled and throttled_usec inside the pod; >10% throttled periods correlates directly with 100ms-800ms p99 spikes.
Applying Quota-Matched Java & K8s Config.
Set -XX:ActiveProcessorCount=2 and bounded ThreadPoolExecutor alongside unthrottled CPU limits.
int safeWorkers = Math.max(2, Math.min(4, Runtime.getRuntime().availableProcessors()));
ExecutorService pool = new ThreadPoolExecutor(
safeWorkers, safeWorkers, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(500));
Preventing Probe Flaps Under Burst Load.
Liveness/readiness probes fail when the HTTP server thread is frozen by CFS; eliminating throttling keeps probe latency <5ms. [INSERT YOUR BENCHMARK / PROD NOTE] for probe reliability.
- nr_throttled: 65%
- P99 Latency: 800 ms
- nr_throttled: 0%
- P99 Latency: 14 ms
- Problem
- Latency-sensitive pods with tight fractional CPU limits (e.g., 500m) suffer 100ms-800ms p99 tail latency spikes and readiness/liveness probe flaps even while average CPU is ~30%.
- Naive Solution
- Scale out more pod replicas while keeping the 500m CPU limit and default JVM/Python thread pool sizing.
- Why It Fails
- Each pod still has ~16 runtime threads competing for a 50ms quota per 100ms CFS period, burning the budget in ~3.2ms and freezing for the remaining ~96.8ms on micro-bursts.
- Alternatives
- Keep 500m CPU limits with smaller thread pools (reduces burst concurrency) vs. removing fractional CPU limits while retaining CPU requests and capping runtime concurrency.
- Engineering Decision
- Remove fractional CPU limits on latency-sensitive pods while keeping CPU requests for scheduling, and bind runtime concurrency (e.g., -XX:ActiveProcessorCount=2 and bounded ThreadPoolExecutor).
- Trade-Offs
- Pods can burst onto spare node CPU without CFS stalls (0% nr_throttled, 14ms p99), at the cost of relying on CPU requests and cgroup shares rather than hard ceilings; avoid for CPU-bound batch workers that must be capped to protect co-located pods.
Why did increasing replicas without removing the 500m limit still leave p99 latency above 200ms?
| Choice | What it buys | What it costs |
|---|---|---|
| 500m Fractional CPU Limit + Uncapped Threads | Hard per-pod CPU ceiling in shared node pools | nr_throttled at 65% under burst load P99 latency spikes to 800 ms with probe flaps |
| CPU Requests Only + Bounded Thread Pools (-XX:ActiveProcessorCount=2) | nr_throttled drops to 0% P99 latency stabilizes at 14 ms and probes stay <5 ms | Requires accurate CPU requests and node-level capacity planning |
Practice: Make the trade-off yourself.
Which cgroup file confirms whether a Kubernetes container is being frozen by CFS CPU throttling?