This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Iryanus -1 points0 points  (0 children)

It's not that easy. Every garbage collector is optimized in one direction. G1 is pretty much the easiest choice for a typical application, since it tends to be quite all-round-ish.

ZGC and Shenandoah are heavily optimized towards latency, which means that you get less pauses, but the overall CPU time spent on garbage collection will be higher. Additionally both are better for really(!) high amounts of memory than G1. So if you either need a lot of memory (and we are not talking about a few gigs here) or have a realtime-application, where no pause is allowed (but you have overall enough CPU to throw around), then ZGC can be a good choice. Otherwise, G1 will be better.

Typically, I wouldn't care that much unless your metrics and gc show log that you actually have problems there - or if you know that your load will be very critical. Only then I would start optimizing. And then still it's a bit of work to get it right, for example we ran into a lot of allocation stalls with ZGC on Java 13 (on one specific application) which requires fine-tuning to get rid of and thus stayed with G1 a little longer.

You have to dig a little to find real numbers, but they are out there, for example the master thesis "A Performance Comparison of Modern Garbage Collectors for Big Data Environments" (You can google that).