The Apache Software Foundation announced today a new version of Apache Tomcat 7. While primarily a maintenance update, these point releases such as the latest Apache Tomcat 7.0.16 actually contain completely new features. Headlining this release is the NIO implementation of the AJP connector.
Apache JServ Protocol, or AJP, is a binary protocol that proxies inbound requests from the web server to Tomcat. Usually found in load balanced architectures where there are many web servers, such as Apache HTTPD, and multiple Tomcat servers, this protocol is used to compress and speed up transactions and enable secure transactions with SSL.
New I/O, or NIO, is a set of Java APIs that provides support for non-blocking of data connections. Without it, threads could be opened from the web server to Tomcat, and remain open, or blocked for a number of hours. Heavy concurrent use of your applications could quickly exhaust available threads and cause the application to throw a HTTP 500 Internal Server error. Mark Thomas, Apache Tomcat Release Manager described the new connector in a post today:
The NIO implementation of the AJP connector uses non-blocking I/O on the Tomcat side. So, rather than having one thread per connection, there is a small number of poller threads (normally one or two, and usually under ten) that maintain the connections between Apache HTTPD and Tomcat. Each poller thread can maintain many connections. These poller threads watch for incoming requests from HTTPD and when a request is received , the poller thread passes the request to a worker thread. Once the worker thread completes its task, the worker thread is free to handle another request while the poller thread maintains the connection to httpd. In this scenario, rather than Tomcat having one thread per httpd connection, you can have one thread per concurrent request processed by Tomcat (plus a safety margin) which is often several orders of magnitude lower.
Employed by VMware SpringSource to both provide consulting to large scale or complex Tomcat applications as well as provide continuous support to the Apache Tomcat project, Thomas cites that this feature was actually developed as a result of SpringSource's support queue:
In recent years, a reasonable number of SpringSource’s support calls come in about configuring Tomcat and HTTPD to ensure that there are always threads available to serve any given request. This new NIO implementation of AJP provides users with a new option that will simplify configuration, tuning and improve performance for deployments where there are multiple instances of HTTPD as well as multiple instances of Tomcat. This will be particularly true where there are multiple platform types involved as it will simplify the setup of this type of non-blocking connector.