ML Heap Size Dictates Your JVM GC Champion.

The optimal JVM garbage collector for ML workloads is primarily determined by heap size and latency/throughput goals. Serial GC suits small heaps (<2GB), Parallel GC maximizes throughput for larger heaps, while G1 offers a balanced approach for medium to large heaps. For extremely large heaps (tens of GBs to TBs) and ultra-low latency, ZGC and Shenandoah are the champions, despite their higher CPU overhead.

The top 3

  1. Optimal JVM GCs for Small vs. Large ML Heaps: For small ML heaps (under 2GB), Serial GC can be efficient, while medium heaps (up to 32GB) often benefit from G1 GC's balanced approach. For very large ML heaps (over 32GB, even terabytes), ZGC and Shenandoah are champions, offering ultra-low pause times independent of heap size.
  2. Throughput vs. Latency: JVM GC Trade-offs for ML: Parallel GC and G1 are generally favored for maximizing throughput in ML workloads where moderate latency is acceptable. For critical real-time ML applications demanding ultra-low latency and minimal pause times, ZGC and Shenandoah are preferred, often accepting slightly higher CPU overhead for their concurrent operations.
  3. Sub-Millisecond Pauses: ZGC and Shenandoah's ML Edge: Modern JVM GCs like ZGC and Shenandoah set records for minimizing 'stop-the-world' pauses, achieving sub-millisecond or single-digit millisecond pause times even with multi-terabyte heaps. This concurrent operation is crucial for latency-sensitive ML inference, significantly outperforming older GCs like G1, which can have P99.9 pauses up to hundreds of milliseconds.

Sources

Open the full topic