Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Ways to reduce memory footprint of JVM  RSS feed

 
Sandeep Deb
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there any way to reduce the memory footprint of a full blown JVM. I am trying to launch a Java application and keep it running for a long time and would love to make it lean in terms of footprint. I have tried to do some research, but unfortunately couldn't gather anything useful. It would be great if someone could share some pointers or experiences.

Regards,
Sandeep
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since so much of the memory footprint of a running jvm is due to loaded classes, it seems to me that the first line of defense would be using as few classes as possible.
JVMs for reallllly small environment that I have looked at have left out long and double math functions to reduce the core code.

Bill
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only ways I'm aware of is

a) reducing the amount of free heap space, for example using the following start up parameters:

-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20

This means that the JVM will keep the heap at a size so that 10-20% of the heap will be free. The default values are 40-70%. You might want to test the impact on the performance of the garbage collector when you do this.


b) reducing the size of the permanent generation

XX:MaxPermSize=...

Default is 64 MB - a too low value will lead to an OutOfMemoryError: permgen


c) reducing the size of the hot spot engine's code cache:

-Xmaxjitcodesize...

Default is 32 MB - a too low value will result in lost performance.


Since Java 5, you can use the JConsole to see how much of the available space is actually used by your application.
 
Sandeep Deb
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Ilja. I will check out your suggestions tomorrow and update the post with my findings. I went through the documentation of the options you have suggested and they look quite promising.

Thanks again,
- Sandeep
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
Since so much of the memory footprint of a running jvm is due to loaded classes, it seems to me that the first line of defense would be using as few classes as possible.


The effect of directly using one more class can vary greatly. If that class has no dependencies on other yet-unloaded classes, the effect will be small. If that class depends on whole frameworks that are not yet loaded, huge amounts of memory will be used. For instance, as soon as you use any Swing class, loads of other classes will get loaded.

There's an option on the JVM to report information about loaded classes. I forget what it is, but it could be very useful here - look it up.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!