Top JVM GCs for ML: ZGC, Shenandoah, G1 Compared

ZGC and Shenandoah excel in minimizing pause times for large machine learning heaps, supporting multi-terabyte sizes, while G1, the default since Java 9, provides a balanced approach between throughput and latency, suitable for various ML workloads. [7, 8, 11, 14, 16, 18, 20, 26]

The top 3

  1. ZGC's Sub-Millisecond Pauses for Real-time ML: ZGC consistently delivers garbage collection pause times under 1 millisecond, often ranging from 0.1ms to 0.5ms, even with multi-terabyte heaps. This ultra-low and predictable latency makes it ideal for real-time machine learning inference and other latency-sensitive applications. Shenandoah also achieves very low pauses, typically within 5-10ms, significantly outperforming G1's potential 50-500ms pauses for such workloads.
  2. Scaling ML Heaps: ZGC for Terabytes: For machine learning applications requiring massive memory, ZGC is specifically designed for ultra-large heap scalability, handling up to 16 terabytes. Shenandoah can manage large heaps up to 2 terabytes, effectively reducing fragmentation through concurrent compaction. G1 is suitable for large heaps in the tens of gigabytes range, offering a balance of throughput and predictable pauses.
  3. GC Trade-offs: Throughput vs. Latency in ML: Garbage collectors present a trade-off between throughput and latency. G1 prioritizes high throughput, often serving as the default for balanced performance, but its pause times can be less predictable (50-500ms). ZGC and Shenandoah prioritize ultra-low latency, achieving sub-millisecond to single-digit millisecond pauses, but this comes at the cost of slightly higher CPU overhead (ZGC and Shenandoah can use 7-15% more CPU than G1 due to concurrent operations) and potentially a small reduction in overall application throughput.

Sources

Open the full topic