mercoledì 16 febbraio 2011

How to increase heap size in Tomcat 6

Most of us who have worked with Apache-Tomcat in productions systems, would have faced out of memory errors sometimes or other.  It is not that it always happens in tomcat but let us look at why does this occur and how to solve it.

 

Understanding Java Virtual Machine 

A Java Virtual Machine on 32-bit operating systems typically has a maximum heap size of 64Mb. The JVM heap space is where all Java objects are stored, as well as memory used by the garbage collector. Sun recommends increasing this value for server applications.

Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications.
64MB  is the heap size in tomcat as well by default and is too less for real world systems. When your application runs and you are able to analyze the app, this is what you would see

heap size in tomcat
heap size in tomcat 

How to increase the heap size?

On windows :

Go to catalina.bat and set this
set JAVA_OPTS=-Xms128m -Xmx192m

On linux :

export CATALINA_OPTS="-Xms16m -Xmx256m";

-Xms – is the minimum or initial size of your heap
-Xmx – is the maximim size

export JAVA_OPTS="-Xms128m -Xmx256m";

On linux , you can also set in setenv.shin the bin folder. The catalina.sh script has logic to call into this script.

Note that CATALINA_OPTS is a better place than JAVA_OPTS. The former is only used when actually starting the Tomcat instance. JAVA_OPTS is also used to start JVMs that only interact with Tomcat (for example the JVM instance that is used to send the shutdown-message to a running Tomcat instance).

You can have a look at this article High Performance in Tomcat. Although this article is pretty old (dates back to Tomcat 4) , it still has lot of good points.
Once you have set the heap , how to check heap size ?

How to check heap size in linux

The output of jmap -heap <pid>.
Some more information can be found here http://wiki.apache.org/tomcat/OutOfMemory

21 commenti:

  1. Hi,

    Great post. I wanted to add that in Ubuntu you can change the heap size by modifying /etc/default/tomcat6. In this file you will find the JAVA_OPTS variable.

    RispondiElimina
  2. Grazie diego and thanks Jose.

    RispondiElimina
  3. Very nice article, was looking to increase heap size in tomcat 6, thanks

    RispondiElimina
  4. Thanks for the nice blog. It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for,Thanks for sharing the such information with us......... by OPS 571 Final Exam provider.

    RispondiElimina
  5. Really impressive post and i learn more useful things from this
    Thanks and keep sharing..by ETH 316 Final provider

    RispondiElimina
  6. Great content i would be glad if you still post these type of Articles so that i can gain lot of information.For more information please go through
    MGT 498 Week 4

    RispondiElimina
  7. Thanks for the nice blog. It was actual advantageous for me. Keep administration such account in the approaching as well. This was absolutely what I was attractive for,Thanks for administration the such advice with us.
    by ETH 316 Final provider



    RispondiElimina
  8. I would prefer to categorical feeling you for the efforts you have got created in distributing this. i'm hoping an equivalent best work from you within the future.by LDR 531 Week 3 Assignment

    RispondiElimina
  9. I am very happy when read this blog post because blog post written in good manner and write on good topic. Thanks for sharing valuable information…....
    by ETH 316 Week 2 Team Assignment provider



    RispondiElimina
  10. Your post really helped me to understand this. It has great details and yet it is easy to understand.That's what i was looking for. I will definitely share it with others.Thanks for sharing..by ETH 316 Week 3 Team Assignment provider

    RispondiElimina
  11. I show up record it. I ache for to catch included this topic…i am respecting the time and fulfillment you put in your site, by ETH 316 Week 4 Team Assignment provider

    RispondiElimina
  12. I actualization up annual it. I affliction for to bolt included this topic…i am applicable the time and ability you put in your site,by MGT 521 provider




    RispondiElimina
  13. I am actual blessed back apprehend this blog column because blog column accounting in acceptable address and address on acceptable topic. Thanks for administration admired information…....by
    MGT 420 Week 2 provider.

    RispondiElimina
  14. Pretty interesting info is visible in this blog and the very good articles are display in this blog. This info is very helpful for me with my project time and thanks you very much for using the valuable info in this blog........ by ECO 365 Final Exam provider.

    RispondiElimina
  15. I would adopt to absolute activity you for the efforts you accept got created in distributing this. i'm acquisitive an agnate best assignment from you aural the future.by
    MGT 420 provider.

    RispondiElimina
  16. Thank you so much for providing this valuable information. It is very important to us. You Posted a Good Stuff... by MGT 521 Entire Course provider

    RispondiElimina
  17. hey thanks for sharing, am just struggled to overcome, but now am clear by refering your article metal planters

    RispondiElimina
  18. Increasing heap size in tomcat v6 is quit confusing in my Apache tomcat online training but with your post I handled it smooth.Thank you sir.

    RispondiElimina