Performance Tuning
Harry
· 12 Sep 2026
· 11 views
JVM Memory
Set heap sizes in bin/setenv.sh (create it if missing):
JAVA_OPTS="-Xms1g -Xmx2g -XX:MaxMetaspaceSize=512m -XX:+UseG1GC"
export JAVA_OPTSDo not set Xmx higher than free RAM; the JVM and the OS need headroom. Tune with -Xss1m only if you see StackOverflowError.
Connector Threads
<Connector port="8080" protocol="HTTP/1.1" maxThreads="200"
minSpareThreads="25" acceptCount="100" connectionTimeout="20000"/>- maxThreads - do not set blindly high; each thread costs memory. 200 is a sane start.
- acceptCount - how many connections queue before refusing.
- Blocking DB calls per thread: pool accordingly, add secondaries for reads.
Compression
<Connector ... compression="on" compressionMinSize="2048"
compressibleMimeType="text/html,text/xml,text/css,text/javascript,application/json"/>Gzip/br text output reduces payloads by 60-80%. Enable for JSON and HTML APIs.
Static Content
- Serve static files from a CDN or nginx - Tomcat is a servlet engine, not a static server.
- Set cache headers / far-future-expiry on immutable assets (images, css, js) via filter or nginx.
Warm Up and Monitor
- JIT warm-up: hit the app with synthetic traffic after restart.
- Measure, change one thing, measure again (heap, GC logs, thread usage).
Key Points
- RAM > thread count; profile before raising limits.
- Compression and caching win more than connector tweaks usually.
- Always keep a test: benchmarking before and after.