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 ...
[2596] Http protocol - what does a web server send
- (new - 2010-01-24)[2552] Web site traffic - real users, or just noise?
[2482] Load balancing with sticky sessions (httpd / Tomcat)
[2355] See this page in French
[2325] Apache, Tomcat, mod_proxy
Top or
Show all for Apache HTTP and Tomcat Servers
[2579] Creating, setting up and using objects in C++
- (new - 2010-01-16)[2578] Where are your objects stored in C++?
- (new - 2010-01-16)[2577] Complete teaching example - C++, inheritance, polymorphism
- (new - 2010-01-15)[2576] What does const mean? C and C++
- (new - 2010-01-15)[2575] Sharing variables between files of code in C - extern
- (new - 2010-01-14)[2573] C Structs - what, how and why
- (new - 2010-01-13)[2572] The what and why of C pointers
- (new - 2010-01-13)[2571] Reading and writing files in C
- (new - 2010-01-12)[2570] Function Prototypes in C
- (new - 2010-01-11)
Top or
Show all for C and C++ Programming
[2640] How is your tax pound spent?
- (new - 2010-02-18)[2597] Does my course include breakfast, lunch, dinner and a hotel room?
- (new - 2010-01-25)[2594] Melksham Area - your community view is sought
- (new - 2010-01-23)[2591] Melksham Hotel, B and B or business accommodation?
- (new - 2010-01-20)[2585] Consultation in Melksham, on Melkshams future
- (new - 2010-01-17)[2584] Melksham Food and Drink Festival, 2010
- (new - 2010-01-17)[2574] Summary of Wiltshire Core Strategy responses
- (new - 2010-01-13)
Top or
Show all for Melksham
[2637] Courses - Melksham and elsewhere - until the end of April
- (new - 2010-02-16)[2566] Excellent staff make for excellent hotel
- (new - 2010-01-07)[2560] Training comparison to QA Training, Learning Tree, GB Direct.
- (new - 2010-01-02)[2548] Ten years ago, we moved to Melksham Spa
[2541] VAT Changes
Top or
Show all for Training from Well House Consultants
[2650] Getting a phone line changed ...
- (new - 2010-02-25)[2598] An excuse for making a sales call
- (new - 2010-01-26)[2593] Food and drink launch
- (new - 2010-01-21)[2530] Taking a knock over Santa
[2502] Monday night, Tuesday night
Top or
Show all for Running a training and hotel company
[2590] A healthy, local breakfast in Melksham
- (new - 2010-01-19)[2581] Snow scenes - and how snow effected our business
- (new - 2010-01-16)[2565] Bright day, snowy day
- (new - 2010-01-06)[2558] Happy new decade - and course and hotel prices for 2010
- (new - 2010-01-01)[2538] Open Source Training Centre and Courses for 2010
Top or
Show all for Well House Manor - Hotel and Training Centre
[2600] Go Programming Language and Courses?
- (new - 2010-01-26)[2592] Re-using our pictures
- (new - 2010-01-21)[2569] How to run a successful online poll / petition / survey / consultation
- (new - 2010-01-10)[2564] Microblogging services - Plurk, Twitter, Jaiku and more
- (new - 2010-01-05)[2562] Tuning the web site for sailing on through this year
- (new - 2010-01-03)
Top or
Show all for For the Webmaster, Postmaster and moderator
[2641] Object Oriented Programming in PHP
- (new - 2010-02-19)[2633] Why do I teach niche skills rather than mainstream?
- (new - 2010-02-13)[2612] The Model, View, Controller architecture (MVC) - what, why and how.
- (new - 2010-02-01)[2586] And and Or illustrated by locks
- (new - 2010-01-17)[2563] Efficient debugging of regular expressions
- (new - 2010-01-04)
Top or
Show all for General Programming Topics
[2646] Compile but do not run PHP - syntax check only
- (new - 2010-02-22)[2635] A PHP example that lets your users edit content without HTML knowledge
- (new - 2010-02-14)[2632] Shipping a test harness with your class in PHP
- (new - 2010-02-12)[2631] How to show a large result set page by page in PHP
- (new - 2010-02-11)[2630] Static variables and ampersands in PHP
- (new - 2010-02-10)[2629] Curly braces within double quoted strings in PHP
- (new - 2010-02-09)[2589] Your PHP code does not work? Here is where to start looking.
- (new - 2010-01-18)[2583] Reducing image size on digital photos - PHP
- (new - 2010-01-17)
Top or
Show all for PHP - the language and its application
[2654] Java - from applets to servlets. JSPs and more
- (new - 2010-02-27)[2653] Java Server Pages - putting it all together
- (new - 2010-02-26)[2652] Reading and writing cookies in Java Servlets and JSPs
- (new - 2010-02-26)[2649] Length, size or capacity in Java?
- (new - 2010-02-24)[2648] Java arrays - are they true arrays or not?
- (new - 2010-02-23)[2642] What does a web application look like under Tomcat?
- (new - 2010-02-20)
Top or
Show all for Java and the Java Environment
[2453] Dark to dark
[2443] Contrasting Cambridge, Bristol and Wiltshire
[2362] Thornham Farm Shop, Seend Cleeve, nr Melksham
[2305] Hot Tap at West Wilts Show
[2302] See us at the West Wilts Show
Top or
Show all for Around, about and nearby to Wiltshire
[2551] Perl and the Common Gateway Interface - out of fashion but still very useful?
[2532] Analysing Google arrivals by country of origin
[2484] Finding text and what surrounds it - contextual grep
[2427] Operator overloading - redefining addition and other Perl tricks
[2416] Automating access to a page obscured behind a holding page
Top or
Show all for The Perl Programming Language and its use
[2628] An example of an injection attack using Javascript
- (new - 2010-02-08)[2554] Adding retrospective ALT attributes to IMG
- (new - 2009-12-28)[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)
Top or
Show all for Client Side Languages (HTML, CSS, Javascript)
[2651] Calculation within objects - early, last minute, or cached?
- (new - 2010-02-26)[2623] Object Oriented Ruby - new examples
- (new - 2010-02-03)[2621] Ruby collections and strings - some new examples
- (new - 2010-02-03)[2620] Direct access to object variable (attributes) in Ruby
- (new - 2010-02-02)[2619] Passing code to procedures and yield in Ruby
- (new - 2010-02-02)[2618] What are Ruby Symbols?
- (new - 2010-02-02)[2617] Comparing floating point numbers - a word of caution and a solution
- (new - 2010-02-01)[2615] String to number conversion with error trapping in Ruby
- (new - 2010-02-01)[2614] Neatly formatting results into a table
- (new - 2010-02-01)[2613] Constants in Ruby
- (new - 2010-02-01)[2610] Cheat Sheet - what do you need for Ruby on Rails?
- (new - 2010-01-31)[2609] Scope of variables - important to Ruby on Rails
- (new - 2010-01-31)[2608] Search and replace in Ruby - Ruby Regular Expressions
- (new - 2010-01-31)[2607] Answers on Ruby on Rails
- (new - 2010-01-30)[2606] Sorting arrays and hashes in Ruby
- (new - 2010-01-30)[2605] Ruby on Rails - a sample application to teach you how
- (new - 2010-01-30)[2603] Ruby objects - a primer
- (new - 2010-01-29)[2601] Ruby - is_a? v instance_of? - what is the difference?
- (new - 2010-01-27)
Top or
Show all for Ruby and Ruby on Rails
[2647] Removing duplicates from a MySQL table
- (new - 2010-02-22)[2645] Optimising and caching your MySQL enquiries
- (new - 2010-02-22)[2644] Counting rows in joined MySQL tables
- (new - 2010-02-22)[2643] Relating tables with joins in MySQL
- (new - 2010-02-21)[2567] Extra MySQL course dates (2 day course, UK)
- (new - 2010-01-08)[2561] The future of MySQL
- (new - 2010-01-03)
Top or
Show all for SQL and MySQL
[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
[2471] A short form of if ... then ... else
Top or
Show all for Tcl, Tcl/Tk and Expect
[2509] A life lesson from the accuracy of numbers in Excel and Lua
[2500] Dynamically formatting your results (Lua)
[2492] Lua Classes - open enrolement
[2461] Luac - getting lua to start fast by precompiling
[2455] Lua examples - coroutines, error handling, objects, etc
Top or
Show all for Programming in Lua
[2655] Python - what is going on around me?
- (new - 2010-02-28)[2622] Handling unusual and error conditions - exceptions
- (new - 2010-02-03)[2616] Defining a static method - Java, Python and Ruby
- (new - 2010-02-01)[2604] Tips for writing a test program (Ruby / Python / Java)
- (new - 2010-01-29)[2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too
- (new - 2010-01-01)
Top or
Show all for Python Programming
[2656] Melksham Carnival
- (new - 2010-02-28)[2624] Skyline and looking up in London
- (new - 2010-02-04)[2611] Sunday Evening, City of London
- (new - 2010-01-31)[2602] East of Melksham - Building Work Starts
- (new - 2010-01-28)[2587] Bowerhill as a cycling community
- (new - 2010-01-17)[2582] Starting to arrange the picture library
- (new - 2010-01-16)[2580] C course inspires new teaching examples
- (new - 2010-01-16)[2555] Bookkeeping
- (new - 2009-12-29)
Top or
Show all for And also ...
[2634] London to and from Melksham by public transport
- (new - 2010-02-13)[2627] Saturdays out from Melksham - to Oxford, to Didcot or to Swindon
- (new - 2010-02-07)[2588] Freddies Wood and the K and A Canal
- (new - 2010-01-17)[2568] Forums for your Melksham and open source discussions
- (new - 2010-01-09)[2557] Rail Campaign - response to core consultation
- (new - 2009-12-31)[2556] Railway Station Survey - please complete today or tomorrow
- (new - 2009-12-30)[2533] Five guests, three groups, one car
[2529] Santa Special, 2009
[2522] Integrated public Transport - what could be done for Melksham
[2515] Why we have two buses an hour - but not a half hourly service
[2513] Wiltshire Council purchases Melksham Station Land
[2511] The story of the railway land at Melksham Station
[2490] Friendly Hotel in Melksham, near Bath
[2486] Santa Special - Trowbridge and Melksham to Swindon
[2477] By train ...
[2473] Exploring Old Railways
[2457] Railway Arithmetic
[2431] Moving busstop!
[2395] From Lymington by train - last of the slammers
[2391] Great Western Route Utilisation Strategy - Draft for Consultation
[2372] Public Transport from (and to) Melksham on Sundays
[2328] Melksham - no trains, no southbound buses through the town
[2318] For Lua Programmers AND for Town Planners
[2268] Westbury Bypass Refused - looking forward
[2253] Walks in and around Melksham, Wiltshire
[2133] Bigger and better this year!
[2083] Do you support a decent train service? Please sign up!
[2075] Supporting Parkinsons and Trains
[2057] Train and Coach fares from London (and airports) to Melksham
[2042] Wiltshire Rail Service Update
[2026] Melksham Climate Friendly Group
[2024] Carry on Training - in spite of the weather
[1999] How low can you sink?
[1986] Walk to Bowerhill
[1965] How much does a train service actually cost
[1964] Why hasnt the fiasco been put right
[1905] A Gold Star for First Great Western Customer Service
[1858] Camera with night vision, youth with no vision
[1848] 30th November - Santa Trip from Melksham
[1802] Motorcycles welcome at Well House Manor
[1777] The Rise and Rise of First Bus Fares
[1757] Preserved railways - struggling to the future?
[1729] Back from the future
[1723] Bath - Melksham - Devizes. Bus route changes, new timetable
[1708] A Train Service Update for Melksham Party in the Park
[1668] Talk on TransWilts train service to Green Party
[1657] Farewell, Newcastle to Stavanger, Haugsund and Bergen
[1640] Walking on The Wiltshire Downs
[1616] Not daring to be an anorak
[1567] Melksham - Swindon. Train v Bus v Car
[1558] Getting somewhere with the train service
[1530] Railway Acronyms and Abbreviations
[1511] Buses from Well House Manor, Melksham, to Bath
[1452] Santa on the train to Melksham
[1428] Travel Across Wiltshire - the game
[1424] Closer than you think - the next step
[1382] First Great Western - information for customers
[1358] Look forward with a new broom - Wiltshire Train Service
[1315] Two years of campaigning for a train service
[1314] Business travel by train in the USA
[1291] Day trip to Weymouth
[1274] Radio coverage for railway issues
[1273] Melksham or Weymouth? Meal or day out?
[1254] Comparing bus stops
[1228] Some progress on the train campaign
[1139] Overcrowded trains around Bristol
[1125] Train service - petititon reply
[1097] Train and business balls all in the air!
[1093] Wiltshire Train - can YOU come on 5th March?
[1085] Lawrence Webb's Melksham Taxi service
[1076] Save the Train - an update
[1069] Rail trouble forced me to buy hotel
[1063] Bradford-on-Avon - 150 years of passenger trains
[1045] Bang! Train campaign hits home
[1044] Call for appropriate train services - Swindon, Bristol, Bath, West Wilts, Severn Beach etc
[1033] Empty at Easleigh, Missing at Melksham, Overflowing at Oldfield
[976] Santa at the station
[974] The last commuter train through Melksham
[952] Coming from London to Melksham by train for a course
[877] Yes, but what do we do now??
[818] Heard, yes. Considered, no. The case for the train.
[814] Melksham Railway Calendar 2007
[803] Not shouting
[793] The Wilts and Berks Canal
[790] Shadow Transport Minister to visit Melksham
[776] Naming Rooms
[764] Journey planning - Xephos v Transport Direct
[708] Linescapes of Mull
[697] For any North and West Wilts and Swindon Readers
[688] Are you free on Friday evening?
[648] West Wilts Railway Users Group and trains to Lacock
[634] Real chance to make a difference
[632] Moral dilemma
[598] Should we cruise around the world?
[527] Greater Western Franchise Awarded
[524] Santa comes to Melksham
[521] Proof needed? Please just use common sense!
[488] Looking for railway groups and users - Swindon, Salisbury, Southampton
[486] Rail services under threat - Swindon, Melksham ... and Newquay and Bicester too
[474] Vintage Bus Day
[459] Kiss and Ride
[447] Tomorrow's meeting.
[434] Through public transport connection, Chippenham to Salisbury, to cease
[428] Swindon - Chippenham - Melksham - Trowbridge - Westbury train service
[187] a popular bus number
[154] Railway train service, Melksham station
[119] PHP course. Come by train.
Top or
Show all for Public Transport
[2626] On Malachite Green
- (new - 2010-02-06)[2625] Both feet on the same pavement
- (new - 2010-02-05)[2542] My armpit was like a zebra crossing
[2496] A better design of mouth
[2397] Signwriting is dead. Long live the sign.
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?
- (new - 2010-02-17)[2638] Finding what has changed - Linux / Unix
- (new - 2010-02-17)[2636] Linux - useful tips including history and file name completion
- (new - 2010-02-15)[2599] Telling Apache web servers apart / notes for the non-technical
- (new - 2010-01-26)[2595] Twelve skills / knowledges needed for the design of a web site
- (new - 2010-01-24)
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?