6

I bought a virtual server with 1gb of memory to run java web site application. I have installed Tomcat 6.0.33 . Each time i run tomcat, it s taking around 450 mb of memory.

I tried everything to reduce that, i set up the CATALINA_OPS as

export CATALINA_OPTS="-Xms256m -Xmx256m"

I have created set setenv.sh file and u put in it :

JAVA_HOME="/usr/local/java"
export JAVA_HOME

JAVA_OPTS="-Xmx256m -Xms256m"
export JAVA_OPTS

CATALINA_HOME="/usr/local/tomcat"
export CATALINA_HOME

When i pass this command : ps -ef | grep tomcat i have :

root      3150     1  5 15:32 pts/0    00:00:18 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Xmx256m -Xms256m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms256m -Xmx256m -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      3217  2041  0 15:37 pts/0    00:00:00 grep tomcat

which shows me that my parameters are really used.

Is there any method to reduce the memory consumed by tomcat ? Thank you.

stunaz
  • 161
  • 1
  • 1
  • 3

1 Answers1

9

The issue here isn't really tomcat, it's java generally. There are a number of different places where java uses memory. The java runtime uses it's own memory and that's going to be included in your number, additionally, java breaks memory down into four distinct locations:

The Heap: This is the memory used to store your objects and is controlled by the -Xms and -Xmx parameters.

The Stack: This is the memory used to store the stack frames for the threads that your program maintains and can be controlled with the -Xss parameter.

Permgen Memory: This is the memory used to store your compiled classes and pooled strings as well as some other things and can usually be controlled with -XX:MaxPermSize although the -XX represents a debugging parameter, so there's no guarantee it's on all JVM's. But, the default Sun/Oracle reference implementations have always had them.

JNI Allocated Memory Any classes utilizing native methods and JNI could potentially allocate unlimited memory. This memory comes from the OS and not the heap and there's no way of knowing how much memory a native class will use without having access to the source.

An overview of the java memory model is probably beyond the scope of the answer to this question and I couldn't find a good concise article/description on the internet, but the short answer to your question is if you are trying to limit the absolute amount of memory used by a java program, there is no easy way to do it. Heuristically, probably cut your -Xms and -Xmx parameters to 128m and you should get close, but it's really going to depend on your application.

nickgrim
  • 4,336
  • 1
  • 17
  • 27
  • Thank you for your answer, i realized that it's still consuming that memory even if havo zero application deployed. Reaaly weird. –  Sep 18 '11 at 21:51
  • Yeah. Tomcat is a java application and it will use memory even if you don't have any other web applications. Addtionally, if you are using JNI for anything that could also consume memory. I edited the answer to reflect that. –  Sep 18 '11 at 21:59
  • "How to reduce Tomcat's memory usage?" -> Do not use Tomcat. – robert Sep 19 '11 at 12:20
  • hi, robert, what do you suggest? – stunaz Sep 19 '11 at 13:26