Quick revision
The short answer
A CPU request is what the scheduler uses to place the pod and the share of CPU it is guaranteed under contention; a CPU limit is a hard cap enforced by the Linux CFS quota. When a container uses up its quota within a scheduling period, usually 100 ms, it is throttled, paused until the next period, which shows up in a Java service as latency spikes. The JVM also sizes its GC threads, JIT compiler threads and the common ForkJoinPool from the CPU count it derives from the limit, so a low limit makes them small. We watch container_cpu_cfs_throttled_periods_total, and many teams set CPU requests without limits for latency-sensitive services while always setting memory limits.
What to remember
In this answer, we saw that CPU requests drive scheduling and the guaranteed share under contention, while limits cap usage through the CFS quota, so a container that uses its quota early in a period is throttled until the next one, adding latency. The JVM sizes GC threads, JIT threads and the common pool from the CPU count it derives from the limit, so a low limit makes them small. We measured throttling with container_cpu_cfs_throttled_periods_total, and saw why many teams set CPU requests without limits for latency-sensitive services, with ActiveProcessorCount set and memory limits always in place.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A CPU request is what the scheduler uses to place the pod and the share of CPU it is guaranteed under contention; a CPU limit is a hard cap enforced by the Linux CFS quota. When a container uses up its quota within a scheduling period, usually 100 ms, it is throttled, paused until the next period, which shows up in a Java service as latency spikes. The JVM also sizes its GC threads, JIT compiler threads and the common ForkJoinPool from the CPU count it derives from the limit, so a low limit makes them small. We watch container_cpu_cfs_throttled_periods_total, and many teams set CPU requests without limits for latency-sensitive services while always setting memory limits.
Why this question is asked
CPU settings look simple, a number of cores, but the way Linux enforces them surprises many Java teams: a service at 30 percent average CPU usage can still be throttled badly and show p99 latency several times its median. Interviewers ask this to see whether we understand requests, limits and the quota mechanism, and how the JVM reacts to them. In this answer, we will recap requests and limits, see exactly how throttling happens, look at how the JVM sizes itself from the CPU count, learn to measure throttling, and discuss the request-without-limit pattern.
1A Quick Recap: Requests and Limits
CPU in Kubernetes is measured in cores, or millicores, where 1000m is one core. The request is a reservation. The scheduler only places a pod on a node with enough unreserved CPU for its request, and when the node is busy, the kernel gives each container a share of CPU time proportional to its request. So a request of 500m guarantees about half a core when everyone is competing, and lets the container use more when the node has spare capacity.
The limit is a ceiling. Kubernetes translates it into a CFS quota, part of the Linux Completely Fair Scheduler: within every period of 100 ms by default, the container may use at most its limit multiplied by the period in CPU time. A limit of 1 core means 100 ms of CPU time per 100 ms period, across all of its threads together.
2What Throttling Looks Like
The catch is that the quota counts CPU time across all threads. A Java service has many threads running at once: request threads, GC threads, JIT compiler threads. If eight threads run in parallel, they use 100 ms of CPU time in about 12.5 ms of wall-clock time. The container has spent its quota, so the kernel pauses all its threads for the remaining 87.5 ms of the period. A request that needed 15 ms of work now takes more than 100 ms.
| Time in period | Threads running | Quota left |
|---|---|---|
| 0 to 12.5 ms | 8 threads (requests, GC, JIT) | 100 ms -> 0 ms |
| 12.5 to 100 ms | none: throttled | 0 ms |
| next period starts | threads resume | 100 ms again |
Notice that average CPU usage over a minute can be low, say 30 percent of the limit, while short bursts hit the quota many times per second. That is why throttling often appears as tail latency, slow p99 with a normal median, and why a garbage collection running with several parallel threads is a common trigger.
3How the JVM Sizes Itself From the CPU Count
The JVM decides many internal sizes from the number of available processors. It reads the container's CPU limit from cgroups and rounds it up: a limit of 1500m becomes 2 processors. Since JDK 19, the request (CPU shares) is no longer used for this count, so without a limit the JVM sees all the node's cores. From that number it sizes the parallel GC threads, the concurrent GC threads, the JIT compiler threads, and the default parallelism of ForkJoinPool.commonPool(), which parallel streams and some async APIs use.
So a very low limit makes the JVM small: one or two GC threads, a single-threaded common pool, and possibly the Serial collector, whose pauses stop the whole application. Very high counts can be just as bad without a limit, because the JVM then creates dozens of GC and compiler threads on a big node. -XX:ActiveProcessorCount lets us set the number the JVM uses, which is useful in both cases.
4Measuring Throttling
cAdvisor, built into the kubelet, exports two counters per container: container_cpu_cfs_periods_total counts scheduling periods in which the container ran, and container_cpu_cfs_throttled_periods_total counts periods in which it was throttled. Their ratio tells us what fraction of periods hit the limit. A few percent is normal; 20 percent or more on a latency-sensitive service is a problem, especially if it lines up with p99 latency spikes.
Inside the container, the same numbers are in the cgroup file cpu.stat (nr_periods, nr_throttled and throttled time), which is handy when debugging a single pod.
5Requests Without Limits for Latency-Sensitive Services
Because throttling hurts latency even at moderate average use, many teams set a CPU request but no CPU limit for latency-sensitive services. The request still guarantees the pod its share under contention and keeps scheduling honest, while bursts can use idle CPU on the node instead of being paused. The trade-off is less predictable performance, since a pod may run faster when the node is quiet than when it is busy, and a misbehaving pod can use spare CPU that others might have used. Some clusters enforce limits through policy, so this is a platform decision.
When we remove the limit, we should set -XX:ActiveProcessorCount close to the request, so the JVM does not size itself for all the node's cores. And memory is different: memory cannot be throttled, only reclaimed or killed, so memory limits should always be set, usually equal to the request for Java services.
| Setting | Scheduling | Bursting | JVM CPU count |
|---|---|---|---|
| Request only | guaranteed share | yes, into idle CPU | node cores unless set |
| Request = limit | guaranteed, Guaranteed QoS with memory too | no, throttled at limit | limit, rounded up |
| Limit much higher than request | guaranteed share | up to the limit | limit, rounded up |
ActiveProcessorCount is a common choice.6Follow-up questions
Does a CPU limit of 2 mean the JVM can only run two threads at once?
No. It can run as many threads in parallel as the node has cores; the limit only caps total CPU time per period. Eight threads can all run at once until they spend 200 ms of CPU time in a 100 ms period, and then the container is throttled. This is why parallel bursts are throttled even under a seemingly generous limit.
Can shorter CFS periods help?
A shorter period spreads the quota more evenly, so pauses are shorter, but it is a node-level kubelet setting that affects every pod and adds scheduling overhead. Most teams prefer removing or raising limits for latency-sensitive services instead.
How do virtual threads interact with CPU limits?
Virtual threads run on a carrier pool whose default size is the available processor count. With a CPU limit of 1, there is only one carrier, so CPU-bound work does not run in parallel. For I/O-bound services that is usually fine, but it is another reason to make sure the JVM's processor count matches the CPU the service really gets.
7Conclusion
In this answer, we saw that CPU requests drive scheduling and the guaranteed share under contention, while limits cap usage through the CFS quota, so a container that uses its quota early in a period is throttled until the next one, adding latency. The JVM sizes GC threads, JIT threads and the common pool from the CPU count it derives from the limit, so a low limit makes them small. We measured throttling with container_cpu_cfs_throttled_periods_total, and saw why many teams set CPU requests without limits for latency-sensitive services, with ActiveProcessorCount set and memory limits always in place.
Open with
A CPU request is a reservation: the scheduler uses it to place the pod, and under contention the kernel gives the container a share proportional to the request.
Then, if they want more
The limit is a hard cap, implemented with the CFS quota: in each 100 millisecond period the container can use at most limit times 100 milliseconds of CPU time, across all its threads.
Java services have many threads, so with a limit of one core and eight busy threads, the quota is gone in 12.5 milliseconds and every thread is paused for the rest of the period. That shows up as p99 latency spikes even when average CPU looks low, and GC is a common trigger.
The JVM also sizes itself from the CPU count it reads from the limit, rounded up: GC threads, JIT compiler threads and the common ForkJoinPool. With a low limit everything is small, and with one CPU and modest memory the JVM even picks the Serial collector.
Without a limit, since JDK 19 the JVM sees all node cores, so I set ActiveProcessorCount. To measure it, I look at container_cpu_cfs_throttled_periods_total divided by container_cpu_cfs_periods_total. For latency-sensitive services, many teams set CPU requests but no CPU limit, so bursts use idle CPU, while always keeping memory limits, because memory cannot be throttled, only killed.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 19
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Kubernetes documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain Kubernetes CPU requests and limits and what CPU throttling looks like for a Java...": https://scrivio-interview-library.netlify.app/spring-boot/containers-and-kubernetes/51a9e31341/