Java garbage collection tuning tips
May 20, 2011 15:54:23 Last update: May 20, 2011 15:54:23
From Oracle:
The simplest and most reliable way to achieve short garbage collection times over the lifetime of a production server is to use a fixed heap size with the default collector and the parallel young generation collector, restricting the new generation size to at most one third of the overall heap.
The following example JVM settings are recommended for most engine tier servers:
If the engine tier server enables caching for call state data, the example settings are:
For replica servers, use the example settings:
The above options have the following effect:
The simplest and most reliable way to achieve short garbage collection times over the lifetime of a production server is to use a fixed heap size with the default collector and the parallel young generation collector, restricting the new generation size to at most one third of the overall heap.
The following example JVM settings are recommended for most engine tier servers:
-server -XX:MaxPermSize=128m -XX:+UseParNewGC -XX:MaxNewSize=256m \ -XX:NewSize=256m -Xms768m -Xmx768m -XX:SurvivorRatio=128 -XX:MaxTenuringThreshold=0 \ -XX:+UseTLAB -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled \ -XX:+CMSPermGenSweepingEnabled
If the engine tier server enables caching for call state data, the example settings are:
-server -XX:MaxPermSize=128m -XX:+UseParNewGC -XX:MaxNewSize=32m \ -XX:NewSize=32m -Xms768m -Xmx768m -XX:SurvivorRatio=128 -XX:MaxTenuringThreshold=0 \ -XX:+UseTLAB -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled \ -XX:+CMSPermGenSweepingEnabled
For replica servers, use the example settings:
-server -XX:MaxPermSize=128m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC \ -XX:MaxNewSize=64m -XX:NewSize=64m -Xms1536m -Xmx1536m -XX:SurvivorRatio=128 \ -XX:MaxTenuringThreshold=0 -XX:CMSInitiatingOccupancyFraction=60 \ -Dsun.rmi.dgc.server.gcInterval=0x7FFFFFFFFFFFFFFE -Dsun.rmi.dgc.client.gcInterval=0x7FFFFFFFFFFFFFFE
The above options have the following effect:
-
-XX:+UseTLAB- Uses thread-local object allocation blocks. This improves concurrency by reducing contention on the shared heap lock.
-
-XX:+UseParNewGC- Uses a parallel version of the young generation copying collector alongside the default collector. This minimizes pauses by using all available CPUs in parallel. The collector is compatible with both the default collector and the Concurrent Mark and Sweep (CMS) collector.
-
-Xms,-Xmx- Places boundaries on the heap size to increase the predictability of garbage collection. The heap size is limited in replica servers so that even Full GCs do not trigger SIP retransmissions. -Xms sets the starting size to prevent pauses caused by heap expansion.
-
-XX:NewSize- Defines the minimum young generation size. BEA recommends testing your production applications starting with a young generation size of 1/3 the total heap size. Using a larger young generation size causes fewer minor collections to occur but may compromise response time goals by cause longer-running full collections.
You can fine-tune the frequency of minor collections by gradually reducing the size of the heap allocated to the young generation to a point below which the observed response time becomes unacceptable.
-
-XX:MaxTenuringThreshold=0- Makes the full NewSize available to every NewGC cycle, and reduces the pause time by not evaluating tenured objects. Technically, this setting promotes all live objects to the older generation, rather than copying them.
-
-XX:SurvivorRatio=128- Specifies a high survivor ratio, which goes along with the zero tenuring threshold to ensure that little space is reserved for absent survivors.