JVM Tuning & GC

1. Garbage Collection Algorithms Comparison

Collector JVM Flags Target Pause Latency Recommended Heap Range Ideal Workload
G1GC (Default) -XX:+UseG1GC 50ms – 200ms 2 GB – 32 GB+ Standard enterprise web apps, balanced throughput & latency.
Generational ZGC -XX:+UseZGC -XX:+ZGenerational (JDK 21+) < 1ms (Sub-millisecond) 8 GB – 1024 GB Ultra-low latency financial, gaming, real-time trading APIs.
ParallelGC -XX:+UseParallelGC Stop-The-World (Seconds) 512 MB – 8 GB Batch computation, offline ETL processing, memory constrained hosts.

2. Tomcat Connector & Thread Pool Architecture (conf/server.xml)

Tuning the HTTP/1.1 and HTTP/2 NIO connector thread pool prevents thread exhaustion and request starvation:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
           connectionTimeout="20000"
           maxThreads="300"
           minSpareThreads="50"
           acceptCount="100"
           maxConnections="8192"
           enableLookups="false"
           compression="on"
           compressionMinSize="2048"
           compressableMimeType="text/html,text/xml,text/plain,text/css,application/json,application/javascript" />
  • maxThreads: Maximum concurrent request processing threads (default 200). Rule of thumb: 1.5 × Peak Concurrent Active Requests.
  • minSpareThreads: Pool of warm standby threads created on boot.
  • acceptCount: Operating system TCP backlog queue when all worker threads are occupied.
  • maxConnections: Maximum open TCP keepalive connections handled asynchronously via epoll/kqueue.