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 ...
[3019] Apache httpd Server Status - monitoring your server
[3018] Tuning Apache httpd and Tomcat to work well together
[3015] Logging the performance of the Apache httpd web server
[2900] Redirecting a page - silent, temporary or permanent?
[2768] Carrying a long URL around - looking for memorable shorts
Top or
Show all for Apache HTTP and Tomcat Servers
[3146] Strings in C
- (new - 2011-01-25)[3145] Structures v Structure Pointers in C. How, which, why.
- (new - 2011-01-25)[3144] Setting up arrays in C - fixed size at compile time, or dynamic
- (new - 2011-01-24)[3124] C++ - putting the language elements together into a program
- (new - 2011-01-08)[3123] C++ objects - some short, single file demonstrations
- (new - 2011-01-07)[3122] When is a program complete?
- (new - 2011-01-06)[3121] New year, new C Course
- (new - 2011-01-05)
Top or
Show all for C and C++ Programming
[3182] What we look for in a lunchtime cafe restaurant in Melksham
- (new - 2011-02-24)[3173] What is the Melksham Chamber of Commerce?
- (new - 2011-02-18)[3172] On consultations, car parking, and Melksham town centre
- (new - 2011-02-17)[3162] Keep your business customer-friendly!
- (new - 2011-02-09)[3127] Burger me!
- (new - 2011-01-10)[3117] Opportunities for Melksham - new businesses in the town
- (new - 2011-01-01)
Top or
Show all for Melksham
[3180] Age limits for Well House Consultants Open Source courses?
- (new - 2011-02-22)[3160] Extra courses - Advanced PHP, MySQL and Lua
- (new - 2011-02-07)[3137] Training Classes - should the training company provide a system for each delegate to use?
- (new - 2011-01-18)[3131] Lua, Tcl, Python; Worldwide training classes
- (new - 2011-01-14)[3130] New Computers for delegates to use
- (new - 2011-01-13)[3129] Extra courses - C and C++
- (new - 2011-01-12)
Top or
Show all for Training from Well House Consultants
[3165] Journalism 101
- (new - 2011-02-11)[3164] Brown - or Mrs Sally Brown, accountant from Whitstable?
- (new - 2011-02-10)[3153] Points West to Belfast
- (new - 2011-02-01)[3147] Hotel star ratings - towards a better system of review
- (new - 2011-01-25)[3103] Thank you - and Happy Christmas
Top or
Show all for Running a training and hotel company
[3134] Melksham Weather - Warm and windy becoming colder and calmer
- (new - 2011-01-15)[3115] Perl, Python, PHP, Lua, Linux, and more - and business hotel too. Menu for 2011
- (new - 2010-12-31)[3107] Hotel and Training Course prices - the effect of the VAT rise on 4th January 2011
[3071] Well House Price list, January to March 2011
[2962] Well House Manor - the history of the hotel
Top or
Show all for Well House Manor - Hotel and Training Centre
[3179] Oops - I typed ci not vi, and have lost my file ...
- (new - 2011-02-21)[3174] Sharing a single hotel internet connection without carrying extra hardware
- (new - 2011-02-18)[3170] How far is something pictured from the camera?
- (new - 2011-02-15)[3168] Web Sites - Subject to Advertising Standards from 1st March - check your sites
- (new - 2011-02-13)[3166] Well house is strong - confirmed?
- (new - 2011-02-11)[3149] Looking back at www.wellho.net
- (new - 2011-01-28)
Top or
Show all for For the Webmaster, Postmaster and moderator
[3169] Rekeying a table - comparison in #Ruby #Perl and #Python
- (new - 2011-02-14)[3152] Jargon busting
- (new - 2011-01-30)[3148] OpenGL / C / C++ - an example to get you started
- (new - 2011-01-26)[3120] Learning to write good programs in C and C++ - separating out repeated code
- (new - 2011-01-04)[3112] Public and private courses - subjects available for 2011
- (new - 2010-12-29)
Top or
Show all for General Programming Topics
[3186] How to add a customised twitter feed to your site
- (new - 2011-02-27)[3163] Twitter - the special use of @ # and http: in tweets
- (new - 2011-02-09)[3143] On time
- (new - 2011-01-23)[3132] Virtual Hosting with Apache http server - an overall scheme, and avoiding common pitfalls
- (new - 2011-01-14)[3094] Setting your user_agent in PHP - telling back servers who you are
Top or
Show all for PHP - the language and its application
[3048] String handling - from first steps to practical examples
[3047] What is a universal superclass? Java / Perl / Python / Other OO languages
[3046] Java Beans, tag libraries and JSPs - what and why.
[3045] After Course Resources - do we publish sample answers. Example from Java Exceptions module.
[3044] Changing a Servlet - more that just editing and compiling
Top or
Show all for Java and the Java Environment
[2923] Fresh air and beautiful places in Wiltshire
[2882] Seeing Wiltshire - from a Melksham base
[2830] Poulshot Village Fete
[2750] Views of Wessex
[2713] History is all around us
Top or
Show all for Around, about and nearby to Wiltshire
[3106] Buckets
[3105] Adventure with references to lists and lists of references
[3098] Learning Object Orientation in Perl through bananas and perhaps Moose
[3097] Making Perl class definitions more conventional and shorter
[3077] Perl 6 - significantly nearer, and Rakudo looks very good
Top or
Show all for The Perl Programming Language and its use
[3133] An image from a website that occasionally comes out as hyroglyphics
- (new - 2011-01-14)[3128] How does your browser find out about itself?
- (new - 2011-01-11)[2913] Six languages in one file - an HTML++ web page
[2675] Redirecting to your main domain for correct security keys
[2628] An example of an injection attack using Javascript
Top or
Show all for Client Side Languages (HTML, CSS, Javascript)
[3158] Ruby training - some fresh examples for string handling applications
- (new - 2011-02-05)[3156] Splitting data reading code from data processing code - Ruby
- (new - 2011-02-04)[3155] Rake - a build system using code written in Ruby
- (new - 2011-02-03)[3154] Changing a class later on - Ruby
- (new - 2011-02-02)[2980] Ruby - examples of regular expressions, inheritance and polymorphism
Top or
Show all for Ruby and Ruby on Rails
[3099] Perl - database access - DBD, DBI and DBIx modules
[3061] Databases - why data is split into separate tables, and how to join them
[3060] INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables
[3035] How to display information from a database within a web page
[2861] MySQL and Java - connectivity past, present, and future thoughts
Top or
Show all for SQL and MySQL
[3066] Separating groups of variables into namespaces
[3009] Expect in Perl - a short explanation and a practical example
[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
Top or
Show all for Tcl, Tcl/Tk and Expect
[3142] Private and Public - and things between
- (new - 2011-01-22)[2951] Lots of way of converting 3 letter month abbreviations to numbers
[2949] Lua - variable function arguments and select
[2947] Teaching Lua to a Perl advocate
[2727] Making a Lua program run more than 10 times faster
Top or
Show all for Programming in Lua
[3181] Beware - a=a+b and a+=b are different - Python
- (new - 2011-02-23)[3177] Insurance against any errors - Volcanoes and Python
- (new - 2011-02-19)[3159] Returning multiple values from a function call in various languages - a comparison
- (new - 2011-02-06)[3151] Disassembling Python and Java - previously compiled code
- (new - 2011-01-29)[3150] Python dictionaries - mutable and immutable keys and values
- (new - 2011-01-29)[3140] Django - separating the HTML from the view / model
- (new - 2011-01-20)[3139] Steering our Python courses towards wxPython, SQLite and Django
- (new - 2011-01-19)[3138] Django - adding your own views, and then templating your views.
- (new - 2011-01-18)[3136] A framework with python - Django - first steps
- (new - 2011-01-17)[3118] Arrays of arrays - or 2D arrays. How to program tables.
- (new - 2011-01-02)
Top or
Show all for Python Programming
[3185] Day Trip to Hereford, in pictures
- (new - 2011-02-26)[3184] Visiting relatives
- (new - 2011-02-26)[3175] The Rhine in winter
- (new - 2011-02-19)[3125] The family is defunct. Long live the family.
- (new - 2011-01-09)[3116] Are there newspapers on New Years Day? Do the shops open on Easter Sunday? Do trains run at Christmas?
- (new - 2011-01-01)
Top or
Show all for And also ...
[3187] Past and Present - Melksham Station
- (new - 2011-02-27)[3183] Redevelopment on the banks of the Avon in Melksham
- (new - 2011-02-25)[3178] The cost of roadworks on the economy of our town - 1800 pounds per hour?
- (new - 2011-02-20)[3176] Comparing German, Dutch and British Railways
- (new - 2011-02-19)[3171] Train and boat journey - the passenger accommodation
- (new - 2011-02-15)[3167] Can I take my dog by train? And other questions
- (new - 2011-02-12)[3161] TransWilts rail - what picture represents us
- (new - 2011-02-08)[3157] A new monopoly on the ferry to Northern Ireland
- (new - 2011-02-04)[3141] Wiltshire Rail services - a golden opportunity
- (new - 2011-01-21)[3135] A time to be brave? We should ask for what is best for our area.
- (new - 2011-01-16)[3126] Car Parking in Melksham - thoughts on the proposed scheme, and wider thoughts too
- (new - 2011-01-09)[3119] TransWilts - some things to see and do
- (new - 2011-01-03)[3114] Transwilts Link - both Wiltshire and beyond
- (new - 2010-12-30)[3113] Trowbridge and Melksham to Chippenham - more roadworks, even slower journey over the winter
- (new - 2010-12-30)[3111] TransWilts Link - Days out from Swindon to Weymouth?
- (new - 2010-12-28)
Top or
Show all for Public Transport
[3084] Can you trust the big brand names?
[3030] Liquorice allsorts and Dolly Mixtures
[3013] Audio equipment
[2945] Last, final, etc
[2944] What others cannot do in 10 months takes Virgin 10 minutes
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
[2896] LAMP - Linux, Apache, MySQL, PHP - install, configure, administer
[2831] Recording (a macro) in vi
[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
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?