Boost Tomcat Performance: Master BIO, NIO, and APR Modes with JVM Tuning
This guide explains Tomcat's three connector modes—BIO, NIO, and APR—shows how to install APR and native libraries, configure the server.xml protocol, and apply JVM and connector optimizations to dramatically improve concurrency and throughput.
Tomcat has three operating modes
BIO : the default mode, very low performance and not optimized.
NIO : uses Java's asynchronous (non‑blocking) I/O. To enable, edit the <Connector> node in server.xml and set protocol="org.apache.coyote.http11.Http11NioProtocol".
<Connector port="80"
protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
enableLookups="false"
redirectPort="8443">APR : solves asynchronous I/O at the OS level, greatly increasing performance. It requires installing APR and the Tomcat native library, then switching the protocol to org.apache.coyote.http11.Http11AprProtocol.
Install APR
yum -y install apr apr-develInstall native library
cd /usr/local/tomcat/bin/
tar xzfv tomcat-native.tar.gz
cd tomcat-native-1.1.20-src/jni/native/
./configure --with-apr=/usr/bin/apr-1-config
make
make installAfter installation you will see:
Libraries have been installed in:
/usr/local/apr/libAdd the library path to Tomcat: CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib" Change the connector protocol in conf/server.xml: protocol="org.apache.coyote.http11.Http11AprProtocol" When Tomcat starts, the log will contain:
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].Concurrency Optimizations
1. JVM tuning : add the following to catalina.sh (adjust values as needed):
JAVA_OPTS="-Xms1024m -Xmx1024m -Xss1024K -XX:PermSize=64m -XX:MaxPermSize=128m"Parameter meanings:
-Xms: initial heap size
-Xmx: maximum heap size
-Xss: thread stack size
-XX:PermSize / -XX:MaxPermSize: non‑heap memory for class metadata
Recommendations: set -Xms and -Xmx to the same value (60‑80% of physical RAM); thread stack size around 256K; adjust non‑heap size based on application.
Example for a 32 GB machine:
JAVA_OPTS="-Xms20480m -Xmx20480m -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=2048m"2. Disable DNS reverse lookup : add enableLookups="false" to the <Connector> element.
3. Optimize Tomcat connector parameters (using APR) :
<Connector port="8080"
protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443"
maxThreads="500"
minSpareThreads="20"
acceptCount="1000"
enableLookups="false"
URIEncoding="UTF-8" />Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
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.
