Tomcat 7: How to set initial heap size correctly?
Asked Answered
S

10

68

I was trying to adjust initial heap size of a tomcat 7 (CentOS, java -version: 1.6.0_25-b06) instance by adding the following line to catalina.sh:

export CATALINA_OPTS="-Xms=512M -Xmx=1024M"

Starting up tomcat fails and logs the following message to catalina.out:

Invalid initial heap size: -Xms=512m
Could not create the Java virtual machine.

What is wrong with these options?

Saintebeuve answered 1/8, 2011 at 11:1 Comment(1)
Do not edit catalina.sh. Please see the proper way of doing this described in this post: https://mcmap.net/q/219536/-can-39-t-change-tomcat-7-heap-sizeHeda
B
114

You must not use =. Simply use this:

export CATALINA_OPTS="-Xms512M -Xmx1024M"
Broome answered 1/8, 2011 at 11:3 Comment(1)
I created a file setenv.sh in the tomcat bin folder and added this line, and it worked!Patty
C
27

Use following command to increase java heap size for tomcat7 (linux distributions) correctly:

echo 'export CATALINA_OPTS="-Xms512M -Xmx1024M"' > /usr/share/tomcat7/bin/setenv.sh
Catcall answered 16/12, 2014 at 13:3 Comment(1)
If in Debian I do recommend I do recommend changing /etc/default/tomcat7 instead, rather than creating the setenv.sh file in the equivalent location. Is is a far less obscure location.Grayson
R
11

You might no need to having export, just add this line in catalina.sh :

CATALINA_OPTS="-Xms512M -Xmx1024M"
Recce answered 25/11, 2013 at 3:46 Comment(1)
NOT to catalina.sh! Put it inside /usr/share/tomcat7/bin/setenv.sh, that's the right place for it.Francis
A
5

Go to "Tomcat Directory"/bin directory

if Linux then create setenv.sh else if Windows then create setenv.bat

content of setenv.* file :

export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"

after this restart tomcat with new params.

explanation and full information is here

http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/

Alcaic answered 20/5, 2016 at 20:14 Comment(0)
I
3

setenv.sh is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. catalina.sh changes from one version of Tomcat to another. But you can keep your setenv.sh unchanged with any version of Tomcat.

Another advantage is, that it is easier to track the history of your changes if you add it to your backup or versioning system. If you look how you setenv.sh changes along the history, you will see only your own changes. Whereas if you use catalina.sh, you will always see not only your changes, but also changes that came with each newer version of the Tomcat.

Illuminism answered 1/2, 2015 at 0:59 Comment(0)
D
2

After spending good time time on this . I found this is the what the setenv.bat must look like . No " characters are accepted in batch file.

set CATALINA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=768m

echo hello "%CATALINA_OPTS%"

Decarburize answered 28/1, 2017 at 7:45 Comment(0)
O
1

Take care with change in Debian distributions! I tried to change CATALINA_OPTS in my Debian 7 and the results where that tomcat didn't start anymore. Thus I solved this issue by changing the property JAVA_OPTS in place of CATALINA_OPTS, like this

export JAVA_OPTS="-Xms512M -Xmx1024M"
Ohmage answered 20/5, 2015 at 2:29 Comment(0)
P
1

Just came across this and I've implemented Nathan's solution:

add the line (changing the values as required):

export JAVA_OPTS="-Xms512M -Xmx1024M"

to /usr/share/tomcat7/bin/setenv.sh

If that file doesn't exists then create it and

chown root:root it
chmod 755 it

And then restart tomcat and check it with

ps aux | grep logging

Which should just pick up the instance and show the java parms

Pneumo answered 21/1, 2016 at 12:0 Comment(0)
S
1

It works even without using 'export' keyword. This is what i have in my setenv.sh (/usr/share/tomcat7/bin/setenv.sh) and it works.

OS : 14.04.1-Ubuntu Server version: Apache Tomcat/7.0.52 (Ubuntu) Server built: Jun 30 2016 01:59:37 Server number: 7.0.52.0

JAVA_OPTS="-Dorg.apache.catalina.security.SecurityListener.UMASK=`umask` -server -Xms6G -Xmx6G -Xmn1400m -XX:HeapDumpPath=/Some/logs/ -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:+UseCompressedOops -Dcom.sun.management.jmxremote.port=8181 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -Dserver.name=$HOSTNAME"
Sicular answered 24/8, 2016 at 23:35 Comment(0)
T
0

If it's not work in your centos 7 machine "export CATALINA_OPTS="-Xms512M -Xmx1024M"" then you can change heap memory from vi /etc/systemd/system/tomcat.service file then this value shown in your tomcat by help of ps -ef|grep tomcat.

Taken answered 20/5, 2019 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.