Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

From GC logs you see young collections every 2 seconds on a G1 service; eden is 1,200 MB before each collection; heap after young GC rises slowly from 900 MB to 1,000 MB over an hour. Estimate the allocation rate and promotion rate, and say what these numbers tell you.

The allocation rate is roughly eden size divided by the interval between young collections: 1,200 MB every 2 seconds, about 600 MB per second. The post-GC heap rising by about 100 MB in an hour means a net promotion of roughly 28 KB per second, after whatever mixed collections reclaimed. High allocation with low promotion means almost everything dies young, which is healthy: GC cost is dominated by young pauses, so reducing the allocation rate lowers GC frequency and CPU, reducing survivors lowers pause time, and a JFR allocation profile shows which code paths to work on.

Why this question is asked

Most GC questions can be answered with two numbers: how fast the application allocates, and how fast data survives into the old generation. They tell us whether young collections are frequent or rare, whether pauses will be long, and whether the old generation will fill up. And we can estimate both from ordinary GC logs with simple arithmetic. Interviewers ask this to see whether we can reason from data instead of guessing. In this answer, we will recap what the two rates mean, do the calculations step by step, interpret what they say, and see what we would change and how to confirm it.

1A Quick Recap: Allocation and Promotion

Every new object is allocated in eden, the part of the young generation where objects start. When eden is full, G1 runs a young collection: live objects are copied to survivor regions or, if they have survived long enough, promoted to the old generation, and eden is emptied. So the allocation rate decides how often young collections happen.

The promotion rate is how fast data moves into the old generation. Old data is only cleaned up by concurrent marking and mixed collections, which are more expensive. So the promotion rate decides how quickly the old generation fills and how often that heavier work is needed.

2Calculating the Allocation Rate

Eden is 1,200 MB before each collection, and a young collection empties it. Young collections come every 2 seconds. So between two collections the application filled 1,200 MB of eden in 2 seconds.

Java
double edenMb = 1_200; // eden used just before each young GC
double intervalS = 2.0; // seconds between young GCs
double allocMbPerS = edenMb / intervalS; // 600 MB per second
double allocGbPerHour = allocMbPerS * 3_600 / 1_024; // about 2,109 GB, roughly 2 TB per hour
long youngGcsPerHour = (long) (3_600 / intervalS); // 1,800 young collections per hour

Notice this is an estimate. Eden also takes some allocation during the pause bookkeeping, and the interval varies, so we take an average over many collections. But the order of magnitude, about 600 MB per second, is what matters. That is a busy service, but not unusual for a JVM handling thousands of requests per second.

3Calculating the Promotion Rate

The heap after young GC is what remains once eden is empty: survivors plus the old generation. It rose from 900 MB to 1,000 MB over an hour. If nothing had been reclaimed from the old generation in that hour, that rise would be exactly what was promoted.

Java
double riseMb = 1_000 - 900; // 100 MB more after-GC heap in one hour
double promoKbPerS = riseMb * 1_024 / 3_600; // about 28 KB per second, net
double promoKbPerGc = riseMb * 1_024 / 1_800; // about 57 KB per young GC
double survivalShare = 0.057 / 1_200; // about 0.005%: almost everything allocated dies young
What the numbers say
NumberValueMeaning
Allocation rateabout 600 MB/syoung GC every 2 s; drives GC frequency and CPU
Young GCs per hour1,800each pause cost multiplies by this
Net promotionabout 28 KB/s, 100 MB/hourold generation fills slowly
Survival to oldabout 0.005% of allocationobjects die young: a healthy pattern

There is a catch: this is a net figure. If mixed collections reclaimed old garbage during the hour, the real promotion was higher, and the rise is promotion minus what was reclaimed. To get the gross number, we turn on -Xlog:gc+heap=info, which is included in gc* and prints old region counts before and after each young collection, and the difference per collection is what was promoted. Still, the conclusion is not sensitive to the exact value: tens of kilobytes per second against hundreds of megabytes allocated.

4Interpreting the Numbers

High allocation with low promotion is the pattern the generational design was built for. Almost every object dies before the next young collection, so each young collection frees nearly all of eden and copies very little. The old generation grows by only about 100 MB an hour, so concurrent marking and mixed collections are needed rarely.

So GC cost in this service is dominated by young pauses, 1,800 of them per hour. Their frequency comes from the allocation rate, and their length comes from how much survives each one, because copying survivors is the main work of a young pause.

That gives us two separate levers. Reducing the allocation rate makes young collections less frequent and lowers GC CPU: halving it to 300 MB per second means a young GC every 4 seconds, 900 per hour. Reducing survivors, the objects that are still alive at the moment of the pause, makes each pause shorter. One thing we should still watch is the slow rise: if after-GC heap keeps climbing even after mixed collections or across days, the 100 MB per hour is not garbage waiting for collection but retained data, and that would be a leak.

5Confirming With a JFR Allocation Profile

The estimates tell us how much is allocated, not where. A JFR recording does. Its allocation sampling events record which stack traces allocate the most memory, with low overhead suitable for production.

Shell
$ jcmd 4711 JFR.start duration=10m settings=profile filename=/tmp/alloc.jfr
$ jfr view allocation-by-site /tmp/alloc.jfr // JDK 21 and later; views vary by version
// Typical top entries for a service like this one:
// byte[] JsonGenerator.writeString 31% // response serialisation
// char[] StringBuilder.append 18% // log message building
// Object[] ArrayList.grow 9% // lists created per request

With this list, we can attack the largest allocators first: reusing serialisation buffers, avoiding building log strings that are not logged, sizing collections up front. Each change shows up directly in the next GC log as a longer interval between young collections.

6Follow-up questions

Why does the allocation rate matter if young collections are cheap?

Because cheap times many is still a cost. At 1,800 collections per hour, a 10 ms pause costs 18 seconds of stopped time per hour, plus the CPU of GC threads. Reducing allocation reduces every one of those, and it also makes the service less sensitive to sudden spikes, such as a burst of large responses.

How would ZGC change this picture?

Generational ZGC would collect the young generation concurrently, so there would be no 1,800 pauses, but it would still have to do the work, using CPU, and the allocation rate would decide how much headroom it needs to avoid allocation stalls. The arithmetic stays useful: 600 MB per second is the number its cycles must keep up with.

7Conclusion

In this answer, we estimated the allocation rate as eden size divided by the interval between young collections, 1,200 MB every 2 seconds or about 600 MB per second, and the net promotion rate from the rise in after-GC heap, 100 MB per hour or about 28 KB per second, noting that mixed collections make the real promotion somewhat higher. High allocation with low promotion is a healthy pattern where GC cost comes from frequent young pauses. Reducing allocation lowers GC frequency and CPU, reducing survivors shortens pauses, and a JFR allocation profile shows where to start.

What to say in the interviewAbout 90 seconds aloud

Open with

The allocation rate is roughly eden size divided by the time between young collections. Eden is 1,200 MB before each collection and collections come every two seconds, so the service allocates about 600 MB per second, which is 1,800 young collections an hour.

Then, if they want more

For promotion, the heap after young GC is survivors plus the old generation, and it rose by 100 MB in an hour, which is about 28 KB per second, or about 57 KB per collection.

That is a net figure, because mixed collections may have reclaimed some old garbage in that hour, so the real promotion is a bit higher; I could get it exactly from gc+heap logging, which shows old regions before and after each pause. Either way, the picture is clear: very high allocation, tiny promotion, so almost everything dies young.

That is healthy and is exactly what generational collection is good at. GC cost here is dominated by frequent young pauses. If I want less GC CPU and fewer pauses, I reduce the allocation rate; if I want shorter pauses, I reduce what survives each collection.

To know where to start, I would take a JFR recording with allocation sampling and fix the top allocating stack traces. I would also keep an eye on the slow rise, to make sure it levels off after mixed collections and is not a leak.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
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 "From GC logs you see young collections every 2 seconds on a G1 service; eden is 1,200 MB...": https://scrivio-interview-library.netlify.app/java/garbage-collection/7ca70e0034/