The Well House Newsletter - Monday, 1st November 2010
About us and this newsletter [link] ...
Previous editions: September 2010July 2010May 2010March 2010January 2010November 2009September 2009July 2009May 2009 • or current edition

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
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 ...

Apache HTTP and Tomcat Servers
[3019] Apache httpd Server Status - monitoring your server - (new - 2010-10-28)
[3018] Tuning Apache httpd and Tomcat to work well together - (new - 2010-10-27)
[3015] Logging the performance of the Apache httpd web server - (new - 2010-10-25)
[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

C and C++ Programming
[2851] Further C++ material - view new or old
[2849] What are C++ references? Why use them?
[2848] C course - final course example puts it all together
[2845] Objects and Inheritance in C++ - an easy start
[2843] String functions in C
Top or Show all for C and C++ Programming

Melksham
[2995] A river in Melksham is not just for boaters. - (new - 2010-10-11)
[2984] Customer Review - Hotel Room, Melksham - (new - 2010-10-03)
[2959] A Melksham news roundup - (new - 2010-09-18)
[2957] Welcome to Countrywides new Melksham store - (new - 2010-09-15)
[2954] Railway meetings, trips and meetups this autumn - (new - 2010-09-12)
Top or Show all for Melksham

Training from Well House Consultants
[3021] Courses for late 2010 and early 2011 - (new - 2010-10-30)
[3001] How will we present courses over the coming years? - (new - 2010-10-17)
[3000] Looking forward - the next 3000 - (new - 2010-10-16)
[2999] 2999 - looking back - (new - 2010-10-15)
[2987] Memorial to a day in 1999 - (new - 2010-10-06)
[2968] Well House Consultants - a potted history - (new - 2010-09-23)
[2965] Testimonials - Well House Consultants Open Source courses - (new - 2010-09-21)
[2956] On site course - travel and accommodation expenses - (new - 2010-09-14)
[2942] Open Source Programming - Training Course Schedule - (new - 2010-08-31)
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[3024] Testing the new pavement ready for Christmas - (new - 2010-10-31)
[3014] Well House Manor - the next six years - (new - 2010-10-24)
[2966] Cheap Country Hotel in Melksham, Wiltshire? - (new - 2010-09-21)
[2961] Initial handling of phone calls and walk in visitors - (new - 2010-09-19)
[2960] The Well House team - September 2010 - (new - 2010-09-19)
[2952] Concluding the interview process - (new - 2010-09-10)
[2946] Level playing fields, job vacancies, lemons and peaches - (new - 2010-09-05)
[2940] Training course locations - Melksham, UK; Buxton, UK; Lake Constance, Germany; Venice Italy, the USA and India - (new - 2010-08-30)
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[2962] Well House Manor - the history of the hotel - (new - 2010-09-20)
[2943] Our facilities to support Well House Consultants Courses - (new - 2010-09-02)
[2941] Wedding season in Melksham - somewhere good to stay - (new - 2010-08-31)
[2926] Journey times to Melksham, Wiltshire
[2925] Well House - the pictures
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[3022] Retaining web site visitors - reducing the one page wonders - (new - 2010-10-31)
[3016] The legal considerations of your web presence - revisited - (new - 2010-10-26)
[2988] Not mugged in London! - (new - 2010-10-08)
[2906] Switching from Adobe Photoshop to Gimp - testing it on animals
[2895] Global Computer Maintenance Department
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[3003] What will we be teaching in six years? - (new - 2010-10-17)
[2973] Learning to program - where to start if you have never programmed before - (new - 2010-09-28)
[2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (new - 2010-09-21)
[2953] Turning an exercise into the real thing with extreme programming - (new - 2010-09-11)
[2922] Getting the OO design write - with PHP a example
Top or Show all for General Programming Topics

PHP - the language and its application
[3020] Handling (expanding) tabs in PHP - (new - 2010-10-29)
[2981] How to set up short and meaningfull alternative URLs - (new - 2010-10-02)
[2939] Protecting your images from use out of context
[2921] Does copying a variable duplicate the contents?
[2918] Downloading a report from the web for further local analysis
Top or Show all for PHP - the language and its application

Java and the Java Environment
[2863] Writing a server in Java
[2862] Fail Safe Error Handling in Java via Exceptions
[2860] What methods are available on this Java object?
[2859] Using java, javac, jar, and CLASSPATH - a simple example
[2735] Type checking, Java arrays and collections
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[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

The Perl Programming Language and its use
[3012] Exception handling in Perl - using eval - (new - 2010-10-23)
[3011] What are .pid files? - (new - 2010-10-23)
[3010] Children, zombies, and reaping processes - (new - 2010-10-23)
[3007] Setting up a matrix of data (2D array) for processing in your program - (new - 2010-10-21)
[3005] Lots of ways of doing it in Perl - printing out answers - (new - 2010-10-19)
[3004] Increment operators for counting - Perl, PHP, C and others - (new - 2010-10-18)
[2972] Some more advanced Perl examples from a recent course - (new - 2010-09-27)
[2970] Perl - doing several things at the same time - (new - 2010-09-25)
[2969] What does blessing a variable in Perl mean? - (new - 2010-09-24)
[2967] Multiway branches in Perl - the given and when syntax - (new - 2010-09-22)
[2963] Removing the new line with chop or chomp in Perl - what is the difference? - (new - 2010-09-21)
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[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
[2554] Adding retrospective ALT attributes to IMG
[2390] Dynamic / changing images on your web page
Top or Show all for Client Side Languages (HTML, CSS, Javascript)

Ruby and Ruby on Rails
[2980] Ruby - examples of regular expressions, inheritance and polymorphism - (new - 2010-10-02)
[2979] Ruby - yield; parallel routines - (new - 2010-10-01)
[2977] What is a factory method and why use one? - Example in Ruby - (new - 2010-09-30)
[2976] Creating, extending, traversing and combining Ruby arrays - (new - 2010-09-30)
[2975] Why do I need brackets in Ruby ... or Perl, Python, C or Java - (new - 2010-09-29)
[2974] Formatting your output - options available in Ruby - (new - 2010-09-29)
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[2861] MySQL and Java - connectivity past, present, and future thoughts
[2749] Delegate Question - defining MySQL table relationships as you create the tables
[2647] Removing duplicates from a MySQL table
[2645] Optimising and caching your MySQL enquiries
[2644] Counting rows in joined MySQL tables
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[3009] Expect in Perl - a short explanation and a practical example - (new - 2010-10-22)
[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
[2471] A short form of if ... then ... else
[2468] What are Tcl lists?
[2467] Tcl - catching an error before your program crashes
[2466] Tcl - passing arrays and strings in and back out of procs
[2463] Tcl - a true interpretive, command based language
[2429] Tcl scripts / processes on a web server via CGI
[2261] Tcl - nice and nasty
[2211] Tcl/Tk - why does the canvas widget use a display list?
[2040] Error: Cant read xxxxx: no such variable (in Tcl Tk)
[1785] What is running on your network? (tcl and expect)
[1782] Calling procs in Tcl and how it compares to Perl
[1614] When an array is not an array
[1613] Regular expression for 6 digits OR 25 digits
[1602] Automating processes through Expect
[1601] Replacing the last comma with an and
[1531] Expecting a item from a list of possibles
[1529] Tcl - learning how to use namespaces, packages and libraries together
[1528] Object Oriented Tcl
[1475] Tcl/Tk - updating your display while tasks are running
[1474] Using Tcl/Tk resource files for flexible applications
[1473] Making a variable dynamically visible in a Tcl/Tk GUI
[1471] Cliff Lift simulator- Lynton to Lynmouth - in Tcl/Tk
[1470] fill and expand on Tcl/Tk pack command
[1469] Curley brackets v double quotes - Tcl, Tk, Expect
[1467] stdout v stderr (Tcl, Perl, Shell)
[1427] Arrays in Tcl - a demonstration
[1426] Buffering up in Tcl - the empty coke can comparison
[1412] Sparse and Greedy matching - Tcl 8.4
[1411] Buffering of inputs to expect, and match order
[1410] Tcl / regsub - changing a string and using interesting bits
[1409] What is Expect?
[1407] Reading from another process in Tcl (pipes and sockets)
[1405] Sorting in Tcl - lists and arrays
[1404] Tcl - global, upvar and uplevel.
[1403] Square Bracket protection in Tcl
[1402] Tcl - append v lappend v concat
[1401] Tcl - using [] or {} for conditions in an if (and while)
[1339] Packages and Namespaces are like Suitcases and Aircraft
[1338] Handling Binary data in Tcl (with a note on C)
[1335] Expanding a grid - Tcl/Tk
[1334] Stable sorting - Tcl, Perl and others
[1327] Tktable - Laying out data in a matrix - Tcl/Tk
[1283] Generating traffic for network testing
[1282] Stringing together Tcl scripts
[1277] AgtInvoke - a command to drive Agilent Tcl software extensions
[1268] Changes in advertising cut lines / Buscot / Tcl course
[1174] Installing Tcl and Expect on Solaris 10 - a checklist
[1173] Cheat Sheet / Check list for Expect maintainers
[1092] Tcl training - often for a larger group
[787] Tk - laying out your GUI with frames, pack and grid
[785] Running external processes in Tcl and Tcl/Tk
[782] Converting between Hex and Decimal in Tcl
[781] Tcl - lappend v concat
[779] The fragility of pancakes - and better structures
[691] Testing you Perl / PHP / MySQL / Tcl knowledge
[675] Adding PHP tags to an old cgi program
[596] The magic of -textvariable
[461] Shortened interactive commands
[445] Sticky news
[435] Expect for Windows
[409] Functions and commands with dangerous names
[404] How to check that a string contains a number in Tcl
[366] Error handling in Tcl through catch
[364] pu daily and p hourly
[362] The ireallyreallywanna operator
[349] Comments in Tcl
[309] Writing a Tcl/Tk GUI is as easy as baking a cake
[290] Object Orientation in Tcl - [incr-Tcl]
[287] Checking that all our servers are up and accessible
[286] Automating regular manual procedures
[212] Tcl/Tk (wish) Grid layout example
[210] Joining lists in Tcl. Indirect variables in Tcl.
[146] example of Tcl namespaces and packages
[144] Tcl sandwich - lists in Tcl
[133] Tcl embeds
[122] Passing arrays to procs in Tcl
[3] Looking for a donkey
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[2951] Lots of way of converting 3 letter month abbreviations to numbers - (new - 2010-09-10)
[2949] Lua - variable function arguments and select - (new - 2010-09-08)
[2947] Teaching Lua to a Perl advocate - (new - 2010-09-06)
[2727] Making a Lua program run more than 10 times faster
[2723] Returning multiple values from a function - Lua
Top or Show all for Programming in Lua

Python Programming
[3002] A list of special method and attribute names in Python - (new - 2010-10-17)
[2998] Using an exception to initialise a static variable in a Python function / method - (new - 2010-10-13)
[2997] 3D graphics - web site usage - simple matplotlib and python example - (new - 2010-10-12)
[2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (new - 2010-10-12)
[2994] Python - some common questions answered in code examples - (new - 2010-10-10)
[2993] Arrays v Lists - what is the difference, why use one or the other - (new - 2010-10-10)
[2992] Matplotlib - graphing in Python - teaching examples - (new - 2010-10-10)
[2991] Loading and saving data - Python / numpy - (new - 2010-10-09)
[2990] What are numpy and scipy? - (new - 2010-10-09)
[2986] Python dictionaries - reaching to new uses - (new - 2010-10-05)
Top or Show all for Python Programming

And also ...
[3008] Dulwich College Preparatory, and Sevenoaks, Schools - (new - 2010-10-21)
[2989] Oddballs in Plymouth - (new - 2010-10-08)
[2985] Right place, right season - (new - 2010-10-04)
[2982] Travel, Transport and Tourism - A vision for Melksham, 2026 - (new - 2010-10-03)
[2978] Christmas 2010 - Well House Manor, Melksham, Hotel - (new - 2010-10-01)
[2971] Should the public sector compete with businesses? and other deep questions - (new - 2010-09-26)
[2948] Melksham shamefully makes the national headlines - (new - 2010-09-07)
Top or Show all for And also ...

Public Transport
[3023] Autumn walk from Bowerhill - (new - 2010-10-31)
[3017] Seventh day traveller on the six day railway - (new - 2010-10-27)
[3006] Santa announcement, 5th December 2010, Melksham - (new - 2010-10-20)
[2983] Strong arm tactics in the bus industry? Poor result for the customer! - (new - 2010-10-03)
[2958] What do these road markings mean? Could Confusion Kill? - (new - 2010-09-17)
[2955] Melksham Railway Station - new information point - (new - 2010-09-13)
[2950] Camilla, Duchess of Cornwall, turns first sod in Melksham Link Canal - (new - 2010-09-09)
Top or Show all for Public Transport

Fun and Flames
[3013] Audio equipment - (new - 2010-10-24)
[2945] Last, final, etc - (new - 2010-09-04)
[2944] What others cannot do in 10 months takes Virgin 10 minutes - (new - 2010-09-03)
[2937] The cat in the dustbin
[2788] Cost of Sales
Top or Show all for Fun and Flames

Keynote Articles
[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

Linux and Shell Programming
[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?

go to Top or other editions September 2010July 2010May 2010March 2010January 2010November 2009September 2009July 2009May 2009 • or current edition


Training sample © 2025, WELL HOUSE CONSULTANTS LTD
This is http://www.wellho.net/demo/newsletter.php
Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
Phone: +44 (0) 1225 708 225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net