The standard Java Virtual Machine (JVM) is configured to optimize for throughput. But some systems are more interested in low pause/reduced latency and GC (garbage collection) might be one source of pausing. (you can read an interesting article about what latency means to your business)
I have found a post on GigaSpaces forum providing some possible JVM configurations to optimize on latency:
-Xms2g -Xmx2g -Xmn150m -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=10 -XX:CMSIncrementalDutyCycle=50 -XX:ParallelGCThreads=8 -XX:+UseParNewGC -XX:MaxGCPauseMillis=2000 -XX:GCTimeRatio=10 -XX:+DisableExplicitGC
Please note that -XX:+UseConcMarkSweepGC has the heaviest impact on performance – decrease of 40%.
The following set of parameters shows 20% better performance than with -XX:+UseConcMarkSweepGC while the pause size still is below 100msec in embedded test with payload 10KB and 100 threads:
-Xms2g -Xmx2g -Xmn150m -XX:GCTimeRatio=2 -XX:ParallelGCThreads=8 -XX:+UseParNewGC -XX:MaxGCPauseMillis=2000 -XX:+DisableExplicitGC
While I’m pretty sure that most of the applications do no need such an advanced VM configuration, it is interesting to see what strategies are employed when low latency is needed.
Option | Details |
---|---|
-XX:+UseConcMarkSweepGC | Sets the garbage collector policy to the concurrent (low pause time) garbage collector (also known as CMS) |
-XX:+CMSIncrementalMode | Enables the incremental mode. (works only with -XX:+UseConcMarkSweepGC) |
-XX:+CMSIncrementalPacing | Enables automatic adjustment of the incremental mode duty cycle based on statistics collected while the JVM is running |
-XX:CMSIncrementalDutyCycleMin | The percentage (0-100) which is the lower bound on the duty cycle when CMSIncrementalPacing is enabled |
-XX:CMSIncrementalDutyCycle | The percentage (0-100) of time between minor collections that the concurrent collector is allowed to run. If CMSIncrementalPacing is enabled, then this is just the initial value. |
-XX:ParallelGCThreads | Sets the number of garbage collector threads |
-XX:+UseParNewGC | Enables multi threaded young generation collection. |
-XX:MaxGCPauseMillis | A hint to the throughput collector that it’s desirable that the maximum pause time is lowed than the given value. (n.b. it looks like this value can also be used with the CMS garbage collector) |
-XX:GCTimeRatio | A hint to the virtual machine that it’s desirable that not more than 1 / (1 + GCTimeRation) of the application execution time be spent in the collector |
-XX:+DisableExplicitGC | Disables explicit garbage collection calls (System.gc() ) |
There is no need to learn all these flags by heart as you can find them covered in various documents:
If you still need help you can try asking for help on the General Performance Forum.