Why is garbage collector not doing a more aggressi

2019-03-30 06:57发布

问题:

These are my Sun Hotspot 1.6 JVM heap settings in WebLogic 11g:

-Xms10g -Xmx10g -XX:MaxPermSize=256m -XX:+UseParNewGC -XX:ParallelGCThreads=2 -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:ConcGCThreads=2

What I'm seeing in the JVM heap free % graph for 24 hours is basically heap free % goes down at a slow rate until we hit about 9% (takes about 24 hours). Then the system is running what looks like a full gc and gets back to 97%.

Is there some setting I should add/modify that will tell the JVM to do this full GC sooner than when we get below 10% heap free? e.g. some ratio setting?

Its not causing problems that it waits until we get to 9% free, but it makes monitoring/alerting more difficult. Ideally we want to stay higher than say 30% free at all times so that if we drop down to those single digit numbers, we know there is some sort of problem e.g. memory leak.

回答1:

Found the answer using a combination of other stackoverflow articles.

-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=N

where N is roughly what percentage occupied will trigger a full GC. Default is ~92, which is why I am seeing full GC's at 9% free. Switching it to 65 worked for my use case. A full GC happens ~ 35% free now.



回答2:

How about removing: -Xms10g and then monitor the total size of the heap? This will also cause the gc to run more often.

If your app only really use 300MB of ram(3%), then it seems extreme to start with a 10 Gigabyte allocation.