2

What should I measure while choosing the garbage collector?

In my case, I am trying to compare the performance of throughput collector over G1GC, not quite sure what should I look for before making my final decision. I know looking at how much time is spent by garbage collector sounds like a good idea but it might or might not affect my application performance. (FYI - migrating from Java 8 to Java 11)

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Sagar
  • 5,315
  • 6
  • 37
  • 66

1 Answers1

2

The different GC in JVM are designed for different use cases:

  1. Throughput - Parallel
  2. Latency - CMS
  3. Predictability - G1, ZGC

Once you know which of these use cases you are looking for you can pick up a relevant metric e.g. it makes no sense to measure average pause time for throughput collector, it would be better to look at total time spent collecting.

Comparing Parallel collector to G1 makes no sense, they are designed for different use case. If you have to process batches of data quickly use Parallel. If you have an application that has to be responsive during the workload use G1.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • Where does CMS fall in the list above? – Sagar Apr 01 '19 at 17:47
  • 1
    CMS is latency oriented but is less predictable than G1. G1 is optimized in Java 11 and should have similar worst case latency to CMS but also has more consistent pause time and it's easier to tune. It's usually better to get a slightly lower but consistent latency, saves a lot of problems on PROD. – Karol Dowbecki Apr 01 '19 at 17:49
  • I see. Thanks for the response. Can you please elaborate more on predictability? Is it like, we can control how long gc should stop the world and how many times? – Sagar Apr 01 '19 at 17:58
  • 2
    If you know what is expected GC pause time (say up to 100 ms) that you can say the request SLA will be under certain time (say up to 500 ms). Without predictability in GC pause you can have a stop-the-world 10 sec GC pause that will break the SLA for the request. – Karol Dowbecki Apr 01 '19 at 18:04
  • The metric is not always that simple. E.g., *String Deduplication* only works with the G1 collector and may have an indirect impact on the performance, resulting in a throughput better than with Parallel. Of course, this depends on the particular application and its strings. – Holger Apr 02 '19 at 11:49