Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat)

Have you ever tried to sort out a complex situation with a supplier - perhaps something's gone wrong with your electic and gas bills (as happened with us a couple of months ago, when our gas payment got credited to our electic account with the same company). You get on the phone, and the initial person you speak to is in a "traige" roll - filtering calls, dealing with trivial ones, and passing the rest on to a whole team that's behind him/her dealing with the longer cases.

Such issues are rarely solved on a first call - we had to find our meters, look for meter numbers on them as well as readings, and phone back. If triage person puts you through to someone different, you're left explaining the whole thing from scratch again, but if you're able to be put through to the same person again, then they will (you hope) remember the initial details and you can pick up where you left off.

Similar issues can apply when you're using a web server for a major application. A server such as the Apache httpd Server may be used as the front end / triage system, making calls to other servers such as Apache Tomcat sitting behind it to perform more intensive operations. A user of a system such as a flight booking system will make a series of calls to the front end server, and if there's more than one server behind it will want to be routed to the same back server each time so that he can carry on from where he left off. The running of multiple servers behind the front end, with traffic distributed around them, is known as load balancing, and the passing of second and subsequent calls to the same system is known as haveing a sticky session.

On our Deploying Apache httpd and Apache Tomcat course (which I ran as a single-company course this Monday and Tuesday), we set up both servers and - where it's relevant to the customer - we set up load balanced servers with sticky sessions.

Although we're balancing the load between a whole series of Tomcats, most of the setup is done in Apache httpd, as - by the time a request gets to Tomcat - it's already been routed (the load balancer supplied in earlier versions of Tomcat that 6.0 was a Syren, tempting unway administrators off course and onto the rocks!). On Tuesday's course, I chose to add a single line to my httpd.conf file to include an extra set of configurations from a separate proxy forwarder file:
  Include conf/extra/httpd-forwarder.conf
(Complete httpd.conf example file, with other changes made on the course, [here])

The forwarder file itself is also on our web site - it's [here]. After a few headers which start proxying from a clean base, and allow it from any remote host, I defined a balancer group to include 2 machines:
  <Proxy balancer://unicycle>
  BalancerMember loadfactor=5 route=jvm100
  BalancerMember loadfactor=10 route=jvm107

And I then requested that any requests for application "wide" get passed on to the balancer:
  ProxyPass /wide/ balancer://unicycle/ stickysession=JSESSIONID|jsessionid
  ProxyPassReverse /wide/ balancer://unicycle/
  ProxyPassReverseCookiePath /latmjdemo /wide

Let's look at those in more detail:
• I'm asking for request from new clients to be passed on to servers at and in a ration of 1 to 2 (perhaps .107 has a lot of other things loaded on it)
• If there's a cookie called JSESSIONID or jsessionid in the request, it's to be examined to see whether it points forward to a machine called "jvm100" or "jvm107" and, if it does, that's where the forwarding is done to, overriding the selection that would be made for a new connection
• Replies from jvm100 and jvm107 are rewritten (by the ProxyPassReverse directive) to include the name of the URL that the user called up in the header to the response so that following links will be in the right context
• Cookies are also rewritten in reverse, so that JSESSIONID (and all other cookies) truely get sent back up to the server with subsequent requests.

We are currently at httpd release 2.2.17; note that there were 'issues' with using both the balancer and the reverse pass directives within the same proxy request until about release 2.2.11, so you really should be quite up to date if you're going to use this very powerful capabilty.

As well as changing the configuration of Apache httpd, you should make a small change to each Tomcat server.xml file - adding a jvmroute into then engine so that each Tomcat includes its identity in the JSESSIONID cookie. Here's the syntax:
  <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm100">
  <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm107">
on my second machine. Complete sample file [here].

The Application should be installed "identically" on each of the Tomcat servers to ensure a consistent service for all users, irrespective of which machine they happen to end up connect to on their first contact. But for testing and demonstration purposes, I like to change the background colour of the response page on each of the server so that it's very clear as each of my delegates visits the site / runs the application that they're initially attached to one (or other) machine - differing between them - buton subsequent contacts they're firmly going to the same server each time. There's a complete Java test appliaction, using sessions, [here].


1. mod_jk may be used in place of mod_proxy for balancing. mod_proxy is prevelant in new installations these days, but we do have separate notes available for delegates who will be looking after systems with the older connectors.

2. Clustering is different to load balancing. With clustering, each request is forwarded to any of the back end systems, and those back end systems constantly pass information back and forth between themselves so that the are all aware of the context (state) of any request that comes their way. Clustering is much more expensive in terms of processor and network bandwidth, but also more robust in highly sensitive applications where it's critical that a session isn't lost if a one of the back servers becomes unavailable for any reason.
(written 2011-05-18)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J906 - Java - Servlets in More Detail
  [479] New servlet from old - (2005-10-28)
  [1495] Single login and single threaded models - Java and PHP - (2008-01-04)
  [1550] Java (JSP and Servlet examples) live on our server - (2008-02-23)
  [1909] javax.servlet cannot be resolved - how to solve - (2008-11-26)
  [2183] Servlet life cycle, and Java Servlet variable scope - (2009-05-16)
  [2652] Reading and writing cookies in Java Servlets and JSPs - (2010-02-26)
  [2717] The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
  [3044] Changing a Servlet - more that just editing and compiling - (2010-11-12)
  [4431] A Java servlet that is also a stand alone program. And a server that is also a web client. - (2015-02-19)
  [4432] Java web application for teaching - now with sessions and clustering / load balancing demonstrations - (2015-02-20)

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)
  [2059] Sharing the load between servers - httpd and Tomcat - (2009-02-28)
  [2482] Load balancing with sticky sessions (httpd / Tomcat) - (2009-10-29)
  [2483] Clustering on Tomcat - (2009-10-30)
  [3339] Simplest ever proxy configuration? - (2011-06-28)
  [3892] Distributed, Balanced and Clustered Load Sharing - the difference - (2012-10-13)

A608 - Web Application Deployment - Apache httpd mod_proxy
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [1006] Apache httpd and Apache Tomcat together tips - (2006-12-24)
  [1376] Choosing between mod_proxy and mod_rewrite - (2007-10-02)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1767] mod_proxy and mod_proxy_ajp - httpd - (2008-08-22)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1944] Forwarding session and cookie requests from httpd to Tomcat - (2008-12-14)
  [2062] Virtual hosting and mod_proxy forwarding of different domains (httpd) - (2009-03-01)
  [2273] Three recent questions on Tomcat Convertors - (2009-07-07)
  [2325] Apache, Tomcat, mod_proxy - (2009-08-06)
  [3680] How can I run multiple web servers behind a single IP address? - (2012-04-02)

Back to
Every tenth picture.
Previous and next
Horse's mouth home
Forward to
It's not just about the jam in the sandwich
Some other Articles
A long day, a long journey, and families and similarities the world over
Dog, hotel, Melksham, Wiltshire?
Strawberry Cream Teas, Coffee straight from the Bean and freshly squeezed orange juice - Melksham, every afternoon
It's not just about the jam in the sandwich
Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat)
Every tenth picture.
Pay and refund scam - alive and kicking against Melksham businesses
Changes (and no changes) at Melksham bus stops
New Camera - very first picture, and next from first films
Random Questions ...
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

1 unpublished comment pending on this page

edit your own (not yet published) comments

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3293_Dis ... mcat-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb