Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce heap usage impact from VisualVM?

I'm trying to optimize the memory usage of my application. Unfortunately, running my application with -Dcom.sun.management.jmxremote and connecting it via VisualVM has quite a big impact on the heap usage. At first I thought that it is my application problem, until I wrote a very simple program to confirm that it is indeed the JMX's overhead. Below is the image of the activity.

After reading this, I come to understand that this is due to the way VisualVM retrieves the data, which is by polling the connected application continuously. I confirmed this by looking at the VisualVM's memory sampler. The RMI TCP Connection(n) thread is allocating 180kb / second.

My question is, is there a way to reduce the heap usage impact of VisualVM? Changing the polling interval might not be preferable as I'm interested with the heap information. If this is not possible, can we exclude the data used for VisualVM? At least I want to be more focus on my application.

Running Code

Object object = new Object();
synchronized (object) {
    object.wait();
}

VisualVM's Heap Monitor activity

enter image description here

like image 418
ceilfors Avatar asked Jun 10 '13 16:06

ceilfors


People also ask

How do you reduce heap?

You cannot reduce the heap size beyond a point; the heap should be large enough for all objects that are live at the same time. Preferably, the heap must be at least twice the size of the total amount of live objects, or large enough so that the JVM spends less time garbage collecting the heap than running Java code.

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.

What do you do when your heap memory is full?

The Heap and the Nursery When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.


1 Answers

The simplest thing to do is to reduce the polling interval. The impact is proportional to the rate to get data.

What I do is use YourKit which does everything in native memory so has no impact on the heap.

like image 144
Peter Lawrey Avatar answered Oct 05 '22 13:10

Peter Lawrey