The Well House Newsletter - Friday, 1st July 2011
About us and this newsletter [link] ...
Previous editions: May 2011March 2011January 2011November 2010September 2010July 2010May 2010March 2010January 2010 • 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
[3339] Simplest ever proxy configuration? - (new - 2011-06-28)
[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?
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[3252] C++ - unknown array size, unknown object type. Help!
[3250] C++ - how we teach the language and the concepts behind the language
[3245] Collections in C and C++ - arrays, vectors and heap memory blocks
[3244] C and C++ - preprocess, compile, load, run - what each step is for
[3243] Breaking the running sequence - an introduction to conditional statements and loops
Top or Show all for C and C++ Programming

Melksham
[3340] Summer Sunday Timetable - TransWilts Trains - (new - 2011-06-30)
[3337] Home Grown Pigs, near Melksham Station - (new - 2011-06-26)
[3334] A lesson from the sporran market? - (new - 2011-06-25)
[3327] Why are chefs miserable? - (new - 2011-06-18)
[3325] The Olympic Torch, and Melksham House - (new - 2011-06-14)
[3317] Self Portrait (in words) - (new - 2011-06-04)
[3307] Melksham Community Radio launches - (new - 2011-05-28)
[3305] Getting away from the madding crowd - an intercontinental journey - (new - 2011-05-27)
[3304] Scones with or without fruit? - (new - 2011-05-26)
[3299] Presidents Report to Melksham Chamber of Commerce, 24.5.2011 - (new - 2011-05-24)
[3295] Strawberry Cream Teas, Coffee straight from the Bean and freshly squeezed orange juice - Melksham, every afternoon - (new - 2011-05-20)
[3279] Letter to The Editor - (new - 2011-05-06)
[3277] Between a rock and a hard place. - (new - 2011-05-04)
[3275] Melksham Chamber of Commerce - grows to appoint new Press Officer. Welcome. Sam - (new - 2011-05-02)
[3272] Melksham Car Parking - current charges and limits - (new - 2011-05-01)
Top or Show all for Melksham

Training from Well House Consultants
[3315] Friday - Electrician, Food Festival, C++ Course, Rail Group Meeting - (new - 2011-06-03)
[3311] Exhilarating day! - (new - 2011-05-30)
[3310] How fast is your Internet access? Do you need something faster for your business or home? - (new - 2011-05-29)
[3292] Every tenth picture. - (new - 2011-05-17)
[3259] Our library in Melksham
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[3333] Honesty and a friendly welcome goes a long way - (new - 2011-06-25)
[3312] Are you cheerful, reliable and available on Saturday mornings? - (new - 2011-05-30)
[3309] Tipping Policy - Well House Manor - (new - 2011-05-29)
[3294] It's not just about the jam in the sandwich - (new - 2011-05-19)
[3271] The importance of feedback - (new - 2011-04-30)
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[3314] Garden Seating, Well House Manor - (new - 2011-06-02)
[3308] Behind the scenes - setting up a cafe - (new - 2011-05-29)
[3296] Dog, hotel, Melksham, Wiltshire? - (new - 2011-05-21)
[3281] Does Well House Manor Hotel in Melksham offer lots of discounts? - (new - 2011-05-07)
[3276] International travel to the UK - coming to Melksham - (new - 2011-05-03)
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[3291] Pay and refund scam - alive and kicking against Melksham businesses - (new - 2011-05-16)
[3222] Clickjacking - another way to get you to follow a malicious link - Facebook issue
[3208] Links for social media, microblogs and business networking
[3190] What do the following web sites have in common?
[3179] Oops - I typed ci not vi, and have lost my file ...
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[3329] Perl from basics - (new - 2011-06-20)
[3262] Some SVG Elements, pixel and percent positioning
[3261] Scalable Vector Graphics - easy, low bandwidth, high resolution, dynamic.
[3251] C++ - objects that are based on other objects, saving coding and adding robustness
[3237] Using functions to keep look and feel apart from calculations - simple C example
Top or Show all for General Programming Topics

PHP - the language and its application
[3210] Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON
[3197] Finding and diverting image requests from rogue domains
[3186] How to add a customised twitter feed to your site
[3163] Twitter - the special use of @ # and http: in tweets
[3143] On time
Top or Show all for PHP - the language and its application

Java and the Java Environment
[3293] Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat) - (new - 2011-05-18)
[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.
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[3284] What to do in the evening during a Tcl course - (new - 2011-05-10)
[3267] Reybridge, Easter Monday
[3247] Light and dark at Green Park
[3206] Wiltshire College / Lackham College - the animals
[2923] Fresh air and beautiful places in Wiltshire
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[3335] Practical Extraction and Reporting - (new - 2011-06-26)
[3332] DNA to Amino Acid - a sample Perl script - (new - 2011-06-24)
[3326] Finding your big files in Perl - design considerations beyond the course environment - (new - 2011-06-14)
[3322] How much has Perl (and other languages) changed? - (new - 2011-06-10)
[3106] Buckets
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[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)

Ruby and Ruby on Rails
[3260] Ruby - a training example that puts many language elements together to demonstrate the whole
[3255] Process every member of an array, and sort an array - Ruby
[3254] Multiple inputs, multiple out, ruby functions
[3253] Is this number between? Does this list include? - Ruby
[3158] Ruby training - some fresh examples for string handling applications
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[3270] SQL - Data v Metadata, and the various stages of data selection - (new - 2011-04-29)
[3269] Files or Databases? MySQL, SQLite, or Oracle?
[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

Tcl, Tcl/Tk and Expect
[3320] Reading the nth line from a file (Perl and Tcl examples) - (new - 2011-06-09)
[3287] Exceptions - Tcl style - (new - 2011-05-12)
[3286] Should we cover expect and/or Tk on our public Tcl courses? - (new - 2011-05-11)
[3285] Extracting data from a string / line from file - Tcl - (new - 2011-05-10)
[3192] Tcl - Some example of HOW TO in handling data files and formats
Top or Show all for Tcl, Tcl/Tk and Expect

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

Python Programming
[3280] Passing parameters to Python functions - the options you have - (new - 2011-05-07)
[3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (new - 2011-05-05)
[3257] All possible combinations from a list (Python) or array (Ruby)
[3218] Matching a license plate or product code - Regular Expressions
[3200] How a for loop works Java, Perl and other languages
Top or Show all for Python Programming

And also ...
[3338] Return trip - Dogs Trust, Newbury - (new - 2011-06-27)
[3330] A lot of exercise this week - (new - 2011-06-21)
[3324] Rabbit Shelter - (new - 2011-06-12)
[3323] Is Melksham town centre dying? - (new - 2011-06-11)
[3321] Travelling around - (new - 2011-06-09)
[3319] Moving on - a task for the hotel staff! - (new - 2011-06-08)
[3316] Twitter Phishing Trips ... and a great new alert service - (new - 2011-06-04)
[3313] What does our MP do on a Bank Holiday? - (new - 2011-05-30)
[3306] Photogenic Place - (new - 2011-05-28)
[3303] Flying tonight - (new - 2011-05-26)
[3300] Wildlife and other pictures from holiday - (new - 2011-05-24)
[3298] Quiet Monday in - (new - 2011-05-23)
[3297] A long day, a long journey, and families and similarities the world over - (new - 2011-05-22)
[3289] New Camera - very first picture, and next from first films - (new - 2011-05-14)
[3283] The juggler - (new - 2011-05-08)
Top or Show all for And also ...

Public Transport
[3336] Efficient travel - from Melsksham to Edinburgh by Sleeper Train - (new - 2011-06-26)
[3331] Comparing Alloa and Melksham - stations and services - (new - 2011-06-23)
[3328] Summer Sundays - days out by train from Swindon on the TransWilts - (new - 2011-06-18)
[3318] Summer Sunday Trains - outings from Swindon, Chippenham, Melksham, Trowbridge and Westbury - (new - 2011-06-05)
[3301] Using public transport - USA style - (new - 2011-05-25)
[3290] Changes (and no changes) at Melksham bus stops - (new - 2011-05-15)
[3282] The future of canal management and charities - Kennet and Avon Canal bias - (new - 2011-05-08)
[3274] Small scale improvement - big scale gain. And they CAN be done with local knowledge - (new - 2011-05-02)
[3273] Wanted - a look to the future - (new - 2011-05-02)
Top or Show all for Public Transport

Fun and Flames
[3302] Are you a half full or half empty person? - (new - 2011-05-25)
[3288] Random Questions ... - (new - 2011-05-14)
[3226] A busy morning for railway announcements
[3223] Answering at my earliest convenience
[3215] Solution looking for problem
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
[3256] Displaying a directory or file system tree - Linux
[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
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 May 2011March 2011January 2011November 2010September 2010July 2010May 2010March 2010January 2010 • or current edition


Training sample © 2024, 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