Web Application Load Balancing and In Memory Session Sharing with Tomcat and Apache
Posted by dvromeu in Web ApplicationsThe combination of Tomcat, Apache and mod_jk can be a good choice on delivering a scalable and robust solution for a simple JSP/Servlet based web application.
Scalability and HTTP session failover can be achieved in a simple manner with a straightforward lightweight servlet container like Tomcat, which offers cluster functionalities.
Load Balancing is achieved through the mod_jk apache module, which distributes incoming requests with a simple weighed-round-robin mechanism through the AJP protocol.
(mod_jk seems to be the best supported and most widespread Tomcat – Apache connector)
In order to offer HTTP session failover (avoidance of session loss in case of failure of the Tomcat instance holding the session), session replication can be used.
Tomcat can share sessions through a database, a file or through in-memory replication.
To get an idea of the overall architecture, you will end up with something like this:
Tomcat uses a very simple clustering mechanism:
Clustering membership is established using multicast pings. Once a multicast ping has been received, the member is added to the cluster. Upon the next replication request, the sending instance will use the host and port info and establish a TCP socket. Using this socket it sends over the serialized data.
It is possible to have an initial starting point for this architecture in no time, and the following is a very brief proof of concept with Apache HTTP Server 2.2.11, mod_jk 1.2.28,Apache Tomcat 6.0.18 running on Mac OS X 10.5.6 (Darwin 9.6.0).
In this example, one Apache HTTP Server will be load balancing http requests between two Apache Tomcat instances through the mod_jk module.
Tags: Apache HTTP Server, Apache Tomcat, Load Balancing, mod_jk, Session Failover, Session Replication, Web Applications
