Thursday 5 May 2011

Tomcat 7 Windows Service memory management - a correction

In an earlier post, I made a serious mistake, so this should go some way to correcting it.

First Hudson Run

My first run of Hudson on Tomcat 7 led to the infamous error :
FATAL: PermGen space java.lang.OutOfMemoryError: PermGen space
Not surprising, given the spec of the machine I'm using, but still a pain.
Using VisualVM, it shows the PermGen size to be still at the default 64MB size. Attempts to monitor the build process weren't successful as the entire machine ground to a halt.


Previously on Tomcat 5/6, I'd've set the catalina.bat or catalina.sh file to contain the memory management options, but this file doesn't exist in Tomcat 7. This was new to me.

Tomcat itself isn't helpful with Permgen, as although it's possible to find the inital and maximum heap memory size on the Manager App, Server Status tab, it doesn't show the permgen size.


There are some really good sites listing the mechanics of setting Tomcat's memory.
WEBMAP is for a Tomcat running on jdk 1.3, but the step by step process to figuring out which parameters are useful is useful.

CATALINA_OPTS vs JAVA_OPTs
I found some sites that suggested setting the OPTS as a Windows environment variable. Several blogs and sites suggest using JAVA_OPTS. I'd caution on this, as although others got it to work, JAVA_OPTS are used by other applications (JBoss in particular was mentioned), not just Tomcat. I decided to stick with CATALINA_OPTS.
But, when I tried setting the environment variable, and restarting Tomcat, I didn't see an increase in the Heap size. I'm not saying it doesn't work, but I couldn't get it to work. Combined with the fact that I didn't like the idea of doing it this way as it seems to be scattering the configuration across a number of places, I didn't really put any further effort into making this work.

Setting memory options on Tomcat

Remember -Xms and -Xmx only set the heap size. These are easy enough to set through the Monitor Tomcat GUI, on the Java tab as the Initial Memory Pool (equivalent to -Xms) and the Maximum Memory Pool (-Xmx).









To set the Permgen size, you need either -XX:PermSize=XXXm or -XX:MaxPermSize=XXXm, and see WEBMAP for a more detailed review of each of these. Again, this can be set on the Java tab of the Monitor Tomcat GUI, this time as a Java Option, I went for -XX:PermSize=128m.

The difference can be seen on the next screenshot, again of the MonitorVM application. Heap size has gone from 67MB to 134MB.


Effect of all of this ?

I now have a Hudson build that doesn't crash Tomcat either during or immediately after each run. Heap size during a build is about the 75MB mark. Maybe now I can start doing some coding ...

Useful references

In addition to those mentioned above, I found these two references from http://www.skill-guru.com to be useful :
Setting Heap Size
Setting Permgen Size

No comments:

Post a Comment