2

I have a web service application that can receive hundreds of requests per minute. With the default GC, the VM in Java 8 stop the world every few minutes, so it happens that some of the requests are extremely slow.

I changed the GC to G1 as follow:

-XX:+UseG1GC

However I read here that G1 is slower:

http://www.optaplanner.org/blog/2015/07/31/WhatIsTheFastestGarbageCollectorInJava8.html

Is there a way to use the default Java 8 collector stopping the world more frequently, so to have a less traumatic effect on some of the requests? What other solution is out there?

user1883212
  • 6,579
  • 9
  • 42
  • 71
  • What is your max heap size? – Nicolas Filotto Jun 03 '16 at 08:44
  • G1 is slower doesn't make any sense to me as it depends on the context, indeed G1 is meant to be used for big heap size up to 32 Go, testing it with 2 Go only doesn't really make sense – Nicolas Filotto Jun 03 '16 at 08:49
  • Read the [Oracle GC Tuning guide](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/toc.html). All of it. – the8472 Jun 03 '16 at 11:32
  • @user1883212, just setting G1GC flag would not be suffice. Have a look at this post: http://stackoverflow.com/questions/8111310/java-7-jdk-7-garbage-collection-and-documentation-on-g1/34254605#34254605 – Ravindra babu Jun 06 '16 at 12:07

1 Answers1

1

Your question implies that you are far away from having non-naive ideas about "garbage collector" setup.

All recent garbage collectors do have different properties; and they have a ton of settings that can be used to alter their behavior to achieve certain goals.

Meaning: it doesn't matter if G1 is slower. If you can tune it in a way that serves your application better than your current setup, it would be the choice you should make.

Long story short: you seem to be at a point where (garbage collection) performance of your application is a real issue. Then there is only one thing to do: start measuring. Understand what your code is doing; how it is doing that; and how that "interacts" with JIT and GC. Then identify goals towards you want to optimize; and start making experiments (where you, ideally, only change one single configuration change) to find JIT/GC tuning settings that move you towards that goal(s).

Example: maybe it would be enough to use G1; and give a "pause time goal" that works for you. But maybe you have to enable "gc tracing" for your JVM; to understand how much work the GC has to do for your application; and maybe maybe the answer would be to fix something in your code ... to simply generate less garbage.

Like in: there is not much point in tuning the GC; if your application is generating (avoidable) GBs of "garbage" every minute.

GhostCat
  • 127,190
  • 21
  • 146
  • 218