Quick revision
The short answer
With more heap, G1 grows the young generation to use the room its 200 ms default pause target allows, so young collections become rare but each one copies more surviving data, and those longer pauses land on the requests that make up p99. Average GC time can look unchanged because fewer, longer pauses add up to the same total. The fleet guidance is to measure the pause distribution and copy phases, set MaxGCPauseMillis to match each service's latency budget, never fix young size with -Xmn on G1, size heaps by live set rather than instance size, and consider generational ZGC where the budget is below what G1 can hold.
What to remember
In this answer, we saw that on larger instances G1 grows the young generation until predicted pauses approach its 200 ms default target, so young collections become rare but each one copies more survivors. Pause time depends on live data copied and roots scanned, not on heap size, and summary dashboards hide the change because fewer, longer pauses add up to similar totals. We measure pause distribution, survivor sizes and object copy times before and after, and the fleet guidance follows: set pause targets from latency budgets, never fix young size with -Xmn on G1, size heaps by live set, and use generational ZGC where G1 cannot meet the budget.
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.
With more heap, G1 grows the young generation to use the room its 200 ms default pause target allows, so young collections become rare but each one copies more surviving data, and those longer pauses land on the requests that make up p99. Average GC time can look unchanged because fewer, longer pauses add up to the same total. The fleet guidance is to measure the pause distribution and copy phases, set MaxGCPauseMillis to match each service's latency budget, never fix young size with -Xmn on G1, size heaps by live set rather than instance size, and consider generational ZGC where the budget is below what G1 can hold.
Background to this question
Moving to larger instances is usually seen as a safe upgrade: more CPU, more memory, same code. When latency gets worse instead, teams often look everywhere except the GC, because their dashboards show GC time per minute unchanged. This scenario is a good test of whether we understand what drives a G1 pause and how defaults scale with hardware. In this answer, we will see why G1 behaves this way on bigger heaps, why the dashboards hid it, how to measure it, and what guidance a platform team should give to all services.
1A Quick Recap: What G1 Tunes Automatically
G1 has one main goal, MaxGCPauseMillis, 200 ms by default. To meet it, G1 adjusts the size of the young generation between a minimum and a maximum share of the heap, 5 and 60 percent by default. A larger young generation means fewer collections, which is good for throughput, so G1 grows it as long as its prediction says the pause will stay within the target.
On a small instance with a 2 GB heap, the young generation is capped by the heap itself; it simply cannot grow much, so pauses stay short by accident, well below 200 ms. On a large instance with a 16 GB heap, the cap is far away, and G1 is free to grow eden until its predicted pause approaches the target.
2Why Pauses Got Longer
The time of a young pause is driven by how much live data it copies and how many roots it scans, not by the size of eden. Dead objects cost nothing to collect. So doubling eden only doubles the pause if the amount of surviving data doubles too.
For many services it does. A request that takes 300 ms holds its objects for 300 ms. With eden filling every second, objects from requests in flight at the moment of the pause survive; with eden filling every eight seconds, the same is true, but caches, session data and batches that live for a few seconds now also survive, because they were still alive when the much rarer pause came. More survivors means more copying, and copying survivors is most of a young pause.
| Measure | 4 vCPU, 4 GB heap | 16 vCPU, 24 GB heap |
|---|---|---|
| Eden size | about 1 GB | about 9 GB |
| Young GC interval | every 2 s | every 18 s |
| Data copied per pause | 40 MB | 350 MB |
| Young pause | 25 ms | 140 ms |
| GC time per minute | 750 ms | about 470 ms |
| Requests hitting a pause | 1 in 80, delayed up to 25 ms | 1 in 130, delayed up to 140 ms |
3Why the Dashboards Hid It
Most fleet dashboards show GC time per minute or GC time as a percentage. In the table above that number even improved. But p99 latency is about the slowest requests, and a request that arrives during a 140 ms pause waits 140 ms longer. If 1 percent or more of requests are caught by pauses, the pause length becomes part of the p99.
Average pause time can hide it too. If the dashboard averages young and mixed pauses, or averages per hour, a few long pauses get diluted. The question says pause times look the same; usually that means the summary metric looks the same, while the distribution has changed shape.
4Measuring Before and After
We should compare the old and new instance types with GC logs from both, at similar traffic. The useful details come from unified logging with phase and age information.
If the Object Copy phase dominates and survivor sizes grew with eden, the explanation above is confirmed. We should also line up pause timestamps with slow request traces; if the slowest requests cluster on pause moments, GC is the cause. If they do not, the larger instance changed something else, such as thread pool sizes derived from CPU count, or the new hardware has different memory bandwidth.
5Fleet Guidance
The first rule is to set a pause target that matches each service's latency budget. A service with a p99 target of 100 ms should not run with the default 200 ms target; something like -XX:MaxGCPauseMillis=50 tells G1 to keep eden smaller, accepting more frequent pauses and a little more GC CPU.
The second rule is to not fix the young generation with -Xmn, NewSize or NewRatio on G1. Those flags take away the lever G1 uses to meet the pause target, so the target is ignored. Teams sometimes add -Xmn after reading old CMS advice; the platform should flag it.
The third rule is to size the heap from the live set, not from the instance. A service with 1.5 GB of live data does not need 24 GB of heap just because the instance has 32 GB; a heap of about three to four times the live set is usually enough, and the remaining memory can serve other containers or the page cache. Setting heap as a fixed share of the container limit is fine only if the container limit itself was sized from the service's needs.
Finally, for services whose latency budget is below what G1 can reliably deliver, say a p99 target of 10 ms on a large heap, the guidance should point to generational ZGC, whose pauses do not grow with heap or live data, in exchange for more CPU and memory headroom.
6Follow-up questions
How would you present the trade-off between CPU and latency to service owners?
With their own numbers. For a service, I would show two or three configurations measured on a canary: for example, default G1 with p99 of 180 ms and 3 percent GC CPU, G1 with a 50 ms target and p99 of 95 ms at 5 percent GC CPU, and generational ZGC with p99 of 60 ms at 9 percent GC CPU and 30 percent more memory. Then translate the CPU into instances and money per month, so the owner can decide whether the latency gain is worth it against the service's latency objective. Most owners pick quickly once both sides are in their units.
Would lowering MaxGCPauseMillis always fix it?
It helps when the young generation grew because the target allowed it. It cannot help when the live data that must be copied in every pause is itself large, for example a big cache in the young generation, because even a small eden then has a lot to copy. In that case the fix is reducing survivors, or a concurrent collector.
Why not simply keep the old small heaps on the new instances?
That is often a good short-term fix: if the old heap size worked, capping the heap brings back the old behaviour. But it hides the real issue, which is that pause targets were never set from latency budgets. The lasting fix is setting both the heap from the live set and the pause target from the budget.
7Conclusion
In this answer, we saw that on larger instances G1 grows the young generation until predicted pauses approach its 200 ms default target, so young collections become rare but each one copies more survivors. Pause time depends on live data copied and roots scanned, not on heap size, and summary dashboards hide the change because fewer, longer pauses add up to similar totals. We measure pause distribution, survivor sizes and object copy times before and after, and the fleet guidance follows: set pause targets from latency budgets, never fix young size with -Xmn on G1, size heaps by live set, and use generational ZGC where G1 cannot meet the budget.
Open with
My first thought is that G1 did exactly what it was told. Its default pause target is 200 milliseconds, and it grows the young generation as long as it predicts pauses will stay under that.
Then, if they want more
On the old small instances the heap itself capped eden, so pauses were short by accident. On the large instances eden can be ten times bigger, so collections are rare, but each one copies more surviving objects, and the pause time is driven by live data copied and roots scanned, not by heap size.
The dashboards looked the same because they show GC time per minute or an average, and fewer, longer pauses can add up to the same total while the requests that hit a pause make up the p99.
I would confirm it with GC logs from both instance types: pause distribution, interval, survivor sizes, and the object copy phase from gc+phases, and I would line pause timestamps up with slow traces.
The fleet guidance is to set MaxGCPauseMillis per service from its latency budget, to never fix young size with -Xmn on G1 because that disables the pause target, to size heaps from the live set rather than the instance, and to move services whose budget is below what G1 can hold, say single-digit milliseconds, to generational ZGC with the extra CPU budgeted.
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.
- Official documentation
- HotSpot Garbage Collection Tuning Guide, JDK 21
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 "A platform team sees that after a move to larger instances, many G1 services have p99...": https://scrivio-interview-library.netlify.app/java/garbage-collection/940079d6a1/