Boost Tomcat Performance: Essential JVM and Connector Tuning Tips

This guide explains why Tomcat’s default settings are unsuitable for production, then walks through JVM memory tuning, thread‑pool adjustments, connector optimizations, and security hardening to dramatically improve stability and throughput on various server configurations.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Tomcat Performance: Essential JVM and Connector Tuning Tips

Introduction

Tomcat is a lightweight open‑source web server widely used for development and debugging of Servlet/JSP applications, but its default parameters are tuned for development rather than production, often causing performance bottlenecks.

Setting Tomcat Variables

vim bin/catalina.sh
JAVA_HOME=/usr/program/jdk1.8.0_72
CATALINA_HOME=/usr/program/tomcat8
CATALINA_OPTS="-server -Xms528m -Xmx528m -XX:PermSize=256m -XX:MaxPermSize=358m"
CATALINA_PID=$CATALINA_HOME/catalina.pid

JVM Optimization

The Java memory model is divided into Young, Tenured, and Perm generations. Proper sizing of these areas prevents frequent garbage collection pauses and OutOfMemoryError issues.

Memory Settings for Different Server Sizes

Example JAVA_OPTS for various RAM configurations:

# 8 GB RAM
JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms6144m -Xmx6144m -XX:NewSize=1024m -XX:MaxNewSize=2048m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=10 -XX:NewRatio=2 -XX:+DisableExplicitGC"

# 16 GB RAM
JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms13312m -Xmx13312m -XX:NewSize=3072m -XX:MaxNewSize=4096m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=10 -XX:NewRatio=2 -XX:+DisableExplicitGC"

# 32 GB RAM
JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms29696m -Xmx29696m -XX:NewSize=6144m -XX:MaxNewSize=9216m -XX:PermSize=1024m -XX:MaxPermSize=1024m -XX:MaxTenuringThreshold=10 -XX:NewRatio=2 -XX:+DisableExplicitGC"

# Development machine
JAVA_OPTS="-Xms550m -Xmx1250m -XX:PermSize=550m -XX:MaxPermSize=1250m"

Parameter Explanations

-Dfile.encoding   : default file encoding
-server            : server‑optimized JVM mode
-Xms / -Xmx        : initial and maximum heap size
-XX:NewSize        : young generation size
-XX:MaxNewSize    : maximum young generation size
-XX:PermSize / -XX:MaxPermSize : permanent generation size
-XX:NewRatio=2    : ratio of young to old generation (1:2)
-XX:MaxTenuringThreshold=10 : max age before promotion
-XX:+DisableExplicitGC : ignore explicit System.gc() calls

Editing Configuration Files

vim conf/server.xml

Disable Shutdown Port 8005

# Default
<Server port="8005" shutdown="SHUTDOWN"/>
# Modified
<Server port="-1" shutdown="SHUTDOWN"/>

Application Security & Disable Auto‑Deploy

# Default
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
# Modified
<Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="false" reloadable="false"/>

Thread Pool Tuning (maxThreads)

# Modified
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="500" minSpareThreads="100" maxIdleTime="60000" prestartminSpareThreads="true" maxQueueSize="100"/>

Key parameters:

maxThreads          : maximum concurrent threads (suggest 500‑800)
minSpareThreads     : threads created at startup
maxIdleTime         : idle thread timeout (ms)
prestartminSpareThreads : pre‑initialize minSpareThreads
maxQueueSize        : maximum request queue length

Connector Parameter Optimization

# Default
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
# Modified
<Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="40000" maxConnections="10000" redirectPort="8443" enableLookups="false" acceptCount="100" maxPostSize="10485760" compression="on" disableUploadTimeout="true" compressionMinSize="2048" acceptorThreadCount="2" compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript" maxHttpHeaderSize="8192" processorCache="20000" tcpNoDelay="true" connectionLinger="5" server="Server Version 11.0" URIEncoding="utf-8"/>

Important connector options include protocol selection (NIO/NIO2), disabling DNS lookups, request queue size, POST size limit, GZIP compression, thread counts, and hiding server version.

Disable AJP (if Apache not used)

# Comment out
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> -->

Hide or Modify Tomcat Version

# Edit ServerInfo.properties
server.info=Apache Tomcat/8.5.16
server.number=8.5.16.0
server.built=Jun 21 2017 17:01:09 UTC

Remove Default Management Apps

# Delete webapps and users file
rm -rf /usr/local/apache-tomcat-8.5.16/webapps/*
rm -rf /usr/local/apache-tomcat-8.5.16/conf/tomcat-users.xml
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javaperformancejvm-tuningTomcatserver optimization
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.