If you're running a lot of traffic through an application, it's possible that one web server can't cope ... not so much because of the traffic levels, but because oomph the computer. Customer's applications range from financial to transport planning. The amount of compute behind the calculation of a Melksham to
Altnabreac train journey schedule is large, even if the result is a tiny report.
Now you'll want to quote your customer a single URL, won't you, to process all your traffic, and you'll want to save yourself the £40,000 cost of a hardware load balancer. OK ... Scheme:
• A single server running Apache httpd forwarding the hard work to ...
• A whole batch of Apache Tomcat servers (if your application is in Java) which are doing all the compute and working out that you need to change at Chippenham, Paddington, Euston and Inverness!
You can do this very nicely, and the modern way of connecting the two servers is using mod_proxy_balancer. It's supplied with httpd (no need to source it extra and build it) and it's powerful and works well once you've come to terms with the various configuration options.
But then here comes the 'sting in the tail'. "What does a RETURN ticket cost" comes back a follow up request, and you need to ensure that your visitor is either
routed to the same server as he was on before or that
the server he gets send to may be a different one, but is aware of the enquiry he is continuing. The first of these approaches (load balancing) is far easier and lower cost in terms of resources than the latter (clustering) which, however, is far more robust in the unlikely event of a Tomcat server going off-line.
There are a number of actions that need to be taken in the configuration of your system to ensure that users DO get routed back to the same server if you take the balance approach:
1. You need to declare a sticky cookie
at the Apache httpd mod_proxy_balancer
2. You need to set a jvmroute
at the Apache Tomcat
3. Your programmer needs to set up a Session
at Your Servlet
and perhaps
4. You need to set up a Reverse Cookie Path.
We've put all this lot in a training example ... and the example we chose was a front end server that receives guests and sends each newly arrived one to a randomly selected put for a drink, but on subsequent visits sends then back to the same pub, secure in the knowledge that they'll feel comfortable and an home there, and will be known to the barman.
Here are the sample files:
The important bit in the httpd.conf configuration file for Apache httpd
<Proxy balancer://barcrawl>
Balancermember ajp://192.168.200.218:8189/bar
Balancermember ajp://192.168.200.214:8189/bar
Balancermember ajp://192.168.200.219:8189/bar
Balancermember ajp://192.168.200.210:8333/bar
Balancermember ajp://192.168.200.215:8189/bar
ProxySet lbmethod=bytraffic
ProxySet stickysession=JSESSIONID
</Proxy>
ProxyPass /bar balancer://barcrawl/
ProxyPassReverseCookiePath /bar /bar
The setting up of the server route in the configuration file for Apache Tomcat - server.xml:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="elm" >
And here are the pertinent lines from within our
Barman application, each copy of which has been altered to welcome the visitor to a different pub:
HttpSession session = request.getSession(true);
out.print("<h1>Welcome. Please enter your name</h1>");
out.print("You are in the King Billy<br>");
We'll train you on setting up Apache httpd and Tomcat on our
Deploying Apache httpd and Tomcat course (but please let us know when you book if you're particularly interested in load balancing and / or clustering and we may suggest an extra day.
And we'll train you on Java Programming on our
Java Bootcamp if you're already a programmer, or on
learning to program in Java if you're a programming novice.
Pictures - Melksham pubs - "The Bear", "The Unicorn" and "The Red Lion"
(written 2009-02-28, updated 2009-03-02)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A690 - Web Application Deployment - Clustering and load balancing [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
[1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
[1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
[1993] Load Balancing - Hardware or Software? - (2009-01-15)
[1995] Automated server heartbeat and health check - (2009-01-16)
[2482] Load balancing with sticky sessions (httpd / Tomcat) - (2009-10-29)
[2483] Clustering on Tomcat - (2009-10-30)
[3293] Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat) - (2011-05-18)
[3339] Simplest ever proxy configuration? - (2011-06-28)
[3892] Distributed, Balanced and Clustered Load Sharing - the difference - (2012-10-13)
[4432] Java web application for teaching - now with sessions and clustering / load balancing demonstrations - (2015-02-20)
Some other Articles
Internal Dummy Connections on Apache httpdVirtual hosting and mod_proxy forwarding of different domains (httpd)Tomcat 6 - Annotated Sample Configuration FilesDatabase connection Pooling, SSL, and command line deployment - httpd and TomcatSharing the load between servers - httpd and TomcatInvoker and cgi servlets on Tomcat 6Train and Coach fares from London (and airports) to MelkshamWeb Site Loading - experiences and some solutions sharedEffect on server when memory runs out and swapping startsTuning httpd / the supermarket checkout comparison