skip to content

Promotion out of the young area rises sharply when a service doubles its traffic, though object lifetimes are unchanged — why?

level: seniorimportance: should knowfreq 46%

answer

  1. the interval changed, not the lifetime
  2. area size over allocation rate
  3. a shorter interval catches more still alive
  4. surviving fraction is roughly lifetime over interval
  5. promotion churn, not longer-lived objects

basics

~20 s

The young area is collected when it fills, so doubling the allocation rate halves the interval between collections. Objects whose lifetime is unchanged now span a larger share of that shorter interval, so more of them are still live when the collector arrives, and more get promoted.

solid answer

~40 s

Age in a generational heap is measured in collections survived, and the collection interval is set by the area's size divided by the allocation rate — not by the clock. Double the traffic and that interval halves. An object that stays reachable for roughly `L` and meets collections spaced `T` apart survives one with probability about `L/T` when `L` is below `T`, so halving `T` roughly doubles the surviving fraction. The same objects, living exactly as long as before, now age and are promoted. This is **premature promotion**: objects that were about to die are moved into the mature area, where cheap young collections can no longer reclaim them, so mature occupancy climbs and mature collections come round sooner.

go deeper

for a junior

Hold on to one fact: the young area is collected when it fills, so a program that allocates faster is collected more often even though its objects live exactly as long.

for a middle

Derive the interval as area size divided by allocation rate, and explain why a shorter interval finds a larger fraction of objects still alive and therefore promotes more of them.

for a senior

Recognise premature promotion in a running system. Separate a rising post-collection occupancy floor, which means retention, from a flat floor with a growing sawtooth, which means promotion churn.

for a principal

Decide where to spend. Weigh footprint bought for the young area against the allocation the application could stop doing, and state which one you would fund for a fleet and why.

## What sets the collection interval A young area is collected when it is full. That gives an interval with nothing clock-like about it: T = young area size / allocation rate A 1 GB young area filled at 500 MB per second is collected about every 2 seconds. Double the request rate, and if each request allocates the same amount, the fill rate doubles to 1 GB per second and the interval halves to about 1 second. Nothing about any individual object changed. ## The survival model Age is counted in **collections survived**, so what matters to an object is not how long it lives but how its lifetime compares with `T`. Take an object that stays reachable for a span `L` and is allocated at a moment unrelated to the collection cycle. The next collection falls somewhere in the interval ahead of it, so, roughly: - if `L` is well below `T`, the chance it is still live when the collector arrives is about `L / T`; - if `L` reaches or exceeds `T`, it survives at least one collection nearly always. This is a back-of-the-envelope model, not a theorem — real allocation is bursty and lifetimes are not uniform — but it gets the direction and the order of magnitude right, which is what an interview wants. ## The worked example Take a service where a unit of work holds its objects for about 200 ms. | | before | after traffic doubles | |---|---|---| | allocation rate | 500 MB/s | 1 GB/s | | young area | 1 GB | 1 GB | | collection interval | ~2 s | ~1 s | | surviving fraction (`L` = 200 ms) | ~10% | ~20% | The surviving fraction doubles because the interval halved. Survivors are copied, aged and, once they have survived enough collections, promoted. So promotion volume rises roughly in step — and it rises on top of the doubled allocation, so the absolute number of promoted bytes per second grows more than twofold. ## Why promotion is the expensive outcome Promotion is not a tidy-up; it is the collector giving up on reclaiming that object cheaply: 1. The bytes are **copied** out of the young area, which is work paid during the young collection itself. 2. The object now lives where young collections do not trace, so if it dies a millisecond later its space is held until a mature-area collection runs. 3. Mature occupancy climbs at the promotion rate, so mature collections arrive sooner and each has more to trace. 4. Each mature collection is the expensive kind, so the split's benefit erodes exactly as promotion grows. The effect is self-reinforcing in appearance: occupancy rises, collections grow, pauses lengthen, and the program that caused it never changed how long it holds anything. ## The confusion to avoid Rising mature occupancy has two very different causes, and they are treated differently: - **Retention.** Objects in the mature area are still reachable because something holds them — an unbounded collection, a registry that is never pruned. Occupancy after a mature collection keeps climbing, because the collector cannot reclaim what is reachable. - **Promotion churn.** Objects in the mature area are already dead; they simply arrived there and now wait for a collection that runs rarely. Occupancy after a mature collection returns to the same floor each time. The distinguishing observation is what happens **after** a mature collection: a floor that keeps rising is retention, a floor that is flat with a rising sawtooth above it is promotion churn. ## What actually changes the picture - **Raise `T`.** A larger young area restores the interval at the higher allocation rate; that is the direct counter to the mechanism above, at a cost in footprint and in the length of each young collection. - **Allocate less per unit of work.** Fewer intermediates means a lower fill rate, which raises `T` without buying memory. - **Hold objects for less time.** Shortening the span an object stays reachable moves it back below `T` — releasing a buffer before a slow downstream call rather than after it, for instance. - **Require more survivals before promotion.** This filters objects that survived by timing alone, at the cost of copying survivors repeatedly and needing somewhere to keep them while they age. ## What an interviewer is listening for That you reach for the interval rather than the object; that you can write `T = size / rate` and say what halving `T` does to the surviving fraction; and that you can separate promotion churn from genuine retention by what the occupancy floor does after a mature collection.

  • Does promoting more objects at least make the young collections cheaper?
    No. Promotion is the copying, so the young collection has already paid for it, and the promoted objects add to the mature live set that the rare, expensive collection must trace. The young area is cheap when objects die in it, not when they leave it.
  • Which lever changes this without touching the collector's configuration?
    Allocate less and hold objects for less time. Fewer intermediates per unit of work lowers the fill rate and lengthens the interval, and releasing buffers before a slow downstream call rather than after it shortens the span an object stays reachable. Both push lifetimes back under the interval.

saying these in an interview costs you the question

  • Thinks object age is measured in elapsed time, so traffic cannot affect it
  • Assumes promotion rises only when objects genuinely start living longer
  • Believes a promoted object that dies is reclaimed by the next young collection
  • Says enlarging the young area cannot change how much is promoted
  • Treats rising mature-area occupancy as proof that something is being retained