The Well House Newsletter - Wednesday, 1st September 2010
About us and this newsletter [link] ...
Previous editions: July 2010May 2010March 2010January 2010November 2009September 2009July 2009May 2009March 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
[2900] Redirecting a page - silent, temporary or permanent? - (new - 2010-08-03)
[2768] Carrying a long URL around - looking for memorable shorts
[2753] You do not just fly - that is just part of the journey
[2728] Redirecting a home page using mod_rewrite
[2596] Http protocol - what does a web server send
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[2851] Further C++ material - view new or old - (new - 2010-07-04)
[2849] What are C++ references? Why use them? - (new - 2010-07-02)
[2848] C course - final course example puts it all together - (new - 2010-07-02)
[2845] Objects and Inheritance in C++ - an easy start - (new - 2010-07-01)
[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)
Top or Show all for C and C++ Programming

Melksham
[2932] Getting into and out of Wiltshire towns .. a.k.a. Car Parking? - (new - 2010-08-23)
[2902] Community consultation - a true open input - (new - 2010-08-04)
[2891] Wiltshire Council ask how they can help businesses - (new - 2010-07-27)
[2883] Melksham Oak - photos of the new community school - (new - 2010-07-22)
[2872] Moved - Melksham Lorry Park - (new - 2010-07-15)
[2869] Contact Information for Melksham Oak Community School - (new - 2010-07-13)
[2867] Cycling in Melksham, and looking forward - (new - 2010-07-11)
[2854] Melksham Food and Drink Fair and Town Crier Competition - (new - 2010-07-04)
[2853] Transport in Wessex - today and into the future - (new - 2010-07-04)
Top or Show all for Melksham

Training from Well House Consultants
[2942] Open Source Programming - Training Course Schedule - (new - 2010-08-31)
[2935] 01225 707126 to 01225 344596 to 01225 899360 - Well House Fax - (new - 2010-08-26)
[2934] Not so much software training - more hotel keeping! - (new - 2010-08-25)
[2928] Public (scheduled) or private course? Book direct, or through a third party? - (new - 2010-08-19)
[2927] Announcing 2011 Open Source Training courses - dates and prices - (new - 2010-08-18)
[2881] Tailoring of courses to meet customers needs - how it works - (new - 2010-07-21)
[2850] Fresh Paint for course presentation - including C++ - (new - 2010-07-03)
[2839] Software versions used - June 2010 - (new - 2010-06-30)
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[2940] Training course locations - Melksham, UK; Buxton, UK; Lake Constance, Germany; Venice Italy, the USA and India - (new - 2010-08-30)
[2938] An opportunity to join our team! - (new - 2010-08-28)
[2936] The service that customers should receive - (new - 2010-08-27)
[2924] Job applicants - wondering why they apply - (new - 2010-08-16)
[2916] Testing the robustness of our hotel and training systems - holiday and sickness times - (new - 2010-08-11)
[2911] Feeding the Grockles - (new - 2010-08-09)
[2910] Robust - testing the system - (new - 2010-08-09)
[2885] Twenty Questions - (new - 2010-07-24)
[2880] Getting in touch - Please allow me to see you when you are online - (new - 2010-07-21)
[2879] Night Porter and reception - 24 hours a day? - (new - 2010-07-20)
[2873] Another toot of the trumpet - (new - 2010-07-16)
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[2941] Wedding season in Melksham - somewhere good to stay - (new - 2010-08-31)
[2926] Journey times to Melksham, Wiltshire - (new - 2010-08-17)
[2925] Well House - the pictures - (new - 2010-08-16)
[2847] Local information for Melksham Hotel Guests - (new - 2010-07-02)
[2838] Respecting our customers anonimity
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[2906] Switching from Adobe Photoshop to Gimp - testing it on animals - (new - 2010-08-06)
[2895] Global Computer Maintenance Department - (new - 2010-07-29)
[2884] Hotlinked images onto adult material sites - (new - 2010-07-23)
[2823] Where have all the bloggers gone?
[2820] Netiquette for forum newcomers
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[2922] Getting the OO design write - with PHP a example - (new - 2010-08-14)
[2909] Be gentle rather than macho ... regular expression techniques - (new - 2010-08-08)
[2898] Programming Standards from the start! - (new - 2010-08-02)
[2865] Relationships between Java classes - inheritance, packaging and others - (new - 2010-07-10)
[2844] Learning about Regular Expressions in C through examples - (new - 2010-06-30)
Top or Show all for General Programming Topics

PHP - the language and its application
[2939] Protecting your images from use out of context - (new - 2010-08-29)
[2921] Does copying a variable duplicate the contents? - (new - 2010-08-14)
[2918] Downloading a report from the web for further local analysis - (new - 2010-08-13)
[2917] Upload Image, Store in database, redisplay in browser. PHP and MySQL - (new - 2010-08-12)
[2912] Predictions for the seagull population - (new - 2010-08-09)
Top or Show all for PHP - the language and its application

Java and the Java Environment
[2863] Writing a server in Java - (new - 2010-07-09)
[2862] Fail Safe Error Handling in Java via Exceptions - (new - 2010-07-09)
[2860] What methods are available on this Java object? - (new - 2010-07-08)
[2859] Using java, javac, jar, and CLASSPATH - a simple example - (new - 2010-07-07)
[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 - (new - 2010-08-15)
[2882] Seeing Wiltshire - from a Melksham base - (new - 2010-07-21)
[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
[2877] Further more advanced Perl examples - (new - 2010-07-19)
[2876] Different perl examples - some corners I rarely explore - (new - 2010-07-18)
[2874] Unpacking a Perl string into a list - (new - 2010-07-16)
[2840] Just pass a pointer - do not duplicate the data - (new - 2010-06-30)
[2836] Perl - the duplicate key problem explained, and solutions offered
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 - (new - 2010-08-10)
[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
[2893] Exclamation marks and question marks on ruby method names - (new - 2010-07-28)
[2892] Alternative loops and conditionals in Ruby and Perl - (new - 2010-07-28)
[2866] Ruby - how does it compare and where is it the right language? - (new - 2010-07-11)
[2826] Ruby - training for automated testing users
[2714] A simple example - XML from a Ruby program
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[2861] MySQL and Java - connectivity past, present, and future thoughts - (new - 2010-07-09)
[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
[2643] Relating tables with joins in MySQL
[2567] Extra MySQL course dates (2 day course, UK)
[2561] The future of MySQL
[2458] Cant connect to local MySQL server through socket /tmp/mysql.sock
[2448] MySQL - efficiency and other topics
[2447] MySQL stored procedures / their use on the web from PHP
[2446] Learn about MySQL stored procedures
[2445] Securing MySQL on a production server
[2444] Potted MySQL installation
[2426] Which version of MySQL am I running?
[2381] Checking the database connection manually
[2263] Mysqldump fails as a cron job - a work around
[2259] Grouping rows for a summary report - MySQL and PHP
[2240] How do I query a database (MySQL)?
[2210] MySQL server replication
[2209] Monitoring and Tuning your MySQL installation
[2204] Images in a database? How big is a database? (MySQL)
[2172] PHP4 v PHP5 - Object Model Difference
[2134] Oracle take over Sun who had taken over MySQL
[2110] MySQL - looking for records in one table that do NOT correspond to records in another table
[2085] MySQL - licensing issues, even with using the name
[2053] What a difference a MySQL Index made
[1935] Summary of MySQL installation on a Linux system
[1885] Hiding a MySQL database behind a web page
[1771] More HowTo diagrams - MySQL, Tomcat and Java
[1766] Diagrams to show you how - Tomcat, Java, PHP
[1754] Upgrade from PHP 4 to PHP 5 - the TRY issue
[1735] Finding words and work boundaries (MySQL, Perl, PHP)
[1731] Apache httpd, MySQL, PHP - installation procedure
[1724] addslashes v mysql_real_escape_string in PHP
[1689] Some sideways thoughts on the news
[1575] Database design for a shopping application (MySQL)
[1574] Joining MySQL tables revisited - finding nonmatching records, etc
[1561] Uploading to a MySQL database through PHP - examples and common questions
[1518] Downloading data for use in Excel (from PHP / MySQL)
[1455] Connecting to MySQL 5 from PHP on Mac OSX Leopard
[1450] Easy selection of multiple SQL conditions from PHP
[1423] MySQL - table design and initial testing example
[1417] What software version do we teach?
[1381] Using a MySQL database to control mod_rewrite via PHP
[1331] MySQL joins revisited
[1235] Outputting numbers as words - MySQL with Perl or PHP
[1213] MySQL - the order of clauses and the order of actions
[1131] MySQL - Password security (authentication protocol)
[1123] mysqldump and mysqlrestore
[1095] Apache httpd , browser, MySQL and MySQL client downloads
[947] What is an SQL injection attack?
[937] Display an image from a MySQL database in a web page via PHP
[924] The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl
[907] Browser -> httpd -> Tomcat -> MySQL. Restarting.
[723] Viewing images held in a MySQL database via PHP
[673] Helicopter views and tartans
[666] Database design - get it right from first principles
[647] Checking for MySQL errors
[644] Using a MySQL database from Perl
[591] Key facts - SQL and MySQL
[581] Saving a MySQL query results to your local disc for Excel
[572] Giving the researcher power over database analysis
[567] Combining similar rows from a MySQL database select
[535] MySQL permissions and privileges
[517] An occasional chance, and reducing data to manageable levels
[515] MySQL - an FAQ
[513] MySQL - JOIN or WHERE to link tables correctly?
[502] SELECT in MySQL - choosing the rows you want
[494] MySQL - a score of things to remember
[489] Which MySQL server am I using?
[449] Matching in MySQL
[401] What is an SQL injection attack?
[375] Oops - I got my initial database design wrong
[361] Binary Large Objects or bars
[334] Symbolic links and hard links
[279] Getting a list of unique values from a MySQL column
[270] NULL in MySQL
[193] The wrong MySQL
[192] Current MySQL and PHP paths and upgrades
[175] Worthwhile
[159] MySQL - Optimising Selects
[158] MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN
[104] mysql_connect or mysql_pconnect in PHP?
[85] Present and future MySQL
[84] MySQL - nuggets
[59] MySQL - Pivot tables
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[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

Programming in Lua
[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

Python Programming
[2929] Passing a variable number of parameters in to a function / method - (new - 2010-08-20)
[2920] Sorting - naturally, or into a different order - (new - 2010-08-14)
[2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (new - 2010-08-11)
[2905] Defining static methods in Python - (new - 2010-08-05)
[2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (new - 2010-08-02)
[2894] Sorting people by their names - (new - 2010-07-29)
[2890] Dates and times in Python - (new - 2010-07-27)
[2889] Should Python classes each be in their own file? - (new - 2010-07-27)
[2887] Snow Leopard and Python (that is OS X 10.6 and wxPython) - (new - 2010-07-26)
[2878] Program for reliability and efficiency - do not duplicate, but rather share and re-use - (new - 2010-07-19)
[2871] Moving from Python 2.6 to Python 3 - (new - 2010-07-14)
Top or Show all for Python Programming

And also ...
[2914] Older picture. - (new - 2010-08-10)
[2907] Dartmouth, Kingswear and Torbay - (new - 2010-08-07)
[2904] Melksham Area Board meeting of last week - (new - 2010-08-04)
[2897] The Land of the Black Labrador - (new - 2010-08-01)
[2888] Recent Pictures - (new - 2010-07-27)
[2886] Congratulations, Kimberly - (new - 2010-07-25)
[2875] A long day in Melksham ... - (new - 2010-07-17)
[2870] Old prices - what would the equivalent price have been in 1966? - (new - 2010-07-14)
[2868] A move towards the family - (new - 2010-07-12)
[2864] Changing with weather and seasons - (new - 2010-07-10)
[2856] Two sides of the coin - (new - 2010-07-06)
[2852] Atworth Village Fete - on the Melksham Community Area Partnership stand - (new - 2010-07-04)
[2846] Catching up with an old friend - (new - 2010-07-01)
Top or Show all for And also ...

Public Transport
[2933] Bath - Melksham - Devizes buses from September - (new - 2010-08-23)
[2931] Syncronise - software, trains, and buses. Please! - (new - 2010-08-22)
[2930] Walk - Tilehurst to Pangborne - (new - 2010-08-21)
[2919] London to Calne, Corsham, Melksham, Bradford-on-Avon, Chippenham by public Transport - (new - 2010-08-13)
[2908] How Green is my train? - (new - 2010-08-07)
[2903] Bath to Devizes bus via Melksham - changing again in September - (new - 2010-08-04)
[2901] Ambassador or Anorak? - (new - 2010-08-03)
[2858] The healthy option - away from the private car - (new - 2010-07-07)
[2857] Park and Ride at Batheaston - will it solve Wiltshires Ills? - (new - 2010-07-06)
[2855] Train Services - Melksham to Bath and Bristol (and airport) - (new - 2010-07-05)
Top or Show all for Public Transport

Fun and Flames
[2937] The cat in the dustbin - (new - 2010-08-27)
[2788] Cost of Sales
[2761] A small business, facing a big government questionnaire
[2676] Changing Times
[2626] On Malachite Green
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 - (new - 2010-07-30)
[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 July 2010May 2010March 2010January 2010November 2009September 2009July 2009May 2009March 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