Tomcat/Java java.lang.outofmemory error problem

For about the last 12 months my companies website has been randomly having out of memory errors. We have been completely lost as to why this is happening.

The problem seems to be this. Our website uses sessions to track users. Each session consumes about 30k of memory. Since we have set our session timeout to 180 minutes or 3 hours these sessions remain in memory until then. The other day my boss was running a custom script that analyzes webpages and coincidentally about 11,000 urls relating to pages on our website were being hit. One at a time but thousands per hour. Apparently the default settings of Tomcat allocate 16 megs up to 64 megs of memory. Tomcat would make it for ~25 minutes before crashing with a java.lang.outofmemory error.

I went and looked on Google for any solutions for months, then this week I finally stumbled upon an article that sounded similar to our problem. You can tell Tomcat to start up with Java using a minimum and a maximum amount of memory.

In conclusion we have now fixed our server crashing problem by adding these lines to a batch file that creates the windows service. When Tomcat starts up it allocates itself much more ram than before.

%CATALINA_HOME%\bin\tomcat -install “Jakarta Tomcat 4” %JAVA_HOME%\jre\bin\server\jvm.dll -Djava.class.path=%CATALINA_HOME%\bin\bootstrap.jar;%JAVA_HOME%\lib\tools.jar -Dcatalina.home=%CATALINA_HOME% %CATALINA_OPTS% -Xrs -Xms1024m -Xmx1536m -start org.apache.catalina.startup.Bootstrap -params start -stop org.apache.catalina.startup.Bootstrap -params stop -out e:\logs\tomcat\stdout.log -err e:\logs\tomcat\stderr.log

* Note the use of the -Xms—-m and -Xmx—-m switches.

We run Tomcat 4.1.30 on Windows 2000 servers with 2G of Ram and 2G of Virtual Ram

Leave a Reply

Your email address will not be published.

*