Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does heap memory usage graph look like this?

Tags:

java

apm

I have install glowroot (java application monitoring) to my JVM. When my application idles, I get this kind graph formation of memory heap usage. The pattern seems almost uniform. Could someone please explain and point me to whatever blog post on why does the graph looks like that? I am curious.

enter image description here

like image 374
snso Avatar asked Dec 12 '17 06:12

snso


People also ask

What causes high heap memory usage?

High heap usage occurs when the garbage collection process cannot keep up. An indicator of high heap usage is when the garbage collection is incapable of reducing the heap usage to around 30%. In the image above you can see normal sawtooth of JVM heap.

How do you analyze heap memory?

We will first start the Memory Analyzer Tool and open the heap dump file. In Eclipse MAT, two types of object sizes are reported: Shallow heap size: The shallow heap of an object is its size in the memory. Retained heap size: Retained heap is the amount of memory that will be freed when an object is garbage collected.

What is memory heap usage?

Heap space is used for the dynamic memory allocation of Java objects and JRE classes at runtime. New objects are always created in heap space, and the references to these objects are stored in stack memory. These objects have global access and we can access them from anywhere in the application.

How do I monitor heap usage?

The easy way to monitor Heap usage is by using a commercial APM (Application Performance management tool) such as CA Wily APM, AppDynamics, New Relic, Riverbed, etc. APM tools not only monitor the heap usage, but you can also configure the tool to Alert you when Heap usage is not normal.


2 Answers

The large-scale sawtooth pattern represents the memory utilization between GC cycles. The application is allocating objects steadily (the upsloping line) until the heap gets full enough for the VM to decide to run the GC (the point). Then the GC reclaims a large amount of garbage (the steep drop) and the process starts again.

The short spikes up and down are harder to understand. It is possible that the upward spikes represent anomalous "large" allocations (of short life-time objects) that are triggering a young generation cycle. The downward spikes might represent cached objects being freed in response to "memory pressure".

If you want a better understanding of the spikes, you need to look at the GC log messages, and try to correlate them with the graphs.

like image 178
Stephen C Avatar answered Nov 10 '22 09:11

Stephen C


It looks like that because (at the least) you're observing it. If your application did absolutely nothing, and there were no threads doing any allocations, you'd get a horizontal line for the heap.

However since you're observing it, there are things being done in the JVM to get that data back to you. That's why you get the ubiquitous sawtooth pattern seen in many, many profiling questions. A few examples below.

java memory leak, visualvm showing wrong data

visualvm monitors memory usage

like image 34
Kayaman Avatar answered Nov 10 '22 10:11

Kayaman