Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 931
Bobby Avatar asked May 03 '16 15:05

Bobby


People also ask

How much memory should I allocate to JVM?

Therefore we recommended that physical memory availability for each JVM be 4096 MB;0.5 GB is for JVM allocation and 512 MB is for overhead. This simplified calculation means that a 64-bit system with 16 GB physical memory can run 3 JVMs.

What is Gc allocation rate?

GC Tuning: In Practice Allocation rate is a term used when communicating the amount of memory allocated per time unit. Often it is expressed in MB/sec, but you can use PB/year if you feel like it.

How do you set the maximum and minimum value of JVM memory?

use the arguments -Xms<memory> -Xmx<memory> . Use M or G after the numbers for indicating Megs and Gigs of bytes respectively. -Xms indicates the minimum and -Xmx the maximum. you may want to look at MaxPermSize as well.


1 Answers

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.

like image 112
Peter Lawrey Avatar answered Sep 17 '22 13:09

Peter Lawrey