Software Development

How to optimize Garbage Collection for low-latency Java 21 applications?

AM Asked by Amanda Lewis · 19-02-2023
0 upvotes 12,610 views 0 comments
The question

We are seeing significant 'Stop-the-World' pauses in our high-frequency trading platform. We recently upgraded to Java 21 and are experimenting with ZGC and Shenandoah. Which GC is better for minimizing latency without sacrificing too much throughput? Are there specific JVM flags that are now obsolete with these modern collectors? 

3 answers

0
KA
Answered on 22-04-2023

For low latency, Generational ZGC (introduced in Java 21) is currently the gold standard. It aims for sub-millisecond pause times by performing almost all work concurrently with the application threads. Unlike the older G1GC, ZGC scales well with very large heaps (from 8MB to 16TB). You should start with the flag -XX:+UseZGC and -XX:+ZGenerational. You'll find that many old tuning flags like -Xmn or -XX:SurvivorRatio are largely unnecessary now, as the modern collectors are much more self-tuning.

0
R
Answered on 10-05-2023

Does ZGC still have a throughput penalty? I heard it uses more CPU cycles to achieve those low pause times compared to Parallel GC. 

JO 13-05-2023

Richard, you're correct that there is a slight overhead because the GC threads are working alongside your app. However, with Generational ZGC, this 'tax' has been significantly reduced. In most real-world scenarios, the benefit of avoiding a 200ms pause outweighs a 3-5% drop in raw throughput. If your app is extremely CPU-bound and can tolerate pauses, Parallel GC is still the king of throughput.

0
L
Answered on 30-05-2024

Just make sure you aren't over-allocating your heap. Modern GCs work best when they have enough breathing room to move objects around.

AM 02-06-2024

Good advice, Lisa. Keeping the heap size balanced is key. I've found that setting Xms and Xmx to the same value also helps stabilize performance in Java 21.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session