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.

The top 3

  1. Top 3 GCs for Ultra-Low Latency, Terabyte ML Heaps: For ML applications demanding sub-millisecond pause times on heaps up to 16TB, ZGC and Shenandoah are the leading choices. ZGC (Java 15+) maintains pause times under 1ms regardless of heap size, with Generational ZGC (JDK 21+) further improving throughput and memory efficiency, while Shenandoah offers comparable low-latency performance across both 32-bit and 64-bit systems.
  2. Optimal GCs for Throughput-Focused, Moderate-to-Large ML Heaps: G1 GC, the default since Java 9, excels in balancing predictable pauses and high throughput for medium to large heaps (e.g., >32GB), making it suitable for many ML workloads where raw throughput is key. Parallel GC, a multi-threaded option, remains a top performer for maximum throughput in batch ML processing, accepting longer pauses for overall work completion.
  3. Best GCs for Resource-Constrained, Small ML Heaps: For ML deployments with small heap sizes (under 2GB) or limited CPU cores, the Serial GC is highly efficient due to its single-threaded, low-overhead operation, often chosen by the JVM default in such environments. While Parallel GC can also be considered for small-to-moderate heaps (e.g., <8GB) if throughput is prioritized and longer pauses are acceptable.

Sources

Open the full topic