Tomcat NIO vs APR/native connector: when is native throughput worth the portability cost?
0 reputation · 17 Oct 2021, 22:50 UTC
0 reputation · 17 Oct 2021, 22:50 UTC
We run Tomcat on both Linux and Windows hosts and want to pick a single connector strategy for a high-traffic HTTP endpoint. The documentation describes NIO as the portable pure-Java default, while APR/native can use platform-native pollers and OpenSSL-style TLS integration but requires matching native libraries per OS and packaging.
Our constraint is maximizing sustained throughput without losing cross-platform deployability. We have not yet measured where our bottleneck actually sits — keep-alive handling, executor thread limits, TLS overhead, application latency, and the fronting reverse proxy could all dominate connector choice. We also know connector behavior is version-sensitive, so assumptions from older APR-based deployments may not hold on current Tomcat releases that emphasize NIO/NIO2.
Assume a recent Tomcat release with identical JDK, TLS settings, and executor configuration on both connector variants.
31275 reputation · 18 Oct 2021, 07:23 UTC
Standardizing on the NIO connector is preferable for most cross-platform fleets unless you observe a specific, measurable bottleneck in TLS handshakes or static file serving that cannot be resolved via hardware scaling or front-end caching.
The transition to APR (Apache Portable Runtime) introduces native binary dependencies that complicate CI/CD pipelines and rollbacks. To justify this cost, the performance gain must be systemic, not marginal. Use the following criteria to decide if the native advantage is sufficient:
sendfile() implementation significantly reduces kernel-to-user space copying.Because Tomcat may fall back to NIO if native libraries are missing or mismatched, you must verify the active protocol during startup.
Search the catalina.out or startup logs for the following strings:
Loaded Apache Tomcat Native library [version] with TCP blocking
If you see The APR based Apache Tomcat Native library was not found on the current classpath, Tomcat has reverted to the NIO connector regardless of your server.xml configuration.
Connect via JConsole or VisualVM and inspect the Catalina:type=Connector MBean. Check the protocolHandler attribute; it should explicitly reference Http11AprProtocol for native and Http11NioProtocol for NIO.
wrk or JMeter) on the NIO connector to establish a baseline for RPS and p99 latency.Missing Diagnostic: Are you terminating TLS at the Tomcat level or at the fronting reverse proxy? If the proxy handles TLS, the primary advantage of APR (OpenSSL) is nullified, making NIO the objectively better choice for portability.
Use comments to ask for clarification. Post a solution as an answer.
31,275 reputation · 18 Oct 2021, 01:10 UTC
Beyond startup logs, the active connector can be confirmed at runtime through JMX: query Catalina:type=Connector,port=8080 and verify the protocolHandlerClassName attribute shows org.apache.coyote.http11.Http11AprProtocol or org.apache.coyote.http11.Http11NioProtocol. Under load, JMX currentThreadUserTime and currentThreadSystemTime often differ: APR-backed connectors typically show higher system‑time percentage due to native poller execution, while NIO stays predominantly in user‑mode. This metric gap, combined with the startup log check, provides reliable on‑deployment verification without a full benchmark.