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.
The top 3
- Throughput-Focused GCs: Ideal for Batch ML: Parallel GC, often called the Throughput Collector, uses multiple threads to maximize the amount of work done by the application, making it highly effective for batch processing or offline ML training where longer, infrequent pauses are acceptable. It prioritizes overall processing speed over individual pause times.
- Latency-Focused GCs: Essential for Real-time ML: ZGC and Shenandoah are designed for ultra-low pause times, consistently achieving sub-millisecond (ZGC) or 1-10ms (Shenandoah) pauses, largely independent of heap size. This makes them critical for real-time ML inference, interactive services, and applications where minimal response time variations are paramount.
- G1 GC: The Balanced Choice for Hybrid ML Workloads: The Garbage-First (G1) collector strikes a balance between high throughput and predictable, soft real-time latencies, making it a popular default choice for many modern ML applications with mixed batch and interactive requirements. G1 achieves this by dividing the heap into regions and prioritizing collection in regions containing the most garbage, offering configurable pause time goals.
Sources
Open the full topic