ContentsPreviousNextTomcat-Book Project

First, it is necessary to know the difference between Tomcat and JServ because people use to confuse about them, and some think both of them are the same. Before Tomcat, there was another servlet container called JServ and was Servlet 2.0 compliant. It worked in conjunction with apache using a module called mod_jserv for process communication between them.

Tomcat is a new independent Servlet 2.2 compliant container and it does not have any relationship with JServ, but some code that was reused specially with the JServ's Apache adapter called mod_jserv.

The problem was that mod_jserv was too complex due to the legacy code that was brought with it when it was ported from the Apache/JServ. Then it was logical that a new version of the module had to be written. Another important problem was that mod_jserv supported only Apache, while mod_jk supports many web servers through a compatibility layer named the "jk" library. Supporting two different modes of work became problematic in terms of support, documentation and bug fixes. Something regarding to security has to do with SSL, mod_jserv wasn't able to identify in a reliable way if a request was made by HTTP or HTTPS protocol, but mod_jk uses a protocol called ajp13 that allows it to identify them. In few words, what Tomcat needs to connect with Apache is an "agent" that resides in the address space of the Web Server and sends him servlet requests. This is the web server plugin, and this is mod_jk. The redirector usually comes in the shape of a DLL/shared object module that you should plug into the web server. In this case it is called mod_jk.so (for Unix) and mod_jk.dll (for Windows).

To understand what ajp12 and ajp13 are, first we need to know what they were made for. Whenever you need to have a servlet executed, you will need a worker, that is, a Tomcat instance to do it on behalf of the web server. The most common example is to have an Apache web server forwarding servlet requests to Tomcat processes. And we can also configure multiple workers to serve servlets requests on behalf of one web server. We are not going to describe the reasons here, but this configuration is frequently used.

According to the above paragraph, we may identify four different kinds of workers:

  1. ajp12
  2. ajp13
  3. jni
  4. lb
The 1 and 2 are the ones we are going to describe. The 3 refers to an in-process Tomcat worker using JNI rather than an out-process one. The 4 is a load-balancing worker, it knows how to provide round-robin based sticky load balancing with a certain level of fault-tolerance.

So, it is clear now that ajp12 and ajp13 are both TCP/IP based protocols that communicate the Apache server process with the Tomcat workers. In the file worker.properties you can define for each ajp12 worker, a name, a port in which it will listen the requests and a host where it will be executed.

The ajp12 typed workers forward requests to out-of-process Tomcat workers using the ajpv12 protocol over TCP/IP sockets and so does the ajp13 typed workers The main difference between ajpv12 and ajpv13 are that:

  1. ajp13 is a more binary protocol and it try to compress some of the request data by coding frequently used strings as small integers.
  2. ajp13 reuse open sockets and leaves them open for future requests.
  3. ajp13 has special treatment for SSL information so that the container can implement SSL related methods such as isSecure().
As the ajp12 worker, you can define a name, a port and a host for the ajp13 worker but also a cache size to specify the number of open socket connections that the worker will keep. By default this value is 1, but multithreaded web servers such as Apache 2.xx, IIS and Netscape will benefit the most by setting this value to a higher level (such as the estimated average concurrent users for Tomcat).

ContentsPreviousNext