The Well House Newsletter - Friday, 1st November 2013
About us and this newsletter [link] ...
Previous editions: September 2013July 2013May 2013March 2013January 2013November 2012September 2012July 2012May 2012 • 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
[4063] Backups by crossover between network centres - setting up automatic scp transfers
[4056] An overpractical test of our backup strategy!
[4045] Linux Web Server - User Roles, User Accounts, and shared administration
[3891] The components of an Apache httpd / Tomcat / MySQL stack and what each does
[3792] Managing daemons from a terminal session
Top or Show all for Linux and Shell Programming

Apache HTTP and Tomcat Servers
[4178] Where are you? How to write a geosensitive application - (new - 2013-09-18)
[4064] Apache httpd - a robust, open source web server
[3996] Tips on Tomcat - moving applications around
[3915] How does PHP work?
[3892] Distributed, Balanced and Clustered Load Sharing - the difference
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[4128] Allocating memory dynamically in a static language like C
[3982] Using a vector within an object - C++
[3811] Associated Classes - using objects of one class within another
[3809] Dwarf Exception Unwind Info
[3807] Reading (and writing) files in C++
Top or Show all for C and C++ Programming

Melksham
[4198] New trains for 2014 - Swindon to Westbury. Meetings Melksham, Swindon, Trowbridge, Chippenham and Westbury - (new - 2013-10-24)
[4188] Extended Weekend - but not a quiet one! - (new - 2013-10-07)
[4186] Melksham to Bath and Zigzag buses - at a turning point? - (new - 2013-10-06)
[4185] TransWilts Trains - running a successful campaign talk - (new - 2013-10-05)
[4183] Reaching a hotel standard where 99% of guests would return - and maintaining that standard - (new - 2013-10-01)
[4173] Train and Rail Travel - who runs it and where do I ask questions? - (new - 2013-09-13)
[4170] Herman Miller coming to Melksham - the Chamber of Commerce is briefed - (new - 2013-09-10)
[4169] Around and about - Melksham - (new - 2013-09-08)
[4164] Melksham Market - every Tuesday - (new - 2013-09-03)
Top or Show all for Melksham

Training from Well House Consultants
[4200] Endorsed Perl, Python and PHP training - Tcl, Lua, Ruby and C too! - (new - 2013-10-24)
[4197] Python and Tcl courses, November, UK (Melksham) ... just a few places left - (new - 2013-10-23)
[4172] Public courses - Python, PHP, Perl, Ruby, Lua, Tcl, C and C++ - autumn 2013 and through 2014 - (new - 2013-09-13)
[4168] Travelling to and from courses - much easier from December 2013 - (new - 2013-09-08)
[4132] Using your own laptop on our courses - now even easier!
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[4177] Setting and publishing your hours to suit your customer base - (new - 2013-09-18)
[4156] A further chance to see Melksham on TV
[4147] A hidden hotel gem in Melksham
[4138] Should a hotel accept guests who book for just one night?
[4112] Really good friends - four in a bed!
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[4175] An alternative format for a new train service timetable - (new - 2013-09-15)
[4174] What would the extra trains from Melksham mean to your journey? - (new - 2013-09-15)
[4166] Pimms and Croquet - Melksham Festival of Food and Drink - (new - 2013-09-07)
[4162] Pimms and Croquet at Well House Manor - 7th September 2013
[4158] Wedding from Well House Manor - an excellent base in Melksham
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[4135] Introducing your product to Well House Consultants - single, personally tuned email please
[4134] Setting up your MacBook Air as a mobile broadband router
[4121] Has your Twitter feed stopped working? Switching to their new API
[4115] More or less back - what happened to our server the other day
[4076] Web site - fully back!
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[4153] Rooms available tonight - how to code an algorithm from first principles
[4114] Teaching CodeIgniter - MVC and PHP
[4098] Using object orientation for non-physical objects
[4096] Perl design patterns example
[4066] MVC and Frameworks - a lesson from first principles in PHP
Top or Show all for General Programming Topics

PHP - the language and its application
[4136] How do I post automatically from a PHP script to my Twitter account?
[4106] Web server efficiency - saving repetition through caches
[4075] Further recent PHP examples
[4074] A comment on comments in PHP
[4073] Learning about Object Orientation in PHP - a new set of examples
Top or Show all for PHP - the language and its application

Java and the Java Environment
[3997] Servlet v JSP (Java Server Page). What is the difference?
[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)
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[3989] Plenty to see and do - even in Winter - on a Well House Manor weekend
[3884] Pictures - across the park, French Weir and River Tone, Taunton
[3800] Fancy a weekend away? Try Well House Manor in Melksham, Wiltshire
[3729] Then and now pictures of Melksham - on show through the summer
[3723] Bank Holiday Monday, so it was pouring with rain.
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[4100] Perl Dancer - from installation to your first real application
[4099] Perl Dancer - a Perl Framework - Installation and first test
[4031] Showing what programming errors look like - web site pitfall
[3941] Building an object based on another object in Perl
[3940] Run other processes from within your Perl program
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[4037] Cascading Style Sheets and formatting your web page
[4036] HTML tags uses in these blog articles
[4035] Special characters in HTML
[4034] The VERY basics of a web page ... and web site
[3532] Sharing the user experience - designing a form with the customer in mind
Top or Show all for Client Side Languages (HTML, CSS, Javascript)

Ruby and Ruby on Rails
[4010] Really Simple Rails
[4009] Clear, concise examples - Ruby classes and objects.
[4008] Reading and checking user inputs - first lessons - Ruby
[4003] Web and console - same principle, same code - Ruby example
[3799] Ruby Documentation through rdoc
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[4007] Which database should I use? MySQL v SQLite
[4006] Ruby / SQLite3 example program, showing JOIN v LEFT JOIN
[3928] Storing your intermediate data - what format should you you choose?
[3494] Databases - when to treat the rules as guidelines
[3455] MySQL, MySQLi, PDO or something else - how best to talk to databases from PHP
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[3638] Sorting dicts and arrays in Tcl
[3629] Sharing lots of values in Tcl without having lots of global declarations
[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
[4117] Is Lua an Object Oriented language?
[4102] Installing Lua 5.2.2 on Mac OS X 10.7.4
[3730] What is a metatable? How do I set one up? How do I use them? Lua
[3727] Using Lua tables as objects
[3725] Lua Tables
Top or Show all for Programming in Lua

Python Programming
[4161] Python varables - checking existance, and call by name or by value?
[4129] Simple OO demonstration in C++, comparison to Python
[4118] We not only teach PHP and Python - we teach good PHP and Python Practice!
[4095] Django - first steps - Updated
[4094] Python Properties - how and why
Top or Show all for Python Programming

And also ...
[4201] Looking to the future at Melksham Station - (new - 2013-10-26)
[4193] Using our non-found page to help look for missing persons - (new - 2013-10-18)
[4189] Who are we - Lisa, Graham, Gypsy and Billy - (new - 2013-10-07)
[4187] Not treading water, but not risking the ship for a 0.5th of tar either - (new - 2013-10-06)
[4184] A fond memory - (new - 2013-10-02)
[4182] Welcome to Salford and Oldham - (new - 2013-09-30)
[4180] Exceptionally, I sign a petition - on a life and death issue for Irish dogs - (new - 2013-09-20)
[4165] Improving travel advise information in Wiltshire - (new - 2013-09-06)
Top or Show all for And also ...

Public Transport
[4199] Draft Westbury - Melksham - Swindon train times, from December 2014 - (new - 2013-10-24)
[4196] Official - Trowbridge and Melksham to London train improvements - (new - 2013-10-22)
[4195] Booking for Santa, Melksham Railway Development Group, 8th December 2013 - (new - 2013-10-21)
[4194] TransWilts Link - meeting notes from 19th October - (new - 2013-10-20)
[4192] A positive progress behind the scenes - (new - 2013-10-14)
[4191] Getting people to and from Melksham Station - not 20 but 700 times a day - (new - 2013-10-12)
[4190] A radical proposal - a cheap and effective way to provide home to city commuter transport - (new - 2013-10-11)
[4181] Grumbling about trains? Buses can be far worse! - (new - 2013-09-29)
[4179] Changing transport and destinations - looking forward to a good future - (new - 2013-09-19)
[4176] International and off island travel from Melksham - (new - 2013-09-16)
[4171] Mapping road accidents in Melksham and elsewhere too - (new - 2013-09-12)
[4163] TransWilts Community Rail Partnership - formally constituted - (new - 2013-09-01)
Top or Show all for Public Transport

Fun and Flames
[4167] The important customers are the majority, not the celebrity - (new - 2013-09-08)
[4140] Riots in Melksham
[4067] The woman, the television, the bullock and Darlington
[3922] Twerp - A person regarded as insignificant and contemptible
[3912] Sand to Arabia, Coals to Newcastle or Woodburners to Russia
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
[4127] Exploring the area ... Ynys, near Harlech
[4054] On Salford Docks - mind over matter?
[4047] Looking for Creative Design, Catering and Transport inputs to help with Melksham Campus
[4044] What to do on a wet weekend in Melksham?
[4043] Bus stop audit - what is missing?
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 September 2013July 2013May 2013March 2013January 2013November 2012September 2012July 2012May 2012 • 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