How to Optimize Tomcat for Production: JVM, Connector, and Security Settings
This guide explains why Tomcat's default development settings need tuning for production, covering JVM memory model basics, configuration file edits, thread pool and connector adjustments, as well as security hardening steps to improve performance and stability.
Introduction
Tomcat is an open‑source lightweight web application server widely used for development and debugging of Servlet/JSP programs. Its default parameters are tuned for development, not production, so memory and thread settings are often too low and become performance bottlenecks.
JVM Optimization
The Java memory model consists of the Young generation (Eden plus two equal‑sized Survivor spaces), the Tenured generation for long‑lived objects, and the Permanent generation (PermGen) that stores class metadata. Minor GC moves surviving objects between Survivor spaces, and after several collections they are promoted to Tenured. PermGen can cause OutOfMemoryError during frequent redeployments.
Edit Configuration Files
Modify
bin/catalina.shto set environment variables:
JAVA_HOME,
CATALINA_HOME,
CATALINA_OPTS, and
CATALINA_PID. Adjust
shutdown.shto replace the default stop command with
stop 10 -forcefor forced termination.
JVM Options for Different Memory Sizes
Example
JAVA_OPTSfor an 8 GB server:
-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. For 16 GB and 32 GB servers, increase
-Xms,
-Xmx,
-XX:NewSize, and
-XX:PermSizeaccordingly. Development machines can use smaller values such as
-Xms550m -Xmx1250m -XX:PermSize=550m -XX:MaxPermSize=1250m. Each flag controls initial and maximum heap size, new generation size, permanent generation size, tenuring threshold, and disables explicit GC calls.
Disable 8005 Shutdown Port
Change the default server entry from
<Server port="8005" shutdown="SHUTDOWN">to
<Server port="-1" shutdown="SHUTDOWN">to disable the remote shutdown function.
Application Security & Disable Auto‑Deployment
Set the
<Host>element to
unpackWARs="false" autoDeploy="false" reloadable="false"to prevent automatic unpacking and deployment of WAR files.
Increase Thread Pool
Replace the default executor configuration with higher limits:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="500" minSpareThreads="100" maxIdleTime="60000" prestartminSpareThreads="true" maxQueueSize="100" />. This raises the maximum concurrent threads and improves request handling capacity.
Connector Parameter Optimization
Switch to the NIO protocol:
protocol="org.apache.coyote.http11.Http11NioProtocol". Set larger values for
connectionTimeout(40000 ms),
maxConnections(10000), enable GZIP compression, disable DNS lookups, increase
maxPostSizeto 10485760, raise
acceptCountto 100, and adjust
maxHttpHeaderSizeto 8192. Additional parameters such as
acceptorThreadCount,
tcpNoDelay, and
serverhide version information.
Disable AJP
If Apache is not used, comment out the AJP connector line
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->.
Hide or Modify Tomcat Version
Unzip
catalina.jar, edit
org/apache/catalina/util/ServerInfo.properties, and change or remove entries such as
server.info,
server.number, and
server.builtto conceal version details.
Remove Default Manager Application
Delete all files under
/usr/local/apache-tomcat-8.5.16/webapps/*and remove
/usr/local/apache-tomcat-8.5.16/conf/tomcat-users.xmlto eliminate the default manager UI.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.