Modify Tomcat connector run mode to optimize Tomcat run performance

Source: Internet
Author: User
Tags openssl library java se

Tomcat is a small, lightweight application Server and one of the most commonly used servers for Java EE developers. However, many developers do not know that the Tomcat Connector (Tomcat connector ) has bio,nio,Apr Three modes of operation, So what's the difference between these three modes of operation, and how do we change the running mode of Tomcat connector to improve the performance of Tomcat?

Let's look at the three operating modes of Tomcat connector first.

Bio

Bio (blocking I/O), as the name implies, is a blocking I/O operation that indicates that Tomcat is using traditional Java I/O operations (that is, java.io packages and their sub-packages). Tomcat, by default, is run in bio mode. Unfortunately, in general, the Bio mode is the lowest performance in three operating modes. We can view the current state of the server through Tomcat Manager. "Click here to view information about the Tomcat Manager User Configuration"

Nio

NiO (new I/O) is a new type of I/O operation provided by Java SE 1.4 and subsequent versions (that is, java . NiO Package and its child packages). Java NiO is based on The buffer , and the Java API that provides non-blocking I/O operations, so NiO is also considered an abbreviation for non-blocking I/O . It has better concurrency performance than traditional I/O operations (bio). To make Tomcat run in NiO mode is simpler, we just need to tomcat< Span style= "color: #0000ff; font-size:13px; Width:auto; Height:auto; Float:none; " > Installing the directory/conf/server.xml file will be configured as follows:

<connectorPort="8080"protocol="http/1.1"
ConnectionTimeout="20000"
Redirectport="8443"/>

The value of the Protocol property in the change to org.apache.coyote.http11.Http11NioProtocol :

<connectorPort="8080"protocol="Org.apache.coyote.http11.Http11NioProtocol"
ConnectionTimeout="20000"
Redirectport="8443"/>

At this point, we can see that the connector run mode of the HTTP protocol for the current server Status page in Tomcat Manager has been changed http-bio-8080 http-nio-8080 .

Apr

Apr (Apache portable Runtime/apache Portable runtime) is the support library for Apache HTTP servers. You can simply understand that Tomcat will invoke the core dynamic link Library of the Apache HTTP server in the form of JNI to handle file reads or network transfer operations, thus greatly improving the performance of Tomcat's handling of static files. Tomcat APR is also the preferred mode for running high concurrent applications on Tomcat. If our tomcat is not running in APR mode, we can see a message similar to the following in the log message when we start Tomcat:

java. library.path:xxx/xxx (Here is the path information)

The configuration of the Tomcat Apr runtime mode is a relatively troublesome one among the three operating modes. As stated in the official documentation, Tomcat APR requires support for the following three components :

    • APR LIBRARY[APR Library]
    • JNI wrappers for APR used by Tomcat (libtcnative) [Simply put, if it's on a Windows operating system, it's a dynamic- link library file called Tcnative-1.dll]
    • OpenSSL Libraries[openssl Library]

In addition, as with the NIO run mode, the corresponding Connector node's attribute value needs to be protocol changed org.apache.coyote.http11.Http11AprProtocol . However, this cumbersome operation is only required before the Tomcat 7.0.30 version, which starts with the Tomcat 7.0.30 version, Tomcat has its own tcnative-1.dll files, and the default is to run in Tomcat Apr mode, So we just need to download the latest version of Tomcat to use directly.

In addition, even if you do not use Tomcat Manager, we can differentiate the current operating mode of Tomcat. If you start in a different connector mode, the boot log information for Tomcat typically contains different things like the following, and we only need to use this information to determine the current Tomcat operation mode:

Bio
Info: Starting Protocolhandler ["http-bio-8080"] 2013-8-6 16:17:50 org.apache.coyote.AbstractProtocol start
Nio
Info: Starting Protocolhandler ["http-nio-8080"] 2013-8-6 16:59:53 org.apache.coyote.AbstractProtocol start
Apr
Info: Starting Protocolhandler ["http-apr-8080"] 2013-8-6 17:03:07 org.apache.coyote.AbstractProtocol start

Modify Tomcat connector run mode to optimize Tomcat run performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.