0

I'am using Tomcat 8.0.x with CentOS 7.3. I'am using systemd to launch Tomcat, here is the Unit File :

# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/tomcat-instances/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/tomcat-engine
Environment=CATALINA_BASE=/opt/tomcat/tomcat-instances/
Environment='CATALINA_OPTS=-Xms128M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/tomcat-instances/bin/startup.sh
ExecStop=/opt/tomcat/tomcat-instances/bin/shutdown.sh
#ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

We can see "Xms128M and -Xmx1024m"

In the setenv.sh file we have this :

export JAVA_OPTS="-Xms256m -Xmx2048m"

So when I do a "ps -ef | grep tomcat" :

tomcat   14051     1  2 09:06 ?        00:00:50 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat-instances/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms256m -Xmx2048m -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Xms128M -Xmx1024M -server -XX:+UseParallelGC -Djava.endorsed.dirs=/opt/tomcat/tomcat-engine/endorsed -classpath /opt/tomcat/tomcat-engine/bin/bootstrap.jar:/opt/tomcat/tomcat-engine/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat-instances/ -Dcatalina.home=/opt/tomcat/tomcat-engine -Djava.io.tmpdir=/opt/tomcat/tomcat-instances/temp org.apache.catalina.startup.Bootstrap start

We can see both value : "-Xms256m -Xmx2048m" and "-Xms128M -Xmx1024M"

Which parameter is use by Tomcat ? Unit File or setenv.sh ? What is the best practices to configure Xmx ?

Thank you,

Djé Djé
  • 13
  • 3
  • 7

1 Answers1

0

On the command line, the last Xmx wins, in your case, the Tomcat process uses the systemd values.

There is no "best practice" for setting the Xmx and Xms values. There are best practices for tuning the JVM, of which setting up the correct memory values is part of. However, for these to make sense, you must know what kind of applications will be deployed to the server.

Lacek
  • 7,233
  • 24
  • 28
  • Thanks Lacek, now I know that it's the latest Xmx who win ! Yeah I know that, it's the most difficult part to setting correct memory value... – Djé Djé Jul 06 '17 at 10:51