Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat - How to limit the maximum memory Tomcat will use

Tags:

I am running Tomcat on a small VPS (256MB/512MB) and I want to explicitly limit the amount of memory Tomcat uses.

I understand that I can configure this somehow by passing in the java maximum heap and initial heap size arguments;

-Xmx256m -Xms128m 

But I can't find where to put this in the configuration of Tomcat 6 on Ubuntu.

Thanks in advance,

Gav

like image 302
gav Avatar asked Apr 27 '10 20:04

gav


People also ask

How much memory should I allocate to Tomcat?

In general, a minimal install requires 4GB for the OS, the tomcat heap XMS setting (default 4GB), 2GB for Retain and any memory the database requires if installed. In all cases, when only the worker is installed the memory is automatically tuned to 3GB.

What is maximum memory pool in Tomcat?

(X denotes the Tomcat version number) Click the Java tab. Enter the following recommended values: Initial memory pool — 1024 MB. Maximum memory pool — 1024 MB.

How much memory is my Tomcat using?

Heap size used by tomcat (as any other java app) is determined by jvm -Xmx param. So if your tomcat runs as a windows service, you would create environment variable CATALINA_OPTS=-Xms64m -Xmx256m. Then, look at the file tomcat-install/bin/catalina.sh (.

What is XMS and XMX in Tomcat?

-xmx and -xms are the parameters used to adjust the heap size. -Xms: It is used for setting the initial and minimum heap size. It is recommended to set the minimum heap size equivalent to the maximum heap size in order to minimize the garbage collection. -Xmx: It is used for setting the maximum heap size.


2 Answers

On Ubuntu, the correct way to customize Tomcat variables is by editing the file

/etc/default/tomcat5.5 

(or /etc/default/tomcat6 if you have a newer version running)

Inside that file, set the JAVA_OPTS variable as described in the other replies here, for example

JAVA_OPTS="-Xmx512m"

to set a maximum memory of 512 MB.

like image 129
Photodeus Avatar answered Oct 10 '22 03:10

Photodeus


Set JAVA_OPTS in your init script,

 export JAVA_OPTS="-Djava.awt.headless=true -server -Xms48m -Xmx1024M -XX:MaxPermSize=512m" 
like image 29
stacker Avatar answered Oct 10 '22 04:10

stacker