Tomcat Support for the AJP Communication Protocol
I've been working on a case where a customer is trying to deploy our product in a fairly common server configuration that relies on the Apache web server to accept HTTP requests, and one or more Tomcat server instances on the back-end to process those requests. There are generally two options for choosing how the Tomcat and Apache servers communicate:
- HTTP Reverse-Proxy - by far, the simplest, though the least efficient
- AJP/13 - a binary protocol for handled by connectors on the Apache (mod_jk) and Tomcat (Coyote AJP connector) servers
So, the customer is trying to use AJP/13 for communication between the two. Configuring the two systems is simple; however, AJP is not very well-suited for real-time communications. The Documentum component I work on, UCF, establishes a communications channel between client and server and requires that the server be able to transmit pieces of an HTTP response over an extended period of time. The AJP connector included with Tomcat buffers HTTP responses until a sufficiently large (~8 kilobytes) amount of data is accumulated or the Servlet is finished, at which point the connector flushes the buffer to a socket connection between Apache and Tomcat. In our case, the server should transmit the small "heartbeat" messages to the client in the HTTP response instead of buffering them. While the messages are buffered in Tomcat, the client thinks that the server is dead.
I've arrived at the conclusion that Tomcat's AJP connector does not work well for real-time applications that have the requirement of being able to send small chunks of an HTTP response to a client. This might not be the case with other application servers, though I was able to verify this behavior in the Tomcat application server because the source code is made available to the public. I haven't seen any evidence that the AJP protocol does not support the transmittal of partial HTTP responses. Rather, it's just Tomcat's connector implementation that imposes this limitation.
I'm left with the option of using Apache as a simple reverse-proxy with the mod_proxy connector module. This problem would not exist if the Tomcat AJP connector provided a configuration parameter to indicate that responses should not be buffered before being flushed to the socket.