Java heap keeps on shrinking! What is happening in this graph of heap size?

谁都会走 提交于 2021-02-04 15:49:39

问题


This is a screen shot of a JVM (win64, 6u17) running ActiveMQ, after every garbage collection the heap size is reducing. As the heap size reduces garbage collection gets more frequent and the heap reduces more quickly. Eventually the VM locks up as it's spending all it's time in GC.

-Xms is the default and -Xmx is 2048mb.

What is happening!!? How can I avoid this?

http://imagebin.org/92614

Shrinking heap http://imagebin.org/index.php?mode=image&id=92614

n.b originally posted on serverfault.com, moved to stackoverflow.com as requested


回答1:


Google found me the following, from the IBM JVM FAQ (how's that for an NLA):

When does the Java heap shrink?

Heap shrinkage occurs when GC determines that there is a lot of free heap storage, and releasing some heap memory is beneficial for system performance. Heap shrinkage occurs after GC, but when all the threads are still suspended.

The Sun JVM does something similar. Below is an excerpt from an Oracle Technology Network article entitled Ergonomics in the 5.0 Java Virtual Machine.

The heap will grow or shrink to a size that will support the chosen throughput goal. Some oscillations in the size of the heap during initialization and during a change in the application's behavior can be expected.

...

It is typical that the size of the heap will oscillate as the garbage collector tries to satisfy competing goals. This is true even if the application has reached a steady state. The pressure to achieve a throughput goal (which may require a larger heap) competes with the goals for a maximum pause time and a minimum footprint (which both may require a small heap).

I suggest you have a look at the rest of that document; it may have more information relevant to your problem.




回答2:


There is a JVM argument that controls when the heap is resized.

-XX:MaxHeapFreeRatio

The default value for this is 70. The free ratio is the amount of space not allocated on the heap over the total heap size. It the percentage of free space rises above the default of 70% the jvm will rreduce the size of the heap to allow the OS to use the memory.

If the heap is shrinking too often you can increase the value of -XX:MaxHeapFreeRatio. If it is set to 100 presumably it will never skrink.




回答3:


Just a guess: It looks like the system is pretty much idle. There might be some caching going on, and stuff drops out of the cache and gets gc'd. Or since it is a queuing system, maybe it has some messages, in the queue, which slowly get delivered and gc'd afterwards.

The increased frequence of gc-runs might be due to ever decreasing load on the system.

As to how to avoid it. Why do you want to avoid it? It seems like your CPU load is zero. So you are free to let the gc do whatever it wants



来源:https://stackoverflow.com/questions/2617159/java-heap-keeps-on-shrinking-what-is-happening-in-this-graph-of-heap-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!