Memory Settings for Tomcat
By default, Tomcat sets its own memory size at around 64MB which by far this is not enough for web applications. You can set the "start size", the "maximum size" and you also need to up the heap space. to find out the proper values for your platform you will need to issue the command "java -X" in the terminal.
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
Once you know your parameters you should allocate about 60% of your available Ram to Tomcat.
Linux
To set the memory you should have a file called "setenv.sh" in your /tomcat/bin directory. If the file does not exsist you should create it. Within the file set the parameters like;
export JAVA_OPTS="-Xms256m -Xmx512m"
|
Then restart Tomcat to apply the new settings.
Windows (started manually)
To set the memory you should have a file called "setenv.bat" in your /tomcat/bin directory. If the file does not exsist you should create it. Within the file set the parameters like;
set JAVA_OPTS="-Xms256m -Xmx512m"
|
Then restart Tomcat to apply the new settings.
Permanent Memory Generation
In some cases the server can run out of a different type of memory (Permanent Generation), and if this is the case the above settings may not help solve the memory issue. A problem like this may occur when running multiple applications on the same server.
If you are experiencing this type of error, you would most likely see the following error in your logs:
java.lang.OutOfMemoryError: PermGen space |
To increase the level of this memory another java parameter will need to be added:
-XX:MaxPermSize=128m |
Linux
As explained above all these settings take place in the setenv.sh. Add the following now;
export JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=128m"
|
Windows (started manually)
As explained above all these settings take place in the setenv.bat. Add the following now;
set JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=128m"
|
Reference URL:
If
the JVM is using an excessive amount of memory, or spending too much time
performing garbage collection, try adding this argument to get more specific
information:
-verbose:gc
With
this argument, the JVM periodically generates output telling you how large the
Java heap size is and how much time is being spent in
garbage collection.
-Xloggc:<filename>
|
Log
GC verbose output to specified file. The verbose output is controlled by the
normal verbose GC flags.
|
-XX:-UseGCLogFileRotation
|
Enabled
GC log rotation, requires -Xloggc.
|
-XX:NumberOfGClogFiles=1
|
Set
the number of files to use when rotating logs, must be >= 1. The rotated log
files will use the following naming scheme, <filename>.0,
<filename>.1, ...,
<filename>.n-1.
|
-XX:GCLogFileSize=8K
|
The
size of the log file at which point the log will be rotated, must be >=
8K.
|
XX:ParallelGCThreads=n
|
Sets
the number of garbage collection threads in the young and old parallel garbage
collectors. The default value varies with the platform on which the JVM is
running.
|
-XX:-PrintGC
|
Print
messages at garbage collection. Manageable.
|
-XX:-PrintGCDetails
|
Print
more details at garbage collection.Manageable.
(Introduced in 1.4.0.)
|
-XX:-PrintGCTimeStamps
|
Print
timestamps at garbage collection. Manageable(Introduced
in 1.4.0.)
|
-XX:-PrintConcurrentLocks
|
Print
java.util.concurrent locks in Ctrl-Break thread
dump. Manageable.
(Introduced in 6.) The jstack
-lcommand
provides equivalent functionality.
|
0 comments:
Post a Comment