• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Question regarding memory usage of Java Application

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic