title: G1GC very high GC count and CPU, very frequency GCs that kill performance
body: <p>I've recently switched my Java application from CMS + ParNew to G1GC.
  What I observed when I did the switch is the CPU usage went higher and the GC count + pause time went up as well.
  My JVM flags before the switched were</p>
  <pre><code> java -Xmx22467m -Xms22467m -XX:NewSize=11233m -XX:+UseConcMarkSweepGC -XX:AutoBoxCacheMax=1048576 -jar my-application.jar
  </code></pre>
  <p>After the switch my flags are:</p>
  <pre><code>java -Xmx22467m -Xms22467m -XX:+G1GC -XX:AutoBoxCacheMax=1048576 -XX:MaxGCPauseMillis=30 -jar my-application.jar
  </code></pre>
  <p>I followed Oracle's Best Practices <a href="http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html" rel="nofollow noreferrer">http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html</a></p>
  <pre><code>Do not Set Young Generation Size
  </code></pre>
  <p>And did not set the young generation size.
  However I am suspecting that the young generation size is the problem here.
  What I see is the heap usage is fluctuating between ~6 - 8 GB.
  <a href="https://i.stack.imgur.com/2lnyx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2lnyx.png" alt="Heap usage" /></a></p>
  <p>Whereas before, with CMS and Par New there the memory usage grew between 4-16 GB and only then I saw a GC:
  <a href="https://i.stack.imgur.com/4NLfl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4NLfl.png" alt="enter image description here" /></a></p>
  <p>I am not sure I understand why with G1GC the GC is so frequent. I am not sure what I'm missing when it comes to GC tuning with G1GC.</p>
  <p>I'm using Java 8 :
  ava version &quot;1.8.0_144&quot;
  Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
  Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)</p>
  <p>I appreciate your help.</p>
  <p><strong>UPDATE</strong>:
  A bit more information about those pauses:
  <a href="https://i.stack.imgur.com/oyiRo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oyiRo.png" alt="enter image description here" /></a>
  As you can see all those pauses are G1New, and seemingly they are as long as my target pause time, which is 30ms.
  When I look at the ParNew pauses before the switch to G1GC, this is how it looked like:
  <a href="https://i.stack.imgur.com/UpSV3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UpSV3.png" alt="enter image description here" /></a>
  So they are also all young gen collections (ParNew) but they are less frequent and shorter, because they happen only when the heap usage gets to around 14GB (according to the graph)</p>
  <p>I am still clueless why the G1New happen so early (in terms of heap usage)</p>
  <p><strong>Update 2</strong>
  I also noticed that NewRatio=2, I don't know if G1GC is respecting that, but that would mean that my New Gen is capped at 7GB. Could that be the reason?</p>
  <p><strong>Update 3</strong>
  Adding G1GC GC logs:
  <a href="https://drive.google.com/file/d/1iWqZCbB-nU6k_0-AQdvb6vaBSYbkQcqn/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1iWqZCbB-nU6k_0-AQdvb6vaBSYbkQcqn/view?usp=sharing</a></p>