OS & Systems FundamentalsGarbage Collection FundamentalsMedium⏱️ ~2 min

GC Throughput vs Latency Trade offs and Memory Overhead

Throughput vs Latency

Throughput collectors maximize application CPU time. They use parallel threads during collection and may stop the world for longer. Acceptable for batch jobs where total completion time matters more than individual response times.

Latency focused collectors minimize pause times. They do more work concurrently with application threads. Overhead is higher but pauses are shorter. Essential for interactive services where P99 latency matters.

Pause Time Characteristics

Parallel collectors: Stop the world for entire collection. Pause scales with heap size. 10 GB heap might pause for 100 to 500 milliseconds. Good throughput, poor latency.

Concurrent collectors: Most work concurrent with application. Short stop the world phases for root scanning and reference updates. Pauses typically 10 to 50 milliseconds regardless of heap size.

Pauseless collectors: ZGC and Shenandoah achieve sub-millisecond pauses even for terabyte heaps. Pauses are O(1) relative to heap size. Higher CPU overhead but predictable latency.

Memory Overhead

Concurrent GC requires more memory. The application continues allocating during collection. The collector must finish before heap exhausts. Rule of thumb: concurrent collectors need 2x the live data size as heap. More headroom reduces collection frequency and failure risk.

Compact collectors use less memory than non-compacting ones. Fragmentation wastes space with scattered free blocks too small to satisfy allocations. Compaction eliminates fragmentation but requires moving objects and updating references.

💡 Key Insight: Pick your priority: throughput (parallel GC), latency (concurrent GC), or ultra-low pause (ZGC or Shenandoah). No collector optimizes all dimensions. Understand your workload requirements before choosing.
💡 Key Takeaways
Throughput collectors: parallel work, longer pauses, good for batch
Concurrent collectors: work alongside application, 10 to 50 ms pauses
Pauseless collectors: sub-millisecond pauses even for terabyte heaps
Concurrent GC needs more memory: application allocates during collection
Compaction prevents fragmentation but requires moving objects
📌 Interview Tips
1Match collector to workload: batch jobs use parallel GC for throughput, web services use concurrent GC for latency
2Explain why concurrent GC needs more memory: collection races against allocation, more headroom prevents exhaustion
3For ultra-low latency requirements, recommend ZGC or Shenandoah: pauses are heap-size independent
← Back to Garbage Collection Fundamentals Overview