Search code examples
javaperformancegarbage-collectionjvmdynatrace

Tuning JVM for High Allocation Rate


I'm trying to tune my application mainly to reduce the "spread" of response times. The average is fine, but the range is too wide.

Dynatrace showed that the higher response times are associated with a larger amount of time spent in suspension. This points to GC.

I've tried changing some JVM GC values based on reading online, to little success.

Based on GC logs I've figured the Allocation Rate to be about 324 MB/s, and the Promotion Rate to be only 0.85 MB/s. To me this seems that it has a very high allocation rate, so I've tried to increase the size of the Young Generation.

The first screenshot is with default Java 8 settings, 1024MB Xmx.

The second screenshot is setting NewRatio=1.

Any suggestions on what to try next would be really appreciated.

Things I've already tried: changing to G1GC, setting NewRatio=1, setting NewRatio=1 and increasing Xmx to 2048, setting NewSize=1600m and Xmx=2048, setting MetaspaceSize=100

Edit: Adding GC logs: http://pastebin.com/VhJwSuxv

Note: These logs are from the 10min test with the change: NewRatio=1

enter image description here enter image description here


Solution

  • Before tuning the GC, you should use a memory profiler to try to reduce the allocation rate in the first place.

    You can try increasing the young generation further, e.g. you can set -Xmn2g -Xmx3g and not set the NewRatio.

    I've figured the Allocation Rate to be about 324 MB/s,

    This is moderate rate for a web application. It could be lower but I wouldn't expect significant problems at this level.

    I would start with a much larger heap depending on how memory your machine has e.g. -Xmn24g -Xmx32g and look at the pause times. Then reduce the heap size until it appears to be impacting the GC times (they might even get shorter).

    Another way to look at it; You might find it is acceptable to have a minor GC every 2 to 10 seconds. This means you want an Eden space of 650 MB to 3.2 GB.