Quick revision
The short answer
The two environments run different JVMs in practice, because ergonomics derives defaults from the pod size. The 1 CPU / 1.5 GiB staging pod is below the server-class threshold, so it gets Serial GC, one GC thread, the minimum number of JIT compiler threads and a common pool of one; the 4 CPU / 8 GiB production pod gets G1 with four parallel GC threads, more compiler threads and a common pool of three, and its default heap is 2 GB instead of about 384 MB. So staging performance results say little about production. We make the important choices explicit, mainly the collector and the heap percentage, and run performance tests on production-shaped pods.
What to remember
In this answer, we saw that ergonomics gives the 1 CPU / 1.5 GiB staging pod Serial GC, one GC thread, a common pool of one and a heap of about 384 MB, while the 4 CPU / 8 GiB production pod gets G1, four GC threads, a common pool of three and a 2 GB heap. Staging performance results therefore do not represent production. We made the collector and heap percentage explicit in every environment and moved performance testing onto production-shaped pods.
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.
The two environments run different JVMs in practice, because ergonomics derives defaults from the pod size. The 1 CPU / 1.5 GiB staging pod is below the server-class threshold, so it gets Serial GC, one GC thread, the minimum number of JIT compiler threads and a common pool of one; the 4 CPU / 8 GiB production pod gets G1 with four parallel GC threads, more compiler threads and a common pool of three, and its default heap is 2 GB instead of about 384 MB. So staging performance results say little about production. We make the important choices explicit, mainly the collector and the heap percentage, and run performance tests on production-shaped pods.
Background to this question
Teams often size staging smaller than production to save money, and that is reasonable for functional tests. The problem appears when someone uses staging to judge performance or to investigate a GC problem, and gets misleading answers. This debugging question tests whether we can recognise that the JVM itself adapts to the pod, and explain each difference from first principles rather than blaming the environment in general. In this answer, we will compare the collector choice, the thread counts and the heap defaults in both pods, see the effect on the GC logs, explain why staging tests do not transfer, and then fix the setup.
1Why the Same Image Behaves Differently
The image contains the same JDK, the same application and the same flags, but the JVM does not decide its settings when the image is built. It decides them when it starts, through ergonomics: it reads the container's CPU and memory limits and picks defaults from them. So two pods with different limits are, as far as the JVM is concerned, two different machines.
The quickest way to see the difference is to ask both JVMs directly.
Every line differs, although nobody changed a flag. Let us go through why.
2Difference 1: Serial GC in Staging, G1 in Production
Ergonomics treats a machine as server class only if it has at least two CPUs and roughly 2 GB of memory. The staging pod fails both tests, so the JVM chooses the Serial collector, which collects with one thread and stops the application for every collection, young and old. Production passes, so it gets G1, which collects young regions in parallel, does most old-generation marking concurrently, and aims for a 200 ms pause target.
That alone explains why the GC logs look different: staging logs show Pause Young (Allocation Failure) and Pause Full lines from Serial, while production shows G1 Evacuation Pause, Concurrent Mark and mixed collections. Engineers comparing them are comparing two different algorithms.
3Difference 2: Thread Counts Derived From CPUs
The CPU count drives several pools. ParallelGCThreads is 1 in staging and 4 in production. The number of JIT compiler threads, CICompilerCount, is the minimum in staging and higher in production, so warmup takes longer in staging because fewer threads compile hot methods. The ForkJoinPool common pool, used by parallel streams and by CompletableFuture's default async methods, has parallelism of CPUs minus one with a minimum of one: 1 in staging, 3 in production. Frameworks such as Netty, Tomcat's defaults in some setups, and connection pools that read availableProcessors() also scale.
| Value | Staging 1 CPU / 1.5 GiB | Production 4 CPU / 8 GiB |
|---|---|---|
| Server class? | No | Yes |
| Collector | Serial | G1 |
| ParallelGCThreads | 1 | 4 |
| Common pool parallelism | 1 | 3 |
| Default max heap (25 percent) | about 384 MB | about 2 GB |
| Default initial heap (1/64) | about 24 MB | about 128 MB |
4Difference 3: Heap Defaults as a Percentage
Without -Xmx, the maximum heap is 25 percent of the container memory and the initial heap is one sixty-fourth. That gives about 384 MB in staging and 2 GB in production. With a smaller heap, staging collects much more often for the same allocation rate, and its live data set may be close to the maximum, which causes repeated full GCs that production never sees. Conversely, a leak that grows slowly may take hours to show in production's larger heap but minutes in staging.
5Why Staging Performance Tests Mislead
Put together, staging differs in collector, parallelism and heap, so its throughput, latency percentiles and GC behaviour cannot be scaled up to production by any simple factor. A change that looks like a 20 percent improvement in staging may be noise in production, and a GC problem in production may not reproduce in staging at all because the collector is different. Even a single-threaded bottleneck can look different, because with one CPU every background thread competes with request threads.
Staging is still fine for functional testing. The mistake is using it as evidence for performance and tuning decisions.
6What We Change
First, make the important decisions explicit so they do not depend on the pod: name the collector and set the heap as a percentage. Then the JVM in both pods at least runs the same algorithm with the same proportions.
Notice what this does not fix: the thread counts still follow the CPUs, and G1 with one CPU is still a different experience from G1 with four. That is correct behaviour, so the second change is about the test environment, not the flags. Performance and load tests run on pods with the same CPU and memory limits as production, even if there are fewer of them, for example one or two production-shaped pods in a performance namespace. If the staging pod must stay small for cost, give it at least 2 CPUs and 2 GiB so it stays in the same ergonomic class, and label its results as functional only.
7Follow-up questions
Should we set -XX:ActiveProcessorCount=4 in staging to imitate production?
It would make thread counts match, but the pod still has only one CPU of quota, so four GC threads would compete for it and get throttled. It hides the difference rather than removing it. Production-shaped pods for performance tests are the honest fix.
Is it bad that production gets G1 by default?
No, G1 is usually the right choice there. The issue is only that staging silently gets something different. Naming the collector explicitly documents the decision and makes every environment run it.
How do we spot this quickly in an incident?
Run jcmd <pid> VM.flags in both environments, or look at the first lines of the GC log, which name the collector and the CPU count. If the collector or heap differs, compare like with like before drawing conclusions.
8Conclusion
In this answer, we saw that ergonomics gives the 1 CPU / 1.5 GiB staging pod Serial GC, one GC thread, a common pool of one and a heap of about 384 MB, while the 4 CPU / 8 GiB production pod gets G1, four GC threads, a common pool of three and a 2 GB heap. Staging performance results therefore do not represent production. We made the collector and heap percentage explicit in every environment and moved performance testing onto production-shaped pods.
Open with
The image is the same but the JVMs aren't, because ergonomics decides at startup from the pod limits. The staging pod has 1 CPU and 1.5 gigabytes, which is below the server-class threshold of two CPUs and about two gigabytes, so the JVM picks the Serial collector.
Then, if they want more
Production has 4 CPUs and 8 gigabytes, so it gets G1. That's why the GC logs look completely different: Serial pauses and full GCs in staging, G1 evacuation pauses and concurrent marking in production.
Then everything derived from the CPU count differs: one parallel GC thread versus four, fewer JIT compiler threads so warmup is slower, a common pool of one versus three, and any framework pools that use availableProcessors.
And the default heap is 25 percent of memory, about 384 megabytes versus 2 gigabytes, so staging collects much more often and may hit full GCs production never sees. So staging performance numbers just don't transfer. What I'd change: make the collector and heap explicit everywhere, say UseG1GC and MaxRAMPercentage of 70, so at least the algorithm and proportions match.
Then run performance tests on pods with production's CPU and memory limits, even if there are only one or two of them. If staging has to stay small for cost, I'd treat it as functional only, and ideally give it 2 CPUs and 2 gigabytes so it's in the same ergonomic class.
About this answer
- Last updated
- 12 November 2026
- 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.
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 "The same service image runs on 1 CPU / 1.5 GiB pods in staging and 4 CPU / 8 GiB pods in...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/6556321aae/