Java offers several garbage collectors, each with its own set of trade-offs in terms of throughput, latency, and footprint. Selecting the right garbage collector is crucial for optimizing application performance:
Serial GC: Ideal for small applications with low memory footprint. Not suitable for low-latency applications due to longer GC pauses.
Parallel GC (Throughput Collector): Focuses on maximizing application throughput by utilizing multiple threads for garbage collection. However, it still suffers from significant pause times, making it less ideal for low-latency applications.
CMS (Concurrent Mark Sweep): Designed to minimize pause times by performing most of its work concurrently with application threads. While it offers lower pause times, CMS can suffer from fragmentation and longer overall GC times.
G1 (Garbage-First Collector): Aims to provide a good balance between throughput and pause times. It works by dividing the heap into regions and prioritizing the collection of regions with the most garbage, hence the name ‘Garbage-First’.
ZGC (Z Garbage Collector) and Shenandoah: The newest collectors designed for low-latency applications. They aim to achieve pause times of less than 10ms, even on large heaps, by performing most tasks concurrently with the application threads.
https://medium.com/stackademic/optimizing-java-for-low-latency-applications-803e181d0add