The Well House Newsletter - Tuesday, 1st May 2012
About us and this newsletter [link] ...
Previous editions: March 2012January 2012November 2011September 2011July 2011May 2011March 2011January 2011November 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 ...

Linux and Shell Programming
[3679] Setting up your Linux system as a firewall using iptables - (new - 2012-04-02)
[3666] Makefile variables - defined internally, from the command line and from the environment - (new - 2012-03-22)
[3652] A Complete makefile example - (new - 2012-03-14)
[3651] Makefile - some basics, and a demonstration - (new - 2012-03-13)
[3632] What is Make? - (new - 2012-03-02)
Top or Show all for Linux and Shell Programming

Apache HTTP and Tomcat Servers
[3680] How can I run multiple web servers behind a single IP address? - (new - 2012-04-02)
[3443] Getting more log information from the Apache http web server
[3339] Simplest ever proxy configuration?
[3019] Apache httpd Server Status - monitoring your server
[3018] Tuning Apache httpd and Tomcat to work well together
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[3649] A single action for multiple iPad / iPhone buttons, and animation - (new - 2012-03-11)
[3593] Chars, char arrays and strings in C. Some early cautions and pitfalls.
[3591] Integer types, and integer overflows, in C
[3590] Defining, declaring and initialising variables in C
[3509] Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses
Top or Show all for C and C++ Programming

Melksham
[3714] Just 12 winners? Or 371 or more? Town Centres. - (new - 2012-04-30)
[3712] Some unpublished and historic pictures - Museum of Melksham - (new - 2012-04-28)
[3710] Encouraging business in Melksham and its neighbourhood - keep business local?? - (new - 2012-04-27)
[3706] An exciting Chamber of Commerce AGM - sound like an Oxymoron? - (new - 2012-04-25)
[3704] The Bowerhill Villager - a newsletter for Bowerhill, Melksham - (new - 2012-04-22)
[3703] A Museum for Melksham History. Open from 12th May 2012. - (new - 2012-04-21)
[3700] Why do people use chains rather than independent traders? - (new - 2012-04-18)
[3697] Events in Melksham - read all about them, and tell us about yours - (new - 2012-04-15)
[3696] Melksham government and business organisations - (new - 2012-04-14)
[3693] Wiltshire Business Support Service - (new - 2012-04-11)
[3692] Deeper than Art - An exhibition of the tattoo Canvas - Melksham - (new - 2012-04-10)
[3682] Melksham Business Newsreel - (new - 2012-04-03)
[3677] Some advise for guest speakers at meetings - (new - 2012-03-31)
[3672] Melksham Train Service - please support the TransWilts case for regular trains - (new - 2012-03-25)
[3663] Changing shops and organisations - Melksham, the last and next five years - (new - 2012-03-21)
[3659] Welcome to Melksham - our new communities - (new - 2012-03-18)
[3657] Basham Festival, Melksham, early August 2012 - a welcome - (new - 2012-03-16)
[3656] TrainWest 2012 - 14th and 15th April, Melksham, Wiltshire - (new - 2012-03-16)
[3647] Along the brook - East Melksham to Melksham - (new - 2012-03-10)
[3644] The way of the Prioress - Melksham history pictured today - (new - 2012-03-09)
[3643] Hotel food, Melksham - enjoy the variety of the American way - (new - 2012-03-08)
Top or Show all for Melksham

Training from Well House Consultants
[3701] Refresh and Revision training class days - Perl / PHP / Python / Lua / Ruby / Tcl / C / C++ - (new - 2012-04-19)
[3691] Back in Cambridge to give a Lua course - (new - 2012-04-09)
[3653] What is happening in 59 days time in Melksham? - (new - 2012-03-14)
[3637] April, May and June 2012 - Public Open Source Programming Courses - (new - 2012-03-04)
[3636] Best tenner I ever spent? - (new - 2012-03-04)
[3628] Historic Drawings from near Melksham - (new - 2012-02-28)
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[3684] Once upon a Maundy Thursday - (new - 2012-04-05)
[3665] Will will smile? - (new - 2012-03-22)
[3660] A Pivotal Incident - learning how to welcome your guests - (new - 2012-03-18)
[3645] Keeping our hotel looking like new, by using our gained experience - (new - 2012-03-09)
[3613] Keeping Business Local. But is that realistic?
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[3708] Strawberry Cream Teas in Melksham - available every day this summer - (new - 2012-04-25)
[3702] Digital Champions think that Well House Manor is a champion venue! - (new - 2012-04-20)
[3612] Help to get online in Melksham
[3611] A customer thanks Well House Manor
[3600] Visa, MasterCard and American Express - changing payment profiles
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[3670] Reading Google Analytics results, based on the relative populations of countries - (new - 2012-03-24)
[3661] Keeping forum and blog comments clean - (new - 2012-03-19)
[3648] iPad and iPhone programming - our seminar weekend with Xcode - (new - 2012-03-11)
[3599] Seeing how Melksham has changed over the years, via an iPad
[3596] Want to learn iPad and iPhone programming? Come along and learn with me for free.
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[3650] Possessive Regular Expression Matching - Perl, Objective C and some other languages - (new - 2012-03-12)
[3609] How do classes relate to each other? Associated Classes
[3608] Design Patterns - what are they? Why use them?
[3607] Designing your application - using UML techniques
[3548] Dark mornings, dog update, and Python and Lua courses before Christmas
Top or Show all for General Programming Topics

PHP - the language and its application
[3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (new - 2012-03-03)
[3584] QR codes - graphics images that provide quick phone links
[3568] Telling which ServerAlias your visitor used - useful during merging domains
[3540] Easy session example in PHP - keeping each customers data apart
[3539] Separating program and artwork in PHP - easier maintainance, and better for the user
Top or Show all for PHP - the language and its application

Java and the Java Environment
[3573] New in Java 7 - and why we are not running public Java 7 courses
[3497] Not the same language - but based on the same constructs
[3365] Turning bright delegates into bright and knowledgable ones
[3293] Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat)
[3048] String handling - from first steps to practical examples
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[3709] Queen to visit eight Wiltshire areas - will she know what she misses in the other 13 areas? - (new - 2012-04-26)
[3641] Swindon to Trowbridge - transport and travel options - (new - 2012-03-06)
[3498] Which West Wilts Town? A picture quiz for you
[3382] What is the picture?
[3341] Farewell to the Hercules?
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[3707] Converting codons via Amino Acids to Proteins in Perl - (new - 2012-04-25)
[3630] Serialsing and unserialising data for storage and transfer in Perl - (new - 2012-02-28)
[3581] Perl - calls to methods that use => - what do they mean?
[3577] How to do multidimensional arrays (or rather lists and hashes) in Perl
[3574] Perl functions such as chop change their input parameters
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[3532] Sharing the user experience - designing a form with the customer in mind
[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
Top or Show all for Client Side Languages (HTML, CSS, Javascript)

Ruby and Ruby on Rails
[3623] Some TestWise examples - helping use Ruby code to check your web site operation
[3622] Loading Ruby classes - where does Ruby look?
[3621] Matching regular expressions, and substitutions, in Ruby
[3619] Ruby v Perl - a comparison example
[3435] Sorta sorting a hash, and what if an exception is NOT thrown - Ruby
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[3494] Databases - when to treat the rules as guidelines
[3455] MySQL, MySQLi, PDO or something else - how best to talk to databases from PHP
[3447] Needle in a haystack - finding the web server overload
[3361] Blowing our own trumpet - MySQL resources
[3270] SQL - Data v Metadata, and the various stages of data selection
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[3638] Sorting dicts and arrays in Tcl - (new - 2012-03-04)
[3629] Sharing lots of values in Tcl without having lots of global declarations - (new - 2012-02-28)
[3618] lists and struct::list in Tcl - Introduction to struct::list and examples
[3617] The fileutil package and a list of file system commands in Tcl
[3614] Tcl - dicts - a tutorial and examples
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[3694] Special __ methods you can use in Lua metatables - (new - 2012-04-12)
[3690] Changes in Lua 5.2 - Garbage Collection - (new - 2012-04-08)
[3687] Binary / bitwise operations in Lua with the standard bit32 library - (new - 2012-04-06)
[3686] The goto statement in Lua - (new - 2012-04-06)
[3685] Programming Standards in Lua - (new - 2012-04-06)
[3683] Weak references in Lua - what are they, and why use them? - (new - 2012-04-04)
Top or Show all for Programming in Lua

Python Programming
[3705] Django Training Courses - UK - (new - 2012-04-23)
[3698] How to stop forms on other sites submitting to your scripts - (new - 2012-04-15)
[3695] Functions are first class variables in Lua and Python - (new - 2012-04-13)
[3673] Object oriented or structured - a comparison in Python. Also writing clean regular expressions - (new - 2012-03-26)
[3669] Stepping through a list (or an array) in reverse order - (new - 2012-03-23)
[3664] Error checking in a Python program - making your program robust via exceptions - (new - 2012-03-22)
[3662] Finding all the unique lines in a file, using Python or Perl - (new - 2012-03-20)
[3658] Using Make for a distribution - (new - 2012-03-17)
[3640] Sessions (Shopping Carts) in Django - the Python Web Framework - (new - 2012-03-05)
[3639] Demonstration of a form using Django - (new - 2012-03-04)
[3634] Defining database relations in your Django model - (new - 2012-03-02)
[3633] Nesting Templates in Django - (new - 2012-03-02)
Top or Show all for Python Programming

And also ...
[3713] Verticals ... last month - (new - 2012-04-29)
[3711] Kiss - (new - 2012-04-28)
[3688] Shopkeepers take an Easter break too - (new - 2012-04-07)
[3681] Kicking up a stink, the Victorian way? - (new - 2012-04-02)
[3678] Potteries and Staffordshire in the Sunshine - (new - 2012-04-01)
[3676] Rising prices, changing habits and society - (new - 2012-03-31)
[3675] Spring 2012 - (new - 2012-03-30)
[3674] Off to walk the dogs - (new - 2012-03-30)
[3667] A modern area of Cambridge - some thoughts provoked? - (new - 2012-03-22)
[3655] Sights and scenes - more London trip pictures - (new - 2012-03-16)
[3654] On a sunny afternoon in London - (new - 2012-03-15)
[3646] Exploring Melksham with a film maker - (new - 2012-03-09)
Top or Show all for And also ...

Public Transport
[3699] Bristol 50? Bristol 25? - (new - 2012-04-17)
[3689] Can I cycle or ride my mobility scooter on the pavement? - (new - 2012-04-07)
[3671] Future train services in Wiltshire - please write in to support a better service - (new - 2012-03-24)
[3668] Kings Cross - new concourse - between Python in Cambridge and Objective C in London - (new - 2012-03-22)
[3642] Wiltshire Travel Times - Chippenham, Trowbridge, Salisbury and other places too - (new - 2012-03-07)
[3631] Getting around Dublin by public transport - some observations - (new - 2012-03-01)
Top or Show all for Public Transport

Fun and Flames
[3462] Hangers, luggage and possessions
[3369] Local Council leads bans on many activities
[3302] Are you a half full or half empty person?
[3288] Random Questions ...
[3226] A busy morning for railway announcements
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

Unclassfied Articles
[3578] A busy start to 2012
[3567] First of the year
[3363] Should we take sponsored adverts on our site?
[3342] A Holiday
Top or Show all for unclassified

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 March 2012January 2012November 2011September 2011July 2011May 2011March 2011January 2011November 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