1

Is it safe (or a good idea) to run "jmap -histo:live" on a scheduled basis (e.g. every 10minutes) to trigger garbage collection? We want to reduce the number of alarms we are getting from AWS (Amazon Web Services), which is triggered when memory consumption is high.

Server has 16GB RAM. GC is G1GC (instead of CMS). Xmx is set at 12GB. Xms is also 12GB (but we are planning to reduce it). Memory consumption icreases rapidly when Excel files are being processed / created via Apache POI (we're using XSSFSheet).

BTW, we plan to run the scheduled jmap on a Production environment (SAP Hybris 5.7.0.3).

geffchang
  • 3,279
  • 2
  • 32
  • 58
  • https://stackoverflow.com/questions/6418089/does-jmap-force-garbage-collection-when-the-live-option-is-used ? – Andremoniy Dec 01 '17 at 12:02
  • so you want to trigger a Full GC in production every ten minutes? smells like a small disaster to me – Eugene Dec 01 '17 at 12:14

1 Answers1

0

If you really want to trigger a full gc, jcmd <pid> GC.run seems clearer, but this is a recipe for disaster. Don't do it! Especially not with G1, where the full gc is single-threaded (one CPU) and can take ages. Fix the problem instead, which is that the application uses too much RAM (decrease the heap size and set limits for metaspace) or that the alarm goes off too early.

In short it is neither safe nor a good idea, it will kill you.

ewramner
  • 5,810
  • 2
  • 17
  • 33
  • I agree that triggering GC is not a good idea but, G1GC has parallel full GC as of JDK 10. – Jacek Tomaka Oct 21 '19 at 11:44
  • Indeed, Java 10 had not been released back in 2017. Still, triggering a full GC remains a very bad idea and is likely to take a long time even with multiple threads. – ewramner Oct 22 '19 at 14:59