title: CMS Garbage Collection taking too long
body: <p>One of our customers runs into major performance problems which seem to be caused by long garbage collection runs and I don't know what to do about it...</p>
  
  <p>Java version: 1.7.0_67
  JVM args: -Xms10240m -Xmx16386m -XX:NewSize=2048m -XX:MaxPermSize=150m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails ...</p>
  
  <p><strong>Additional info</strong></p>
  
  <p>The application is our server backend for a web application. The server connects to a SQL database and multiple ERP systems. This data is then processed and sent out to the web clients. This customer in particular has around 50 users world wide that access data via this single server.</p>
  
  <ul>
  <li>OS: Windows Server 2008 R2 Datacenter + SP1</li>
  <li>CPU: Xeon E5-2660 (4 Cores + HT)</li>
  <li>RAM: 32 GB</li>
  </ul>
  
  <p><strong>What I've tried so far</strong></p>
  
  <ul>
  <li>increased Xmx and Xms (read that Xms should be identical or at least near Xmx for best performance)</li>
  <li>tinkered with size of Young Generation (Ratio 1, 2, 3)</li>
  <li>increased PermGeneration</li>
  <li>tried different GC variants</li>
  </ul>
  
  <p>Here are some parts of the gc log. You can clearly see that gc duration increases over time and peaks at about !!!17 seconds!!!.</p>
  
  <p>What could cause these problems?
  Are there any JVM args that sould be tinkered with?</p>
  
  <p><strong>Update / 25.03.2016</strong></p>
  
  <p>After getting VisualVM running it seems I found one of / the problem:
  Young Generation is now set to 4GB - the ratio between Eden and Survivor seems to be way off... Eden = 3,5 GB while Survivor = 0,5 GB
  As there are a lot of new objects generated all the time (a thing I'll have to investigate further), Eden gets populated with more then 0,5 GB (more like 1 to 2 GB). Survivor can't hold it and therefore a Major GC is triggered.</p>
  
  <p>New questions arising:</p>
  
  <ol>
  <li>Are my assumptiums wrong?</li>
  <li>I think my next steps should be to manually set the survivor ratio. Any suggestions based on my case?</li>
  <li>Do I need to disable AdaptiveSizePolicy? (-XX:-UseAdaptiveSizePolicy)</li>
  <li>Why does the GC log show the cause as "System.gc()" while there is definitely no manual GC triggered in code (decompiled all classes and checked):</li>
  </ol>
  
  <p><code>2016-03-25T04:59:55.726+0100: 14992.418: [Full GC (System.gc())2016-03-25T04:59:55.726+0100: 14992.418: [CMS: 265708K-&gt;265749K(6291456K), 1.1520720 secs] 507160K-&gt;265749K(10066368K), [CMS Perm : 54875K-&gt;54875K(91504K)], 1.1523255 secs] [Times: user=1.14 sys=0.00, real=1.14 secs]</code></p>
  
  <p><strong>Old Logs / 24.03.2016</strong></p>
  
  <p>First few logs after start:</p>
  
  <pre><code>12.434: [GC12.434: [ParNew: 1677824K-&gt;100069K(1887488K), 0.0983359 secs] 1677824K-&gt;100069K(10276096K), 0.0985257 secs] [Times: user=0.31 sys=0.02, real=0.11 secs] 
  16.293: [GC16.293: [ParNew: 1777893K-&gt;209664K(1887488K), 0.1933143 secs] 1777893K-&gt;212290K(10276096K), 0.1934443 secs] [Times: user=0.50 sys=0.02, real=0.19 secs] 
  19.994: [Full GC19.994: [CMS: 2626K-&gt;172662K(8388608K), 0.6312313 secs] 1521173K-&gt;172662K(10276096K), [CMS Perm : 24831K-&gt;24825K(24896K)], 0.6314259 secs] [Times: user=0.70 sys=0.06, real=0.64 secs] 
  261.411: [Full GC261.411: [CMS: 172662K-&gt;27686K(8388608K), 0.2232379 secs] 876118K-&gt;27686K(10276096K), [CMS Perm : 30913K-&gt;30911K(41376K)], 0.2234464 secs] [Times: user=0.22 sys=0.00, real=0.22 secs] 
  441.716: [Full GC441.716: [CMS: 27686K-&gt;24604K(8388608K), 0.1768511 secs] 500368K-&gt;24604K(10276096K), [CMS Perm : 30937K-&gt;30936K(51520K)], 0.1770344 secs] [Times: user=0.17 sys=0.00, real=0.17 secs] 
  </code></pre>
  
  <p>Some time later:</p>
  
  <pre><code>20235.044: [Full GC20235.044: [CMS: 195484K-&gt;248016K(8388608K), 1.0221468 secs] 798601K-&gt;248016K(10276096K), [CMS Perm : 52564K-&gt;52564K(87480K)], 1.0223571 secs] [Times: user=1.00 sys=0.02, real=1.01 secs] 
  20431.860: [Full GC20431.860: [CMS: 248016K-&gt;404539K(8388608K), 1.6120188 secs] 1385622K-&gt;404539K(10276096K), [CMS Perm : 54537K-&gt;54536K(87672K)], 1.6122663 secs] [Times: user=1.58 sys=0.03, real=1.61 secs] 
  20655.867: [Full GC20655.867: [CMS: 404539K-&gt;323692K(8388608K), 1.4389098 secs] 958490K-&gt;323692K(10276096K), [CMS Perm : 54655K-&gt;54652K(90896K)], 1.4391006 secs] [Times: user=1.43 sys=0.00, real=1.43 secs] 
  20956.441: [Full GC20956.441: [CMS: 323692K-&gt;378663K(8388608K), 1.4717112 secs] 1233969K-&gt;378663K(10276096K), [CMS Perm : 54713K-&gt;54713K(91092K)], 1.4719180 secs] [Times: user=1.47 sys=0.00, real=1.47 secs] 
  21149.053: [Full GC21149.053: [CMS: 378663K-&gt;284427K(8388608K), 1.1860728 secs] 717555K-&gt;284427K(10276096K), [CMS Perm : 54828K-&gt;54828K(91284K)], 1.1862890 secs] [Times: user=1.19 sys=0.00, real=1.19 secs] 
  21438.332: [Full GC21438.332: [CMS: 284427K-&gt;519857K(8388608K), 2.0659280 secs] 1676708K-&gt;519857K(10276096K), [CMS Perm : 62993K-&gt;62984K(91476K)], 2.0662088 secs] [Times: user=2.03 sys=0.03, real=2.06 secs] 
  21738.902: [Full GC21738.903: [CMS: 519857K-&gt;470206K(8388608K), 1.9628709 secs] 1590878K-&gt;470206K(10276096K), [CMS Perm : 63230K-&gt;63229K(104976K)], 1.9631042 secs] [Times: user=1.95 sys=0.00, real=1.95 secs] 
  21922.221: [Full GC21922.221: [CMS: 470206K-&gt;448817K(8388608K), 1.7216487 secs] 1127397K-&gt;448817K(10276096K), [CMS Perm : 63269K-&gt;63269K(105384K)], 1.7218965 secs] [Times: user=1.72 sys=0.00, real=1.72 secs] 
  22161.837: [Full GC22161.837: [CMS: 448817K-&gt;435548K(8388608K), 1.7168703 secs] 943145K-&gt;435548K(10276096K), [CMS Perm : 63298K-&gt;63298K(105576K)], 1.7170921 secs] [Times: user=1.72 sys=0.00, real=1.72 secs] 
  22402.100: [Full GC22402.100: [CMS: 435548K-&gt;613005K(8388608K), 2.3503697 secs] 1841133K-&gt;613005K(10276096K), [CMS Perm : 65977K-&gt;65976K(105576K)], 2.3506446 secs] [Times: user=2.29 sys=0.05, real=2.34 secs] 
  22642.893: [Full GC22642.893: [CMS: 613005K-&gt;621214K(8388608K), 2.3825301 secs] 1710749K-&gt;621214K(10276096K), [CMS Perm : 66925K-&gt;66924K(109964K)], 2.3827835 secs] [Times: user=2.37 sys=0.00, real=2.37 secs] 
  22883.148: [Full GC22883.148: [CMS: 621214K-&gt;600821K(8388608K), 2.4086658 secs] 1523224K-&gt;600821K(10276096K), [CMS Perm : 67550K-&gt;67550K(111544K)], 2.4089147 secs] [Times: user=2.40 sys=0.00, real=2.40 secs] 
  </code></pre>
  
  <p>At the peak of gc duration:</p>
  
  <pre><code>51603.282: [Full GC51603.282: [CMS: 4940385K-&gt;4859068K(8388608K), 16.6679541 secs] 5987385K-&gt;4859068K(10276096K), [CMS Perm : 114750K-&gt;114750K(153600K)], 16.6684484 secs] [Times: user=16.66 sys=0.00, real=16.66 secs] 
  51813.482: [Full GC51813.482: [CMS: 4859068K-&gt;4900085K(8388608K), 16.4928686 secs] 6116576K-&gt;4900085K(10276096K), [CMS Perm : 114750K-&gt;114750K(153600K)], 16.4933047 secs] [Times: user=16.49 sys=0.00, real=16.49 secs] 
  52026.148: [Full GC52026.148: [CMS: 4900085K-&gt;4896483K(8388608K), 16.8907197 secs] 6090675K-&gt;4896483K(10276096K), [CMS Perm : 114755K-&gt;114755K(153600K)], 16.8911947 secs] [Times: user=16.88 sys=0.00, real=16.89 secs] 
  52223.160: [Full GC52223.160: [CMS: 4896483K-&gt;5031826K(8388608K), 17.1507980 secs] 6559062K-&gt;5031826K(10276096K), [CMS Perm : 114763K-&gt;114763K(153600K)], 17.1513112 secs] [Times: user=17.16 sys=0.00, real=17.16 secs] 
  52425.802: [Full GC52425.802: [CMS: 5031826K-&gt;5016422K(8388608K), 17.8492606 secs] 6444936K-&gt;5016422K(10276096K), [CMS Perm : 114811K-&gt;114811K(153600K)], 17.8497294 secs] [Times: user=17.85 sys=0.00, real=17.85 secs] 
  52628.857: [Full GC52628.858: [CMS: 5016422K-&gt;5077701K(8388608K), 17.9003775 secs] 6606932K-&gt;5077701K(10276096K), [CMS Perm : 114812K-&gt;114812K(153600K)], 17.9027559 secs] [Times: user=17.88 sys=0.02, real=17.89 secs] 
  52747.442: [GC52747.443: [ParNew: 1677824K-&gt;209664K(1887488K), 1.3771078 secs] 6755525K-&gt;5530527K(10350324K), 1.3774630 secs] [Times: user=1.64 sys=0.08, real=1.37 secs] 
  52833.644: [Full GC52833.644: [CMS: 5320863K-&gt;4956574K(8462836K), 17.7157636 secs] 6575478K-&gt;4956574K(10350324K), [CMS Perm : 114826K-&gt;114826K(153600K)], 17.7162266 secs] [Times: user=17.74 sys=0.00, real=17.72 secs] 
  53058.481: [Full GC53058.482: [CMS: 4956574K-&gt;5002967K(8462836K), 17.9367047 secs] 6626713K-&gt;5002967K(10350324K), [CMS Perm : 114835K-&gt;114835K(153600K)], 17.9371138 secs] [Times: user=17.92 sys=0.00, real=17.92 secs] 
  </code></pre>
  
  <p>Full Log:
  <a href="http://pastebin.ca/3409912" rel="nofollow">http://pastebin.ca/3409912</a></p>