The Well House Newsletter - Friday, 1st January 2010
About us and this newsletter [link] ...
Previous editions: November 2009September 2009July 2009May 2009March 2009January 2009November 2008September 2008July 2008 • 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
[2552] Web site traffic - real users, or just noise? - (new - 2009-12-26)
[2482] Load balancing with sticky sessions (httpd / Tomcat)
[2355] See this page in French
[2325] Apache, Tomcat, mod_proxy
[2273] Three recent questions on Tomcat Convertors
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[2086] C Programming v Learning to Program in C. Which course?
[2005] Variables and pointers and references - C and C++
[2004] Variable Scope in C++
[2002] New C Examples - pointers, realloc, structs and more
[1675] Comparing Objects in C++
Top or Show all for C and C++ Programming

Melksham
[2546] How well do you know Melksham - a quiz for Christmas - (new - 2009-12-21)
[2544] Vision for Wiltshire - (new - 2009-12-20)
[2540] Rock and hard place .. and the relaxing right one won - (new - 2009-12-18)
[2531] Melksham - new Tuesday Market - (new - 2009-12-09)
[2524] An update on legal changes from the FSB? - (new - 2009-12-03)
[2521] Melksham Market - Tuesdays, 09:00 to 14:00 - (new - 2009-12-01)
[2517] Blogging accuracy - open invitation for any corrections - (new - 2009-11-29)
[2514] The road show has been - where now? - (new - 2009-11-27)
[2512] Kim of the Castle - (new - 2009-11-25)
[2508] Community Area Partnership - inaugural AGM - (new - 2009-11-20)
[2497] Brown horses in Melksham - (new - 2009-11-08)
[2495] Planning the future of Wiltshire - (new - 2009-11-07)
[2487] Melksham Forum - (new - 2009-11-01)
Top or Show all for Melksham

Training from Well House Consultants
[2548] Ten years ago, we moved to Melksham Spa - (new - 2009-12-24)
[2541] VAT Changes - (new - 2009-12-19)
[2534] And now for some posts a bit more technical - (new - 2009-12-12)
[2366] At the end of the course
[2354] Training, Open Source computer languages
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[2530] Taking a knock over Santa - (new - 2009-12-08)
[2502] Monday night, Tuesday night - (new - 2009-11-13)
[2441] Not your cup of tea?
[2413] Sanity checking the price, and selling up to increase income
[2396] Easing off in our 50s?
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[2538] Open Source Training Centre and Courses for 2010 - (new - 2009-12-16)
[2537] Faster network, but not faster browsing until ... - (new - 2009-12-14)
[2493] Melksham buses to/from Chippenham, Trowbridge, Bath, Devizes, London - (new - 2009-11-05)
[2436] Melksham Hotel Rooms - pictures
[2425] Weekend and Christmas Promotion - Well House Manor Hotel, Melksham
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[2527] Flying tonight - (new - 2009-12-05)
[2526] A reluctance to move from old shoes to new - (new - 2009-12-05)
[2519] Status Page / breaks of service in early December - (new - 2009-11-30)
[2470] Windows 7 and Open Source Programming
[2449] Four aspects - Chamber, Transport, Courses and Hotel
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[2550] Do not copy and paste code - there are much better ways - (new - 2009-12-26)
[2536] All the Cs ... and Java too - (new - 2009-12-13)
[2535] When should I use Java, Perl, PHP, or Python? - (new - 2009-12-13)
[2510] The music of the stock market - (new - 2009-11-22)
[2507] Admission - (new - 2009-11-19)
[2505] I almost put the bins out this morning - (new - 2009-11-16)
[2501] Simples - (new - 2009-11-12)
Top or Show all for General Programming Topics

PHP - the language and its application
[2545] Scraping content for your own page via PHP - (new - 2009-12-21)
[2539] Changing Images - (new - 2009-12-17)
[2488] A variable number of arguments in a PHP function - (new - 2009-11-02)
[2478] How did I do THAT?
[2433] Controlling, supressing, enabling PHP error messages
Top or Show all for PHP - the language and its application

Java and the Java Environment
[2525] Using JSPs, Tag Libraries, Java Beans, Tomcat in one short example - (new - 2009-12-04)
[2434] Abstract classes, Interfaces, PHP and Java
[2423] What is a JVM, a JRE, a JDK - components of the core Java Environment
[2422] Looking inside Java classes - javap and javadoc
[2421] Sorting Collections of Objects in Java
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[2453] Dark to dark
[2443] Contrasting Cambridge, Bristol and Wiltshire
[2362] Thornham Farm Shop, Seend Cleeve, nr Melksham
[2305] Hot Tap at West Wilts Show
[2302] See us at the West Wilts Show
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[2551] Perl and the Common Gateway Interface - out of fashion but still very useful? - (new - 2009-12-26)
[2532] Analysing Google arrivals by country of origin - (new - 2009-12-10)
[2484] Finding text and what surrounds it - contextual grep - (new - 2009-10-30)
[2427] Operator overloading - redefining addition and other Perl tricks
[2416] Automating access to a page obscured behind a holding page
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[2554] Adding retrospective ALT attributes to IMG - (new - 2009-12-28)
[2390] Dynamic / changing images on your web page
[2223] CSS Style Diagrams - working out where attributes come from
[2135] What features does this visitors browser support? (PHP)
[1998] Text on a background image
[1926] Flash (client) to PHP (server) - example
[1831] Text formating for HTML, with PHP
[1814] Javascript/HTML example, dynamic server monitor
[1813] Ajax - going Asyncronous and what it means
[1812] Starting Ajax - easy example of browser calling up server data
[1811] Alternative URLs using % symbol encoding
[1806] Dealing with overhead cables in a photograph
[1681] Adding a button to a web page to print the page
[1677] CSS training - Cascading Style Sheets (UK course)
[1630] To provide external links, or not?
[1618] A small picture does not always cut it!
[1519] Flipping images on your web page
[1493] Comparison - cellpadding versus cellspacing
[1463] All the special characters in HTML ...
[1431] Getting the community on line - some basics
[1352] Actionscript / Flash / Flex (IAQ/FAQ)
[1322] Flash - is it available to your web page?
[1160] HTML - example of a simple web page
[1034] The new web site look spreads
[1019] span and div tags - a css comparison
[1017] css - handling white space and pre
[1016] Modernising from tables to cascading style sheets
[999] Cascading and the buses
[996] Setting your colour theme through PHP
[994] Training on Cascading Style Sheets
[993] Positioning with Cascading Style Sheets
[887] HTML tables - telling whats wrong from the display
[857] Strikingly busy
[847] Image maps for navigation - a straightforward example
[665] PHP Image viewing application
[565] Using PHP to output images, XML, Style sheets, etc
[553] Keep that image small
[522] Javascript events - a good example
[501] .css - using PHP to make dynamic style sheets
[411] Javascript examples (some PHP and MySQL too)
[351] Is photoajustment an addiction?
[220] When to use Frames
Top or Show all for Client Side Languages (HTML, CSS, Javascript)

Ruby and Ruby on Rails
[2296] Variable scope - what is it, and how does it Ruby?
[2293] Regular Expressions in Ruby
[2292] Object Orientation in Ruby - intermediate examples
[2291] Collection objects (array and hash) in Ruby
[2290] Opening and reading files - the ruby fundamentals
Top or Show all for Ruby and Ruby on Rails

SQL and 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
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[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
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[2509] A life lesson from the accuracy of numbers in Excel and Lua - (new - 2009-11-21)
[2500] Dynamically formatting your results (Lua) - (new - 2009-11-10)
[2492] Lua Classes - open enrolement - (new - 2009-11-04)
[2461] Luac - getting lua to start fast by precompiling
[2455] Lua examples - coroutines, error handling, objects, etc
Top or Show all for Programming in Lua

Python Programming
[2523] Plan your application before you start - (new - 2009-12-02)
[2520] Global and Enable - two misused words! - (new - 2009-11-30)
[2506] Good example of recursion in Python - analyse an RSS feed - (new - 2009-11-18)
[2504] Learning to program in ... - (new - 2009-11-15)
[2489] Parallel Pinging, using Python Threads or Expect spawn lists - (new - 2009-11-02)
[2485] How do I set up a constant in Python? - (new - 2009-10-31)
Top or Show all for Python Programming

And also ...
[2555] Bookkeeping - (new - 2009-12-29)
[2553] On a short walk from home - (new - 2009-12-27)
[2549] Christmas Day ... - (new - 2009-12-25)
[2547] The great thing about snow .... - (new - 2009-12-23)
[2543] Day and night at Christmas - (new - 2009-12-19)
[2528] Melksham Christmas Lights - (new - 2009-12-05)
[2518] Through the arches - (new - 2009-11-29)
[2503] Melksham manslaughter case concludes - sort of - (new - 2009-11-14)
[2499] ourdog is Greyhound, Staffie and Ginger Cake - (new - 2009-11-09)
[2498] Remembrance Sunday 2009, Melksham - (new - 2009-11-08)
Top or Show all for And also ...

Public Transport
[2557] Rail Campaign - response to core consultation - (new - 2009-12-31)
[2556] Railway Station Survey - please complete today or tomorrow - (new - 2009-12-30)
[2533] Five guests, three groups, one car - (new - 2009-12-11)
[2529] Santa Special, 2009 - (new - 2009-12-06)
[2522] Integrated public Transport - what could be done for Melksham - (new - 2009-12-01)
[2515] Why we have two buses an hour - but not a half hourly service - (new - 2009-11-28)
[2513] Wiltshire Council purchases Melksham Station Land - (new - 2009-11-26)
[2511] The story of the railway land at Melksham Station - (new - 2009-11-24)
[2490] Friendly Hotel in Melksham, near Bath - (new - 2009-11-02)
[2486] Santa Special - Trowbridge and Melksham to Swindon - (new - 2009-10-31)
Top or Show all for Public Transport

Fun and Flames
[2542] My armpit was like a zebra crossing - (new - 2009-12-19)
[2496] A better design of mouth - (new - 2009-11-07)
[2397] Signwriting is dead. Long live the sign.
[2256] Is it Python past cheetah already?
[2251] Over a third of numbers start with the digit 1
Top or Show all for Fun and Flames

Keynote Articles
[2483] Clustering on Tomcat - (new - 2009-10-30)
[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
[2494] Making Linux Politically correct - (new - 2009-11-06)
[2491] Root is root for a reason! - (new - 2009-11-03)
[2479] Accidentally typed ci rather than vi?
[2301] Mistaken identity?
[2300] What does x on a linux directory mean?
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 November 2009September 2009July 2009May 2009March 2009January 2009November 2008September 2008July 2008 • 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