Comparison and optimization of three operating modes (BIO, NIO, APR) of tomcatconne
The performance of three different running Modes of Tomcat ctor varies greatly. The results tested are as follows:
The differences between the three modes are as follows:
BIO:A thread processes a request. Disadvantage: High concurrency leads to a large number of threads, which wastes resources. Tomcat 7 or lower, which is used by default in Linux.
NIO:Java asynchronous IO processing allows a small number of threads to process a large number of requests.
Tomcat8 uses this method by default in Linux. Tomcat7 must modify Connector configuration to start:
APR:Apache Portable Runtime solves the io blocking problem from the operating system level.
Tomcat7 or Tomcat8 is enabled in Win7 or later systems by default. If apr and native are installed in Linux, Tomcat can directly start apr. (Installation: http://my.oschina.net/lsw90/blog/181161)
Java Blocking Java ctor Java Nio Blocking Connector APR/native Connector
BIO NIO APR
Classname AjpProtocol AjpNioProtocol AjpAprProtocol
Tomcat Version 3.x onwards 7.x onwards 5.5.x onwards
Support Polling NO YES
Polling Size N/A maxConnections
Read Request Headers Blocking Sim Blocking
Read Request Body Blocking Sim Blocking
Write Response Blocking Sim Blocking
Wait for next Request Blocking Non Blocking
Max Connections maxConnections
When Tomcat is started, you can view the running mode used by Connector through the log:
Starting ProtocolHandler ["http-bio-8080"]
Starting ProtocolHandler ["http-nio-8080"]
Starting ProtocolHandler ["http-apr-8080"]