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

在这里输入图像描述


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.

链接地址: http://www.djcxy.com/p/14040.html

上一篇: maven:部署工件文件名

下一篇: 如何减少来自VisualVM的堆使用影响?