aspose file tools*
The moose likes Performance and the fly likes Question regarding memory usage of Java Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Question regarding memory usage of Java Application" Watch "Question regarding memory usage of Java Application" New topic
Author

Question regarding memory usage of Java Application

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Hi,

I have a question regarding memory usage of java web applications..

In Task manager, Tomcat service seems to occupy 8,677,544,000 Bytes of memory

In jvisualvm, memory usage of the java application deployed under that Tomcat service is as follows

Heap
----
Used: 2,304,233,184 B
Size: 8,589,934,592 B
Max: 10,737,418,240 B

Permgen
-------
Used: 80,272,056 B
Size: 536,870,912 B
Max: 536,870,912 B


Memory Parameters which I have configured in Tomcat's Service.bat file:

-Xms8192m;-Xmx10240m;-XX:PermSize=512m;-XX:MaxPermSize=512m

Now, my question is no matter what I set MaxHeapFreeRatio the free space is not shrinking evenhough the used space is shrinking at times.

Can anyone, kindly tell me why is this behaving like this.. Is there a way to shrink the free space so that other processes runnning on the system can utilize it?

I am using latest versions of JDK 1.7 & Tomcat 7..

Thanks,
Vivek
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

the free space is not shrinking evenhough the used space is shrinking at times.


I'm not quite sure what you meant by this. Is your expectation that the native memory allocated to the JVM process will shrink based on this parameter (MaxHeapFreeRatio) ? That is not how it works. The JVM asks the OS to allocate some native memory and uses it to scale the heap. It is the heap that shrinks and grows and not the native memory itself. No matter what the value for MaxHeapFreeRatio, it will not release any native memory on the OS.

From the documentation for this VM option.

-XX:MaxHeapFreeRatio=70 Maximum percentage of heap free after GC to avoid shrinking.


If you want more breathing room for other processes on the OS, reduce the size of the Xmx parameter. This also effectively reduces your overall heap size.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Depending on the circumstances, the JVM can be configured to return the native memory to the OS. See this thread, especially the link Ulf has provided there, as I was initially mistaken about that too....
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Martin Vajsar wrote:Depending on the circumstances, the JVM can be configured to return the native memory to the OS. See this thread, especially the link Ulf has provided there, as I was initially mistaken about that too....


Thank you for correcting me. I did not know that the JVM releases memory back to the OS. knowledge++

Quoting stolsvik's comment from that thread


The default values are 70 and 40 respectively, which means that the JVM only
shrinks its memory use after 70% (!!!) of the heap is free, and it only shrinks
to the point that 40% of the heap is still free. A few numbers to put this
waste into perspective: If your JVM's heap grew to 300 MB, and now only
requires 100 MB, it will NOT shrink (because only 66% is free). If later
you need just 90 MB, the heap will finally shrink, but only to 150 MB (so
that 40% still remains free).


In the OP's case around 27% of the heap is used. Going by the default values of 70% / 40% the heap should have shrunk. I wonder if the value for Xms also affects the way this feature behaves. If the Xms requested is 8GB, it would go against the contract of that command line argument to reduce the heap any further than 8GB. I'd consider reducing that value to check if it helps. I have not seen any documentation to prove that the last statement will have any affect. Its just an intuition of mine.

As a side note, a large range between Xms and Xmx can lead to performance troubles since the JVM must continually allocate new space every time your application frees it and then needs it.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Deepak Bala wrote:I wonder if the value for Xms also affects the way this feature behaves.


It does. -Xms and -Xmx set hard lower and upper limits on heap size.

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Thank you all for your responses.. I did go through all your links and experimented with smaller xms & xmx values..I will get back and post here if I find more appropriate solution for releasing the unused (heap) memory..

Thanks,
Vivek..
 
wood burning stoves
 
subject: Question regarding memory usage of Java Application