Q. "How do I increase the memory that my Java Virtual Machine in Tomcat can use?"
A question asked - not for the first time - by a delegate on todays's Deploying Apache httpd and Tomcat
A. Set the JAVA_OPTS environment variable
. Longer answer:
If you're running on a Unix or Linux system, edit the setenv.sh file in Tomcat's bin directory to add in a line like:
export JAVA_OPTS="-Xms128m -Xmx512m"
or on a Windows system, add in to setenv.bat something like:
set JAVA_OPTS=-Xms128 -Xmx512
and restart the Tomcat server.
By default (out of the tar), Tomcat starts up with just 64 Mbytes allocated to the JVM, and that's also it's maximum. This is a very low figure, but it's a sensible default for a new install where the person setting the system up isn't into the tuning of the system.
The two extra parameters specified via JAVA_OPTS are as follows:
-Xms - the amount of memory that the JVM starts with.
-Xmx - the maximum memory that the JVM may have.
I have seen advise (but have no proof) that your should keep the -Xms figure rather lower than the -Xmx figure, since Tomcat uses more memory at startup than when it's running. The result (if you have them set to the same value) is a peak and unnecessary memory demand at startup which in an extreme case can cause a failure.
A couple of other tips:
a) You should consider using the -server
option too to run your JVM in server rather than (default) client mode (actually, they're two different but related VMs). The server that's selected with -server
is slower to load but is said to run faster.
b) We have customers who run multiple instances of Tomcat on the same box (but on different ports) - not a bad idea if you're sharing load between multiple processors. You can front them with httpd using mod-proxy-balance or mod-jk to distribute the requests, but at the same time to provide "sticky sessions" so that a series of requests made by an individual user will all be handled by the same instance. (written 2008-07-24, updated 2008-07-25)
Associated topics are indexed underA506 - Web Application Deployment - Java - Installing and Deploying optional Technologies 
Gathering information - logging - with log4j. First steps. - (2010-11-12) 
Jmeter - a first test case - (2009-03-14) 
Connecting jconsole remotely - the principles - (2009-03-14) 
Java - Memory Allocation and garbage collection - (2009-03-14)A912 - Web Application Deployment - Upgrading and tuning Tomcat 
Tuning Apache httpd and Tomcat to work well together - (2010-10-27) 
Database connection Pooling, SSL, and command line deployment - httpd and Tomcat - (2009-03-01) 
Java CLASSPATH explained - (2008-11-26) 
Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)A656 - Web Application Deployment - More Tomcat Configuration 
Monitoring and loading tools for testing Apache Tomcat - (2009-07-07) 
Virtual Hosting under Tomcat - an example - (2008-11-22) 
Apache Tomcat Performance Tuning - (2007-09-29) 
Separating 'per instance' data from binaries and web sites - (2005-10-16) 
Short weekend - (2005-04-17)A692 - Web Application Deployment - Monitoring and load testing your server 
Server logs - drawing a graph of gathered data - (2010-11-03) 
Apache httpd Server Status - monitoring your server - (2010-10-28) 
Logging the performance of the Apache httpd web server - (2010-10-25) 
Using ApacheBench and jconsole to test and monitor Tomcat - (2009-03-14)A901 - Replaced Page
Some other Articles
PHP examples - source code and try it out tooPerl 6 - When will we have a production release?Some Ruby lesser used functionsA special day - last Friday in JulyIncreasing Java Virtual Machine memory for TomcatQ - Should I use Perl or Python?Larger applications in PHPPictures from South HampshireHillier Gardens, HampshireWays to accept credit cards - or not!