Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Eliminating 800ms Kubernetes CFS Tail
Latency Spikes at 30% CPU.

Latency-sensitive pods with 500m CPU limits suffer 450-800ms p99 spikes and probe flaps while dashboards show 30% average CPU.
Start the journey3 stages· Last modified Dec 1, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

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.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Inspecting /sys/fs/cgroup/cpu.stat (nr_throttled)
Core prerequisite: Inspecting /sys/fs/cgroup/cpu.stat (nr_throttled).
Kubernetes QoS classes
Core prerequisite: Kubernetes QoS classes.
Full walkthrough · 3 stages
01
L4 · FUNDAMENTALS

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.

Before · Naive
After · Hardened
02
L4 · FUNDAMENTALS

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));
03
L5 · APPLIED DESIGN

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.

Before · 500m CPU Limit + 16 JVM Threads
  • nr_throttled: 65%
  • P99 Latency: 800 ms
After · CPU Requests Only + ActiveProcessorCount=2
  • nr_throttled: 0%
  • P99 Latency: 14 ms
Engineering Decision Framework
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.
Decision Exercise · Make the Call

Why did increasing replicas without removing the 500m limit still leave p99 latency above 200ms?

ChoiceWhat it buysWhat it costs
500m Fractional CPU Limit + Uncapped ThreadsHard per-pod CPU ceiling in shared node poolsnr_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 msRequires accurate CPU requests and node-level capacity planning
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 1
Score: 0/1

Which cgroup file confirms whether a Kubernetes container is being frozen by CFS CPU throttling?

Recommended Learning Flow