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 ...
[2768] Carrying a long URL around - looking for memorable shorts
- (new - 2010-05-17)[2753] You do not just fly - that is just part of the journey
- (new - 2010-05-06)[2728] Redirecting a home page using mod_rewrite
[2596] Http protocol - what does a web server send
[2552] Web site traffic - real users, or just noise?
Top or
Show all for Apache HTTP and Tomcat Servers
[2843] String functions in C
- (new - 2010-06-30)[2842] Staring a C course with Hello World - why?
- (new - 2010-06-30)[2841] C Course exercise and sample answer - source in 2 files
- (new - 2010-06-30)[2763] Our C and C++ training course are on Open Source platforms
- (new - 2010-05-13)[2674] Make and makefiles - a commented example to help you learn
Top or
Show all for C and C++ Programming
[2837] Lorry Parking in Melksham
- (new - 2010-06-29)[2829] Dauncey Gardens, Melksham
- (new - 2010-06-27)[2827] Melksham - a gem in Wiltshire
- (new - 2010-06-26)[2782] Tell the Melksham Chamber or you only have yourself to blame
- (new - 2010-05-26)[2779] The history and future of Melksham Chamber of Commerce
- (new - 2010-05-25)[2770] Melksham Chamber of Commerce - Presidents report to AGM
- (new - 2010-05-19)[2748] Monitoring the success and traffic of your web site
- (new - 2010-05-01)
Top or
Show all for Melksham
[2839] Software versions used - June 2010
- (new - 2010-06-30)[2835] A course is more than just a chap giving a lecture
- (new - 2010-06-28)[2810] A course review - for the tutor to complete
- (new - 2010-06-14)[2784] Course Lunches
- (new - 2010-05-27)[2777] Blowing our own trumpet
- (new - 2010-05-23)[2775] Declarations of interest - knowing where you stand with people
- (new - 2010-05-22)[2772] Graham Ellis - Summary of Training Record
- (new - 2010-05-21)[2732] Asking about Jesus
[2731] Training Courses - time of change
[2726] Every cloud has a silver lining
[2661] Current Public Courses
[2637] Courses - Melksham and elsewhere - until the end of April
[2566] Excellent staff make for excellent hotel
[2560] Training comparison to QA Training, Learning Tree, GB Direct.
[2548] Ten years ago, we moved to Melksham Spa
[2541] VAT Changes
[2534] And now for some posts a bit more technical
[2366] At the end of the course
[2354] Training, Open Source computer languages
[2350] Ten years in Melksham - looking forward to ten more.
[2342] Training Classes in other tongues
[2278] First courses for 2010
[2258] Questions I have been asked on answering the phone
[2158] On the roof of a Melksham Spa House
[2041] httpd, Tomcat and PHP course enhancements
[2032] Mobile Internet - an alternative to hotel WiFi
[1996] Advise before my Apache / Tomcat course
[1989] So sad to see you go
[1933] Learning to Program in C
[1932] Training Passports - booking a training program
[1898] Every cloud has a silver lining
[1874] Is it worth it?
[1867] Domain Renewal Group
[1836] Next in the sequence - courses next year (2009)
[1816] Holt on holt
[1781] Reception
[1693] July to December 2008 - Open Source training schedule
[1645] Seeing how others do it - PHP training
[1599] Fresher tutor, better course
[1577] Spring and early summer training courses
[1565] Languages compared - based on developer community size
[1465] Perl, PHP, Python, Tcl, Linux, MySQL, Ruby courses ...
[1459] Interactive training, and advancing techniques further
[1443] Christmas is coming very early
[1420] The Learning Perl crew, October 2007
[1419] National Speaker - now to get the talk ready
[1415] Better technology makes for longer commutes?
[1364] Korn shell course - resources
[1363] One computer per delegate, or pair programming?
[1242] Speaking at St. Catherine's College, Oxford University
[1240] Fancy going to Glastonbury?
[1193] Dangerous Dogs and Hotel Marketing
[1141] A strong team broadens the professional coverage
[1126] MacFormat - Me and My Mac
[1102] A Reference
[1101] Mushroom Curry and Perl Courses
[1081] Customer takes over class, and I am delighted
[1040] What the customer is looking for - effective training
[1038] Know to the police
[1035] Longer hours and better value courses
[910] Helping the miles pass
[741] Last week - picture of the Perl course
[726] In praise of training course delegates.
[719] Gardens, Well House Consultants HQ
[669] The best Open Source library in town
[640] Training Centre Pictures
[636] What is your business latency and potential?
[579] Short Linux and Perl courses for small groups
[578] Woman screaming at me
[570] Features and Benefits
[564] Open Source training from Well House Consultants
[559] ''I don't know'' is sometimes a good answer
[554] What backup is adequate?
[509] Snippets from Geekmas
[504] We are about Open Source programming courses in the UK
[499] Good IT training cannot be cheap
[497] I have a river to cross
[490] A new way to get lost
[460] New Network
[456] Laying out a vegetarian lunch
[450] Wheelchair access - can do!
[448] Out of the norm.
[432] New print centre for our manuals
[397] Where now for dial-up providers?
[396] The next technologies
[387] Training course plans for 2006
[378] A word of admiration for the London cabbie
[371] The training team that's looking out for you
[342] The evening after the course
[336] Targetted Advertising
[333] Do NOT follow links or read attachments in these emails
[310] Just in time - the talk is writ
[306] Bristol Airport this morning, The Farm this evening.
[302] Dining full circle
[292] Elegant languages - Perl, PHP, Python
[277] Fire drill
[273] Course Picture
[264] 100% Training
[256] Spring is in the air
[250] We dont stand still
[247] Extreme training
[244] Getting your examples, my examples and the data files after your course
[241] Dress for training
[234] How to get the best from your supplier
[224] YOUR application and YOUR data
[221] Lunchtime Drink
[219] Some unusual features
[215] Open Source becomes mainstream
[213] Off to Munich
[201] 0870 telephone numbers
[199] Post course support - part of the service
[196] An Open Source course on the Channel Islands
[191] Setting up a training room for a course
[181] Maximum number of trainees on a course
[174] Contrast - the storm and the calm.
[172] Public courses in London
[170] MySQL, Java, PHP and Linux - new technical articles
[168] Welcoming Leah Davies to our team
[167] Upgrade to the Library
[163] Introduction fees, bonuses, commissions, kickbacks
[160] Review of the Autumn
[143] Network Camera
[139] Just provide a room and the students
[136] Please tell us
[134] Geekmas - a brief review
[128] Technical Weekend / Geekmas
[120] Good early morning
[118] History around you
[107] Taking Equipment offshore to run a course
[101] Good value, low cost, cheap.
[99] Should we call it 'Geekmas'?
[83] Geek Cruising
[82] Keeping up to date
[56] Dress Code
[53] Drive the drive
[41] A Thousand and four words
[38] An update for old friends
[36] Tesco at 5
[13] Mobile Office revamp
[10] What do you look for in your IT trainer?
[2] Diary entry - 5th August 2004
Top or
Show all for Training from Well House Consultants
[2828] Sharing our programs - easy. Sharing our data - harder.
- (new - 2010-06-26)[2793] They do weddings, we do courses.
- (new - 2010-06-04)[2724] Escapee Grandparents welcome - Henfield and Melksham
[2650] Getting a phone line changed ...
[2598] An excuse for making a sales call
Top or
Show all for Running a training and hotel company
[2838] Respecting our customers anonimity
- (new - 2010-06-29)[2794] The Farming Industry pictured around Melksham
- (new - 2010-06-04)[2762] Well House - Mission and Policy summaries
- (new - 2010-05-13)[2705] Hotel booking in Melksham made easy!
[2663] Improve your PHP on a weekend away
Top or
Show all for Well House Manor - Hotel and Training Centre
[2823] Where have all the bloggers gone?
- (new - 2010-06-24)[2820] Netiquette for forum newcomers
- (new - 2010-06-20)[2781] The 500 pound question to get you started
- (new - 2010-05-26)[2751] Going off at a tangent, for a ramble
- (new - 2010-05-04)[2743] Public Open Source Training Courses running this summer and autumn in Melksham
Top or
Show all for For the Webmaster, Postmaster and moderator
[2844] Learning about Regular Expressions in C through examples
- (new - 2010-06-30)[2834] Teaching examples in Perl - third and final part
- (new - 2010-06-27)[2806] Macho matching - do not do it!
- (new - 2010-06-13)[2804] Regular Expression Myths
- (new - 2010-06-13)[2800] The Merchants And
- (new - 2010-06-09)[2769] Easy - but for whom?
- (new - 2010-05-18)[2758] But what will you DO with all those pictures?
- (new - 2010-05-09)[2755] Books in the store in the USA - still a portent of the UK market to come?
- (new - 2010-05-08)[2747] Containment, Associative Objects, Inheritance, packages and modules
- (new - 2010-04-30)
Top or
Show all for General Programming Topics
[2774] PHP - Object Oriented Design in use
- (new - 2010-05-21)[2773] Dynamically watching your web site via a PHP wrapper
- (new - 2010-05-21)[2742] A simple server benchmark script
[2738] What is all this SESSION stuff about? (PHP)
[2729] Uploading a document or image to its own URL via a browser
Top or
Show all for PHP - the language and its application
[2735] Type checking, Java arrays and collections
[2734] for and foreach in Java
[2654] Java - from applets to servlets. JSPs and more
[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
[2830] Poulshot Village Fete
- (new - 2010-06-27)[2750] Views of Wessex
- (new - 2010-05-03)[2713] History is all around us
[2687] A lovely spring afternoon
[2685] Stairs
Top or
Show all for Around, about and nearby to Wiltshire
[2840] Just pass a pointer - do not duplicate the data
- (new - 2010-06-30)[2836] Perl - the duplicate key problem explained, and solutions offered
- (new - 2010-06-28)[2833] Fresh Perl Teaching Examples - part 2 of 3
- (new - 2010-06-27)[2832] Are you learning Perl? Some more examples for you!
- (new - 2010-06-27)[2825] Perl course - is it tailored to Linux, or Microsoft Windows?
- (new - 2010-06-25)[2821] Chancellor George Osborne inspires Perl Program
- (new - 2010-06-22)[2818] File open and read in Perl - modernisation
- (new - 2010-06-19)[2817] Setting a safety net or fallback value in Perl
- (new - 2010-06-19)[2816] Intelligent Matching in Perl
- (new - 2010-06-18)[2815] switch and case, or given and when in Perl
- (new - 2010-06-17)[2813] Iterating over a Perl list and changing all items
- (new - 2010-06-15)[2812] What is Perl?
- (new - 2010-06-15)[2811] Igloos melt in the summer, but houses do not
- (new - 2010-06-15)[2805] How are you getting on?
- (new - 2010-06-13)[2801] Binary data handling with unpack in Perl
- (new - 2010-06-10)[2798] Perl - skip the classics and use regular expressions
- (new - 2010-06-08)[2783] The Perl Survey
- (new - 2010-05-27)
Top or
Show all for The Perl Programming Language and its use
[2675] Redirecting to your main domain for correct security keys
[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
Top or
Show all for Client Side Languages (HTML, CSS, Javascript)
[2826] Ruby - training for automated testing users
- (new - 2010-06-25)[2714] A simple example - XML from a Ruby program
[2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast
[2651] Calculation within objects - early, last minute, or cached?
[2623] Object Oriented Ruby - new examples
Top or
Show all for Ruby and Ruby on Rails
[2749] Delegate Question - defining MySQL table relationships as you create the tables
- (new - 2010-05-02)[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
Top or
Show all for SQL and MySQL
[2681] Tcl - a great engineering language
[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
[2723] Returning multiple values from a function - Lua
[2710] __index and __newindex in Lua - metatable methods
[2706] Error trapping in Lua - no exceptions.
[2703] Lua Metatables
Top or
Show all for Programming in Lua
[2822] Python training courses for use with ESRI ArcMap software
- (new - 2010-06-23)[2814] Python - splitting and joining strings
- (new - 2010-06-16)[2790] Joining a MySQL table from within a Python program
- (new - 2010-06-02)[2786] Factory methods and SqLite in use in a Python teaching example
- (new - 2010-05-29)[2785] The Light bulb moment when people see how Object Orientation works in real use
- (new - 2010-05-28)[2780] Formatted Printing in Python
- (new - 2010-05-25)[2778] Learning to program in Python 2 ... and / or in Python 3
- (new - 2010-05-24)[2766] Optional and named parameters to Python functions/methods
- (new - 2010-05-15)[2765] Running operating system commands from your Python program
- (new - 2010-05-14)[2764] Python decorators - your own, staticmethod and classmethod
- (new - 2010-05-14)[2746] Model - View - Controller demo, Sqlite - Python 3 - Qt4
- (new - 2010-04-29)
Top or
Show all for Python Programming
[2824] A pint of Black Rat, and a lazy barman
- (new - 2010-06-25)[2819] Some more pictures ...
- (new - 2010-06-19)[2809] Frankfurt in 90 minutes
- (new - 2010-06-13)[2807] Canal through Melksham - the options and issues
- (new - 2010-06-13)[2803] Travelling across Europe
- (new - 2010-06-12)[2802] After the Perl course in Nurnberg
- (new - 2010-06-11)[2799] Nuremberg - some pictures
- (new - 2010-06-08)[2797] Sur la T.G.V.
- (new - 2010-06-07)[2795] Simon says
- (new - 2010-06-05)[2792] Should Government compete with private industry?
- (new - 2010-06-03)[2787] Sleeping in on Sunday
- (new - 2010-05-30)[2776] Regional Spatial Strategy and the next 20 years - Whence Wiltshire under the new government?
- (new - 2010-05-22)[2767] Back from a Python course in Glasgow
- (new - 2010-05-16)[2760] Views of Scotland
- (new - 2010-05-11)[2759] Touching base
- (new - 2010-05-10)[2757] Bodicea, Lincoln, and our new MP
- (new - 2010-05-09)[2756] Same subject - different pictures
- (new - 2010-05-09)[2754] At Arlington and the Pentagon
- (new - 2010-05-07)[2752] Voting day - UK General Election
- (new - 2010-05-06)
Top or
Show all for And also ...
[2808] From home to Nurnberg - journey pictures
- (new - 2010-06-13)[2796] Sunday - waiting for the ferry.
- (new - 2010-06-06)[2791] Bath to Melksham buses - times
- (new - 2010-06-03)[2789] Melksham to London (Heathrow, and Central London)
- (new - 2010-06-02)[2771] Melksham to Calne by public transport
- (new - 2010-05-20)
Top or
Show all for Public Transport
[2788] Cost of Sales
- (new - 2010-06-01)[2761] A small business, facing a big government questionnaire
- (new - 2010-05-12)[2676] Changing Times
[2626] On Malachite Green
[2625] Both feet on the same pavement
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
[2831] Recording (a macro) in vi
- (new - 2010-06-27)[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
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?