Keynote article ...
Clustering on Tomcat
Subject: Clustering, using Apache http server (version 2.2.14 in my example) with mod_proxy_balancer as the front load splitter and Apache Tomcat 6.0.20 as the replicated application engine. [[Tip should also work for other recent 2.2.x and 6.0.x versions]]
Background
This is a follow on article from Load balancing with sticky sessions (httpd / Tomcat), where I looked at sharing out the application work between a number instances of Tomcat from an Apache http server (httpd) that did the bookkeeping. In a nutshell, the Apache http server sent new arrivals to a 'random' Tomcat, and then used sticky sessions so that - when a visitor came back for their subsequent visit in the same series of accesses - they would always talk to the same Tomcat and could continue their conversation with the server having full knowledge of the position to date.
The balancer alone is a good solution as far as it goes but:
• What happens if the Tomcat that has been stuck to goes out of service?
• What happens if you have such a lot of traffic that you need to replicate your httpd front end?
• What happens if your httpd fails?
• What is you don't actually want to use sessions, but still need what appears to be a single Tomcat?
One possible option to addressing some of these is to use the clustering capability of Tomcat, which I'll describe below. But you should first consider if you really need the extra step:
(a) can I accept that a session will be lost on the rare occasions that a Tomcat goes offline?
(b) is writing to a backend database going to preserve sufficient information anyway?
and if the answer to either is "yes", you probably do NOT need to cluster.
How does clustering work?
You run your web application on a series of identical (or rather "near identical" - the IP address will differ!) servers. With clustering turned on, each of the servers in the cluster is broadcasting (via multicast) any changes made in sessions, cookies, etc to any other listening cluster members on that same multicast address. So that when a visitor comes back for his / her next access, all the machines know what's been going on and can knowledgeably handle the request, even if the original machine isn't available.
You can turn clustering on in Apache Tomcat 6.0.20 simply by uncommenting the line in the default server.xml file that relates to it:
<Cluster className = "org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
and restating your Tomcat. Older versions of Tomcat (such as 5.5) had a long configuration section listing the ports, replication time, IP addresses to use, trigger files all of which are important but none of which actually needs to be changed from default in the current release that's the target of this article.
Once you have turned clustering on (yes, it's now that simple), your machines will be communicating ... it's rather like starting a rumor in an office - before you know it, EVERYONE who's around has heard the rumor.
Clustering with the balancer
If you have already implemented balancing with sticky sessions (as covered in the preceeding article), turning on clustering will cause the data to be shared around. Most of the time the data passed around will not be used - it will ONLY form a backup of the session, to be used if the balancer is unable to reach the sticky machine because it has done down or been taken out of service.
With sticky sessions activated, even a second front-end Apache http server won't cause a switch from one Tomcat to another unless a fail-over occurs, as the jvmroute is a part of the cookie so either (any) of the httpd front ends will correctly forward to the original Tomcat. And if you have an intelligent hardware load balancer, that too will be able to forward consistently and the the clustering will remain merely as a backup.
If you disable sticky sessions on your balancer, the metrics will change. Forwarding will now be at shared to each of the Tomcats in the balanced group / cluster group (take care that all members of the balance group are included in the cluster!) and so the visitor will get to a differnt back end box each time. But that's now perfectly fine, as they're sharing the data between them so will all know about the originator.
Testing if your cluster is working
Ironically, clustering and balancing is designed to be transparent, so how do you test whether it's working?
My first simple 'trick' is to change the background colour of the pages returned from each cluster member so that "if it's orange it must be Holt" and "if it's blue it must be Chippenham" (our servers are names after local towns and villages!). Going a little further, you can edit your servlet / JSP to return the name of the current host. In Java, the following line:
String myname = InetAddress.getLocalHost().getHostName();
will return you the local name of your computer, so that you can then echo the name.
On last Tuesday's course, I took our sample "Barman" script that remembers how many drinks you've had in a session (visit counter!) and extended it into a "Pub Watch" script, where each of the barman communicates with his colleagues in neighboring pubs to keep track of who's out on the town, and how much they have had to drink in each establishment.
If you click on the links in the previous paragraph, you can download the source code for "Barman" and "PubWatch" and try the code out for yourself. Using the balancer manage that I introduced at the end of yesterday's article, you can open and close individual pubs and see how their customers go elsewhere for their next drink, and you can turn sticky sessions off in the balancer and see how faithful customers will then hit the road and go to a different pub each time for their next drink.
Some notes on clustering
1. The machines in the cluster communicate through multicast, so must be on the same subnet.
2. It's a good idea for the subnet you use to have plenty of capacity if your environment is busy, and for it to be firmly behind a strong firewall from your own company's general user traffic, let alone the Internet
3. If you have multiple Tomcat clusters on the same subnet, you'll need to configure one of the clusters away from the default settings - otherwise they'll end up as being one big cluster (you'll find the word 'tribe' creaping in here!)
At present, we mention clustering on our public deploying apache httpd and Tomcat course. Only a small proportion of our delegate want to go 'that far', and for newcomers who hadn't done any web server work when they first came along a couple of days earlier, it would be just too much for the one session.
An extra day on the end of a Tomcat course, coverage in a private course, or a special session set up for the purpose ... all are possible to help you learn how clustering and balancing work. We'll have a network of computers set aside at our training centre for the purpose of setting up a test case, experimenting with configurations, seeing what happens when machines are switched on and off. Something you wouldn't dare so with your own production environment, and might be reluctant to do even on your development of test networks (that's even assuming that you do HAVE multiple machines at the development or test level). (this article written on 2009-10-30) |
Other articles ...
[2728] Redirecting a home page using mod_rewrite
- (new - 2010-04-17)[2596] Http protocol - what does a web server send
[2552] Web site traffic - real users, or just noise?
[2482] Load balancing with sticky sessions (httpd / Tomcat)
[2355] See this page in French
Top or
Show all for Apache HTTP and Tomcat Servers
[2674] Make and makefiles - a commented example to help you learn
- (new - 2010-03-12)[2673] Multiple Inheritance in C++ - a complete example
- (new - 2010-03-12)[2670] Pointers to Pointers to Pointers - what is the point?
- (new - 2010-03-10)[2669] Efficient use of dynamic memory - C and realloc
- (new - 2010-03-10)[2579] Creating, setting up and using objects in C++
Top or
Show all for C and C++ Programming
[2739] Melksham Scouts
- (new - 2010-04-25)[2725] How do our tactics help us meet the strategy, for the greater good?
- (new - 2010-04-16)[2716] Melksham in Pictures
- (new - 2010-04-10)[2708] The bull on the footpath
- (new - 2010-04-04)[2691] New brochures for the Melksham area
- (new - 2010-03-24)[2683] Car Parking in Melksham
- (new - 2010-03-18)[2666] Random thoughts on Melksham Town Planning and development
- (new - 2010-03-08)[2665] Early Spring walk in Melksham
- (new - 2010-03-07)[2664] Oliver Cromwell at Bristol Temple Meads
- (new - 2010-03-06)
Top or
Show all for Melksham
[2732] Asking about Jesus
- (new - 2010-04-20)[2731] Training Courses - time of change
- (new - 2010-04-19)[2726] Every cloud has a silver lining
- (new - 2010-04-16)[2661] Current Public Courses
- (new - 2010-03-05)[2637] Courses - Melksham and elsewhere - until the end of April
Top or
Show all for Training from Well House Consultants
[2724] Escapee Grandparents welcome - Henfield and Melksham
- (new - 2010-04-15)[2650] Getting a phone line changed ...
[2598] An excuse for making a sales call
[2593] Food and drink launch
[2530] Taking a knock over Santa
Top or
Show all for Running a training and hotel company
[2705] Hotel booking in Melksham made easy!
- (new - 2010-04-03)[2663] Improve your PHP on a weekend away
- (new - 2010-03-05)[2660] One number for Well House - 01225 708225
- (new - 2010-03-04)[2659] New numbers, as 01225 707126 and 01225 709638 are being retired
- (new - 2010-03-04)[2590] A healthy, local breakfast in Melksham
Top or
Show all for Well House Manor - Hotel and Training Centre
[2743] Public Open Source Training Courses running this summer and autumn in Melksham
- (new - 2010-04-27)[2697] Email metrics and filtering
- (new - 2010-03-28)[2690] The World Company Register - is it another scam?
- (new - 2010-03-23)[2686] Freedom of Information - consideration for web site designers
- (new - 2010-03-20)[2668] Is it worth it?
- (new - 2010-03-09)
Top or
Show all for For the Webmaster, Postmaster and moderator
[2747] Containment, Associative Objects, Inheritance, packages and modules
- (new - 2010-04-30)[2741] What is a factory?
- (new - 2010-04-26)[2737] Improving your function calls (APIs) - General and PHP
- (new - 2010-04-24)[2715] Uploading an image, document or pdf via a browser (php)
- (new - 2010-04-10)[2700] The same very simple program in many different programming languages
- (new - 2010-03-31)
Top or
Show all for General Programming Topics
[2742] A simple server benchmark script
- (new - 2010-04-27)[2738] What is all this SESSION stuff about? (PHP)
- (new - 2010-04-25)[2729] Uploading a document or image to its own URL via a browser
- (new - 2010-04-18)[2684] Exception handling in PHP
- (new - 2010-03-18)[2682] Adding extensions to PHP Open Source applications - callbacks
- (new - 2010-03-17)[2680] Static class members in PHP - a documented example
- (new - 2010-03-16)[2679] How to build a test harness into your PHP
- (new - 2010-03-16)[2667] Web page to telephone calls / links using an iPhone
- (new - 2010-03-08)
Top or
Show all for PHP - the language and its application
[2735] Type checking, Java arrays and collections
- (new - 2010-04-23)[2734] for and foreach in Java
- (new - 2010-04-22)[2654] Java - from applets to servlets. JSPs and more
- (new - 2010-02-27)[2653] Java Server Pages - putting it all together
[2652] Reading and writing cookies in Java Servlets and JSPs
Top or
Show all for Java and the Java Environment
[2713] History is all around us
- (new - 2010-04-09)[2687] A lovely spring afternoon
- (new - 2010-03-21)[2685] Stairs
- (new - 2010-03-19)[2453] Dark to dark
[2443] Contrasting Cambridge, Bristol and Wiltshire
Top or
Show all for Around, about and nearby to Wiltshire
[2736] Perl Course FAQ
- (new - 2010-04-23)[2688] Security considerations in programming - what do we teach?
- (new - 2010-03-22)[2657] Want to do a big batch edit? Nothing beats Perl!
- (new - 2010-03-01)[2551] Perl and the Common Gateway Interface - out of fashion but still very useful?
[2532] Analysing Google arrivals by country of origin
Top or
Show all for The Perl Programming Language and its use
[2675] Redirecting to your main domain for correct security keys
- (new - 2010-03-13)[2628] An example of an injection attack using Javascript
[2554] Adding retrospective ALT attributes to IMG
[2390] Dynamic / changing images on your web page
[2223] CSS Style Diagrams - working out where attributes come from
[2135] What features does this visitors browser support? (PHP)
[1998] Text on a background image
[1926] Flash (client) to PHP (server) - example
[1831] Text formating for HTML, with PHP
[1814] Javascript/HTML example, dynamic server monitor
[1813] Ajax - going Asyncronous and what it means
[1812] Starting Ajax - easy example of browser calling up server data
[1811] Alternative URLs using % symbol encoding
[1806] Dealing with overhead cables in a photograph
[1681] Adding a button to a web page to print the page
[1677] CSS training - Cascading Style Sheets (UK course)
[1630] To provide external links, or not?
[1618] A small picture does not always cut it!
[1519] Flipping images on your web page
[1493] Comparison - cellpadding versus cellspacing
[1463] All the special characters in HTML ...
[1431] Getting the community on line - some basics
[1352] Actionscript / Flash / Flex (IAQ/FAQ)
[1322] Flash - is it available to your web page?
[1160] HTML - example of a simple web page
[1034] The new web site look spreads
[1019] span and div tags - a css comparison
[1017] css - handling white space and pre
[1016] Modernising from tables to cascading style sheets
[999] Cascading and the buses
[996] Setting your colour theme through PHP
[994] Training on Cascading Style Sheets
[993] Positioning with Cascading Style Sheets
[887] HTML tables - telling whats wrong from the display
[857] Strikingly busy
[847] Image maps for navigation - a straightforward example
[665] PHP Image viewing application
[565] Using PHP to output images, XML, Style sheets, etc
[553] Keep that image small
[522] Javascript events - a good example
[501] .css - using PHP to make dynamic style sheets
[411] Javascript examples (some PHP and MySQL too)
[351] Is photoajustment an addiction?
[220] When to use Frames
Top or
Show all for Client Side Languages (HTML, CSS, Javascript)
[2714] A simple example - XML from a Ruby program
- (new - 2010-04-10)[2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast
- (new - 2010-04-07)[2651] Calculation within objects - early, last minute, or cached?
[2623] Object Oriented Ruby - new examples
[2621] Ruby collections and strings - some new examples
Top or
Show all for Ruby and Ruby on Rails
[2647] Removing duplicates from a MySQL table
[2645] Optimising and caching your MySQL enquiries
[2644] Counting rows in joined MySQL tables
[2643] Relating tables with joins in MySQL
[2567] Extra MySQL course dates (2 day course, UK)
Top or
Show all for SQL and MySQL
[2681] Tcl - a great engineering language
- (new - 2010-03-17)[2476] Tcl - uplevel to run code at calling level
[2475] Quick easy and dangerous - automated logins via Tcl / Expect
[2474] Using Tcl and Expect to automate repetitive jobs
[2472] split and join in tcl and expect
Top or
Show all for Tcl, Tcl/Tk and Expect
[2727] Making a Lua program run more than 10 times faster
- (new - 2010-04-16)[2723] Returning multiple values from a function - Lua
- (new - 2010-04-15)[2710] __index and __newindex in Lua - metatable methods
- (new - 2010-04-05)[2706] Error trapping in Lua - no exceptions.
- (new - 2010-04-04)[2703] Lua Metatables
- (new - 2010-04-02)[2702] First and last match with Regular Expressions
- (new - 2010-04-02)[2701] Is Lua an Object Oriented language?
- (new - 2010-04-01)[2699] Lua tables - they are everything
- (new - 2010-03-30)
Top or
Show all for Programming in Lua
[2746] Model - View - Controller demo, Sqlite - Python 3 - Qt4
- (new - 2010-04-29)[2745] Connecting Python to sqlite and MySQL databases
- (new - 2010-04-28)[2744] PyQt (Python and Qt) and wxPython - GUI comparison
- (new - 2010-04-28)[2722] Mixins example in Python
- (new - 2010-04-14)[2721] Regular Expressions in Python
- (new - 2010-04-14)[2720] Multiple inheritance in Python - complete working example
- (new - 2010-04-14)[2719] Traffic lights in Python
- (new - 2010-04-13)[2718] Python - access to variables in the outer scope
- (new - 2010-04-12)[2717] The Multiple Inheritance Conundrum, interfaces and mixins
- (new - 2010-04-11)[2695] TCP v UDP / Client v Server - Python examples
- (new - 2010-03-25)[2694] Multiple processes (forking) in Python
- (new - 2010-03-25)[2693] Methods that run on classes (static methods) in Python
- (new - 2010-03-25)[2692] Flexible search and replace in Python
- (new - 2010-03-25)[2655] Python - what is going on around me?
- (new - 2010-02-28)
Top or
Show all for Python Programming
[2740] Melksham Hustings at George Ward School
- (new - 2010-04-26)[2733] Travel Troubles and Jesus again
- (new - 2010-04-21)[2712] A more informed decision than ever before
- (new - 2010-04-08)[2698] Ruth Davis, 1916 - 2010
- (new - 2010-03-28)[2689] Can my dog eat potatoes? Doggie Dietary Research, and political sleaze!
- (new - 2010-03-23)[2677] Blowing out the winter cobwebs
- (new - 2010-03-14)[2671] Melksham - Carnival, Party in the Park, and Spot the Oddity
- (new - 2010-03-11)[2656] Melksham Carnival
- (new - 2010-02-28)
Top or
Show all for And also ...
[2730] Bird Watching on the Melksham Avon
- (new - 2010-04-18)[2709] Old trackways and routes near Melksham
- (new - 2010-04-05)[2707] A walk on the Kennet and Avon
- (new - 2010-04-04)[2704] A walk within without - Melksham Without
- (new - 2010-04-02)[2696] Garlic bread without garlic
- (new - 2010-03-27)[2678] Reaching out to the community - a good case for support
- (new - 2010-03-15)[2672] Dear Planners, please provide viable alternatives
- (new - 2010-03-11)[2662] Is Melksham public transport actually used?
- (new - 2010-03-05)[2658] Save the Train - a significant change in approach
- (new - 2010-03-03)
Top or
Show all for Public Transport
[2676] Changing Times
- (new - 2010-03-13)[2626] On Malachite Green
[2625] Both feet on the same pavement
[2542] My armpit was like a zebra crossing
[2496] A better design of mouth
Top or
Show all for Fun and Flames
[2483] Clustering on Tomcat
[2384] Looking ahead to the Autumn season of training and accommodation
[2144] Looking for a career change - Physician to Web Site Designer
[1955] How to avoid duplicating web page maintainance
[1857] November and December Public Course Schedule
Top or
Show all for Keynote Articles
[2639] su or su - ... what is the difference?
[2638] Finding what has changed - Linux / Unix
[2636] Linux - useful tips including history and file name completion
[2599] Telling Apache web servers apart / notes for the non-technical
[2595] Twelve skills / knowledges needed for the design of a web site
Top or
Show all for Linux and Shell Programming
Public Transport • Training from Well House Consultants • And also ... • Tcl, Tcl/Tk and Expect • Programming in Lua • Python Programming • Well House Manor - Hotel and Training Centre • Apache HTTP and Tomcat Servers • The Perl Programming Language and its use • Ruby and Ruby on Rails • PHP - the language and its application • C and C++ Programming • Linux and Shell Programming • Melksham • SQL and MySQL • For the Webmaster, Postmaster and moderator • Java and the Java Environment • Fun and Flames • Running a training and hotel company • Around, about and nearby to Wiltshire • Client Side Languages (HTML, CSS, Javascript) • Keynote Articles • General Programming Topics
A little more about this newsletter ...
At Well House Consultants, we run niche IT training courses ... and we run a hotel for delegates on those courses and other visitors to Melksham too. And we make a lot of friends - have a lot of ambassadors with whom we want to keep in touch. So every day Graham (that's me, writing this piece) puts together an article or two which might include the latest sample programs that I've written during the current course, new information about
Well House Manor - our business hotel, tips on search engine optimisation,
announcements of upcoming public courses, pictures of local places, and even (on occasions) rants and whimsical pieces to keep those friends up to date and in touch. The feeds are available directlt via the Blog -
"The Horse's Mouth", they're on our
Twitter Feed and you can find me at my
LinkedIn profile.
But most people just want to look us up occasionally - every month or two, and then to catch up on the latest news just for their particular subjects of interest ... and that's what this newsletter is about
You'll find above the titles of ALL the new articles written in the last two months, listed by major subject area, and showing as
(new) with their date of publication. You'll find additional articles in each category too - topping each category up to a minimum of five articles. And you'll find a link at the end of each section which lets you expand that section to show the titles of every article that's been published in that section. After all, "the old ones are often the best ones", aren't they?