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
[3252] C++ - unknown array size, unknown object type. Help!
- (new - 2011-04-17)[3250] C++ - how we teach the language and the concepts behind the language
- (new - 2011-04-17)[3245] Collections in C and C++ - arrays, vectors and heap memory blocks
- (new - 2011-04-12)[3244] C and C++ - preprocess, compile, load, run - what each step is for
- (new - 2011-04-12)[3243] Breaking the running sequence - an introduction to conditional statements and loops
- (new - 2011-04-11)[3242] How to return 2 values from a function (C++ and C) - more uses of pointers
- (new - 2011-04-10)[3238] Bradshaw, Ben and Bill. And some C and C++ pointers and references too.
- (new - 2011-04-09)[3236] C - a first program that does something useful for you
- (new - 2011-04-09)[3234] Your program - you just provide the filling in the sandwich
- (new - 2011-04-08)
Top or
Show all for C and C++ Programming
[3258] Morning in Melksham
- (new - 2011-04-23)[3249] Events - Spring and Early Summer 2011 in Melksham
- (new - 2011-04-17)[3248] What have these pictures in common?
- (new - 2011-04-16)[3246] Melksham - the way forward. 26th April, Well House Manor
- (new - 2011-04-13)[3239] TrainWest, 2011 in pictures - Christie Miller, Bowerhill, Melksham
- (new - 2011-04-09)[3232] Around and about Melksham in more pictures
- (new - 2011-04-05)[3230] Whaddon - near us and yet so remote from us
- (new - 2011-04-03)[3229] Coincidence, or naturally repeating event?
- (new - 2011-04-03)[3227] Her favourite store
- (new - 2011-04-02)[3225] Campus - answer to business questions
- (new - 2011-04-01)[3221] How long is a speech?
- (new - 2011-03-29)[3217] Vandalism and riot from the minority - the effect
- (new - 2011-03-28)[3214] Melksham Campus - any last minute inputs from Melksham businesses?
- (new - 2011-03-26)[3209] Seeing Electricity Pylons near Melksham
- (new - 2011-03-21)[3199] Lunch for Melksham Businesses
- (new - 2011-03-11)[3194] Buses - what they cost and their future direction in the SW and in Wiltshire
- (new - 2011-03-06)[3193] Melksham Campus - what, why, questions, concerns and how you can input
- (new - 2011-03-04)[3188] What proportion of the British Workforce still works a Monday to Friday, 9 to 5, week?
- (new - 2011-03-01)
Top or
Show all for Melksham
[3259] Our library in Melksham
- (new - 2011-04-23)[3235] How we make our programming courses both time and cost effective
- (new - 2011-04-09)[3233] C / C++ Course Lunch - sitting out at the West End
- (new - 2011-04-07)[3219] How do I become a Linux System Administrator?
- (new - 2011-03-28)[3205] Open Source (Public) courses - PHP, Tcl, SQL, Python, C and C++ in Melksham, Wiltshire, UK
- (new - 2011-03-18)[3196] No news is good news.
- (new - 2011-03-07)
Top or
Show all for Training from Well House Consultants
[3271] The importance of feedback
- (new - 2011-04-30)[3201] A change to the Well House team - thank you and good luck, Chris
- (new - 2011-03-14)[3165] Journalism 101
[3164] Brown - or Mrs Sally Brown, accountant from Whitstable?
[3153] Points West to Belfast
Top or
Show all for Running a training and hotel company
[3263] Come as a customer, leave as a friend - Well House Manor, Hotel, Wiltshire
- (new - 2011-04-24)[3212] Well House Manor - a home from home for the business and leisure guest in Melksham
- (new - 2011-03-26)[3202] Telling you something about us in just one line
- (new - 2011-03-15)[3134] Melksham Weather - Warm and windy becoming colder and calmer
[3115] Perl, Python, PHP, Lua, Linux, and more - and business hotel too. Menu for 2011
Top or
Show all for Well House Manor - Hotel and Training Centre
[3222] Clickjacking - another way to get you to follow a malicious link - Facebook issue
- (new - 2011-03-29)[3208] Links for social media, microblogs and business networking
- (new - 2011-03-20)[3190] What do the following web sites have in common?
- (new - 2011-03-03)[3179] Oops - I typed ci not vi, and have lost my file ...
[3174] Sharing a single hotel internet connection without carrying extra hardware
Top or
Show all for For the Webmaster, Postmaster and moderator
[3262] Some SVG Elements, pixel and percent positioning
- (new - 2011-04-24)[3261] Scalable Vector Graphics - easy, low bandwidth, high resolution, dynamic.
- (new - 2011-04-23)[3251] C++ - objects that are based on other objects, saving coding and adding robustness
- (new - 2011-04-17)[3237] Using functions to keep look and feel apart from calculations - simple C example
- (new - 2011-04-09)[3213] Should I use Open Source or Commercial software?
- (new - 2011-03-26)[3211] Computer Graphics in PHP - World (incoming data) to Pixel (screen) conversion
- (new - 2011-03-24)
Top or
Show all for General Programming Topics
[3210] Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON
- (new - 2011-03-22)[3197] Finding and diverting image requests from rogue domains
- (new - 2011-03-08)[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
[3143] On time
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
[3267] Reybridge, Easter Monday
- (new - 2011-04-27)[3247] Light and dark at Green Park
- (new - 2011-04-14)[3206] Wiltshire College / Lackham College - the animals
- (new - 2011-03-19)[2923] Fresh air and beautiful places in Wiltshire
[2882] Seeing Wiltshire - from a Melksham base
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
[3128] How does your browser find out about itself?
[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)
[3260] Ruby - a training example that puts many language elements together to demonstrate the whole
- (new - 2011-04-23)[3255] Process every member of an array, and sort an array - Ruby
- (new - 2011-04-21)[3254] Multiple inputs, multiple out, ruby functions
- (new - 2011-04-19)[3253] Is this number between? Does this list include? - Ruby
- (new - 2011-04-18)[3158] Ruby training - some fresh examples for string handling applications
Top or
Show all for Ruby and Ruby on Rails
[3270] SQL - Data v Metadata, and the various stages of data selection
- (new - 2011-04-29)[3269] Files or Databases? MySQL, SQLite, or Oracle?
- (new - 2011-04-28)[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
Top or
Show all for SQL and MySQL
[3192] Tcl - Some example of HOW TO in handling data files and formats
- (new - 2011-03-04)[3189] Tcl - the danger of square brackets in a while command
- (new - 2011-03-02)[3066] Separating groups of variables into namespaces
[3009] Expect in Perl - a short explanation and a practical example
[2681] Tcl - a great engineering language
Top or
Show all for Tcl, Tcl/Tk and Expect
[3142] Private and Public - and things between
[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
[3257] All possible combinations from a list (Python) or array (Ruby)
- (new - 2011-04-23)[3218] Matching a license plate or product code - Regular Expressions
- (new - 2011-03-28)[3200] How a for loop works Java, Perl and other languages
- (new - 2011-03-12)[3181] Beware - a=a+b and a+=b are different - Python
[3177] Insurance against any errors - Volcanoes and Python
Top or
Show all for Python Programming
[3268] Baby Pictures
- (new - 2011-04-27)[3265] Alternative Vote (AV) - cutting the crap
- (new - 2011-04-25)[3264] Alternative Vote (AV) - explaining and an example
- (new - 2011-04-25)[3241] Spring in the countryside near Melksham
- (new - 2011-04-10)[3240] Melksham Town Council - vacancy in the Spa Ward
- (new - 2011-04-10)[3224] Melksham Campus - a win / win opportunity, but a severely lacking decision process
- (new - 2011-03-31)[3220] Panasonic Lumix TZ20
- (new - 2011-03-28)[3207] Lambing at Lackham
- (new - 2011-03-19)[3204] Two views of a war memorial
- (new - 2011-03-17)[3195] Sunny day - Clanger and Picket Woods, Shearwater, and Westbury
- (new - 2011-03-06)[3191] Date of the Census (which month and day?)
- (new - 2011-03-03)
Top or
Show all for And also ...
[3266] Easter on the Canal - near Melksham, Wiltshire
- (new - 2011-04-26)[3231] Footpath, Bridleway, Byway, Road used as Public Path
- (new - 2011-04-04)[3228] What can you take on a public footpath? Pram? Wheelbarrow? Dog? Shopping Trolley? Horse? Cycle?
- (new - 2011-04-03)[3216] Images of a Spring Walk
- (new - 2011-03-27)[3198] TransWilts rail - coming together, wanted and needed
- (new - 2011-03-10)[3187] Past and Present - Melksham Station
- (new - 2011-02-27)
Top or
Show all for Public Transport
[3226] A busy morning for railway announcements
- (new - 2011-04-01)[3223] Answering at my earliest convenience
- (new - 2011-03-29)[3215] Solution looking for problem
- (new - 2011-03-27)[3203] Melksham Town Council announces ...
- (new - 2011-03-16)[3084] Can you trust the big brand names?
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
[3256] Displaying a directory or file system tree - Linux
- (new - 2011-04-22)[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
[2599] Telling Apache web servers apart / notes for the non-technical
[2595] Twelve skills / knowledges needed for the design of a web site
[2494] Making Linux Politically correct
[2491] Root is root for a reason!
[2479] Accidentally typed ci rather than vi?
[2301] Mistaken identity?
[2300] What does x on a linux directory mean?
[2299] How much space does my directory take - Linux
[2203] Always use su with minus. And where do programs come from?
[2201] Running straight from the jar, but not from a tar
[2182] What Linux run level am I in?
[2150] Routers, Firewalls and multilayer servers
[2149] Routing Network Traffic - Proxies, Redirects and DNS
[2139] OS Commerce install made simple
[2130] Javascript - move cursor over image to change a different image.
[2117] Choosing a railway station fairly in PHP
[2035] 1234567890 ... coming up on Friday 13th
[2023] sw_vers - what version of OSX am I running?
[1903] daemons - what is running on my Linux server?
[1902] sstrwxrwxrwx - Unix and Linux file permissions
[1893] Some Linux and Unix tips
[1803] FTP passive mode - a sometimes cure for upload hangs
[1801] Will your backups work if you have to restore them?
[1774] What is my real and my effective ID? [Linux]
[1765] Dialects of English and Unix
[1764] Yank and Push - copy and move in vi
[1719] A special day - last Friday in July
[1712] As different as night and tyres
[1700] FTP server on Fedora Linux
[1690] Conversion of c/r line ends to l/f line ends
[1666] Slow boot and terminal start on Linux boxes
[1660] Korn shell - some nuggets
[1659] String, Integer, Array, Associative Array - ksh variables
[1658] Some useful variables and settings in the Korn Shell
[1651] ls command - favourite options
[1650] Looking for files with certain characteristics (Linux / Unix)
[1648] The tourists guide to Linux
[1592] Setting up a new user - Linux or Unix
[1527] Selecting file names in a shell - one word or another
[1439] Linux / Unix - layout of operating system files
[1438] Copy and paste / cut and paste and other vi techniques
[1408] Wireless hotel tips - FTP and Skype connections failing
[1367] korn tips - some useful korn shell techniques
[1366] awk - a powerful data extraction and manipulation tool
[1361] Korn shell course
[1288] Linux run states, shell special commands, and directory structures
[1259] Where am I and how did I get here?
[1028] Linux / Unix - process priority and nice
[1023] Finding public writeable things on your linux file system
[1013] Copy multiple files - confusing error message from cp
[1012] Moving files between Windows / DOS and Linux / Unix
[984] Cardinal numbers and magic numbers
[827] No news is good news with Unix and Linux
[770] Splash!
[768] Our new .eu top level domain
[735] Boys will be boys, saved by Ubuntu
[711] THE home directory or MY home directory
[705] Disc Partitioning
[703] Copying files and preserving ownership
[686] Name Services - telling your LDAP from your DNS
[683] Supporting users on Linux and Unix
[679] More or less on the edge of the page
[593] Finding where the disc space has gone
[544] Repeating tasks with crontab
[511] Domain Forwarding - 2 ways of doing it
[506] What are DHCP and DNS?
[476] May I be politically incorrect?
[442] How far away is that server?
[431] File permissions of Linux and Unix systems
[430] Linux commands - some basics
[367] Ajax
[267] Searching security holes
[249] An easy way out
[166] Acronyms
[153] Linux - where to put swap space
[152] Aladdin, or careful what you wish.
[74] pushd and popd
[73] vi - full circle
[71] Comparators in Linux and Unix
[64] Shell Script for CGI on the web
[63] Almost like old times
[37] Security and Safety
[34] Linux / LAMP course
[11] A bolt of lightning on Multicasting
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?