Solved

Tomcat Memory Allocations

Posted on 2015-01-05
5
293 Views
Last Modified: 2015-01-06
I have a website running on Tomcat and I am trying to understand the memory allocation settings specifically the Java flags  -Xms & -Xms and the Tomcat --JvmMs, JvmMx memory pool allocations.

Now I have read through numerous sites including Oracle and Tomcat specifications and underrstand that these flags are used to set minimum and maximum memory poo sizes and that this relates to Garbage Collection but what this escapes me is what is the difference between these two groups of settings.

I have found with testing that setting --JvmMs & JvmMx to something really low (10m) causes Tomcat to crash during start up (no errors logged) and that setting -Xms & -Xms to 10m allows Tomcat to start but causes the site to timeout. Given this I suspect that these two sets memory allocation are controlling different aspects of the website.

Can anyone out there explain the what each of these two groups control in relation to each other.

I also find it strange that when running Tomcat in exe mode that --JvmMs and JvmMx are not used, so why are they needed for running as a service?
0
Comment
Question by:Michael74
  • 2
  • 2
5 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 40533304
Good start is to not tune anything and analyze OOMs - do you need more memory or you need to address resource leak.
0
 
LVL 27

Accepted Solution

by:
dpearson earned 500 total points
ID: 40534211
I think you'll find there's actually only 2 values in use here.

-Xms defines the initial Java heap size to use
-Xmx defines the maximum heap size it is allowed to use

These flags are generic to all Java programs, nothing specific about Tomcat and a Java process only ever has one heap with a specific maximum size.  These are set on the JVM (the Java Virtual Machine - the thing which runs Java apps) when it starts up.

These 2 other flags ( JvmMs & JvmMx) sound like a Tomcat specific way to go about configuring the real flags for the JVM.  You can see it in their names - they are intended to be passed to the JVM and set the Ms and Mx flags.

So I'd guess that the reason you're seeing setting some of these producing different behavior is that there's some level of overriding going on and sometimes the flags are set and clobbered by other values and sometimes not.

To see what's really going on, I'd suggest using "ps aux | grep java" to look at the running process and the command line actually used to launch it.

You should see something similar to this:

/usr/bin/java -Djava.util.logging.config.file=/var/local/tomcat/ow/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xmx3500M -Dcom.sun.management.jmxremote=true -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/var/local/tomcat/ow -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/var/local/tomcat/ow/temp org.apache.catalina.startup.Bootstrap start

which contains the actual params used - you can see here we have ours set to 3.5GB as max heap.

It should help you sort out what's happening.

Doug
0
 
LVL 23

Author Comment

by:Michael74
ID: 40534411
Hi Doug

Thank you, good answer.

Any chance you know the command I could use to get this information on Win2k8
0
 
LVL 27

Expert Comment

by:dpearson
ID: 40534523
I think you can see the command line params for a running Windows process by going to:

1) Task manager
2) Switch to process tab
3) Select "View | Select columns" from the menu
4) Choosing "Command line" in the list of options

Then just hunt for Tomcat by hand in the list of tasks :)

I trust that option is available in Win2K8.  I just checked and it worked for me on Windows 7.

Doug
0
 
LVL 62

Expert Comment

by:gheist
ID: 40534530
look into catalina.out file for OOM, and change parameters with tomcat service controller.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 40
Java exception bubble up 2 21
sql import cannot be resolved jsp 3 49
IBM TS2900 (3572) Tape Autoloader Java? 12 15
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question