The Well House Newsletter - Friday, 1st July 2016
About us and this newsletter [link] ...
Previous editions: May 2016March 2016January 2016November 2015September 2015July 2015May 2015March 2015January 2015 • 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
[4587] shell - bash. Writing conditional tests and statements - the options available
[4586] Extending your bash shell with aliases, functions and extra commands
[4585] What is make? What is gcc?
[4584] Bash ... some new scripts to - handling user input
[4487] Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it.
Top or Show all for Linux and Shell Programming

Apache HTTP and Tomcat Servers
[4491] Web Server Admin - some of those things that happen, and solutions
[4434] Public training courses - upcoming dates
[4432] Java web application for teaching - now with sessions and clustering / load balancing demonstrations
[4431] A Java servlet that is also a stand alone program. And a server that is also a web client.
[4412] Java -making sure you have the right versions
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[4635] Encapsulating logic in functions and structs - the C approach to Object Oriented techniques
[4633] String handling in C - new examples of extracting integers from a string
[4566] C - why is slow to write and debug) but fast to run?
[4565] Allocation of memory for objects in C++ - Stack v Heap
[4563] Formatting and outputting your own classes in C++
Top or Show all for C and C++ Programming

Melksham
[4695] Melksham Rail Development Group becoming Melksham Rail Users Group - (new - 2016-06-21)
[4694] Supported Bus Services in Wiltshire - analysis of written-in comments - (new - 2016-06-11)
[4693] Wiltshire supported bus service consultation, early 2016 - interim results published - (new - 2016-06-09)
[4692] How are bus support payments currently calculated? - (new - 2016-06-07)
[4691] Real life PHP application using our course training MVC example - (new - 2016-06-05)
[4690] Buses in Wiltshire - potential changes and where we stand at the moment - (new - 2016-05-30)
[4688] Melksham Station - as at May 2016 - Part 5 (services and prices) - (new - 2016-05-30)
[4672] Annual review of Melksham Matters for Chamber of Commerce AGM - (new - 2016-05-15)
Top or Show all for Melksham

Training from Well House Consultants
[4689] Training Course schedule for summer and autumn 2016 - (new - 2016-05-30)
[4671] Ruby training, half a world away - (new - 2016-05-14)
[4602] Training course and hotel room prices - 2016
[4588] What teach you in a week stays with you for a decade
[4583] Back in the saddle again - excellent open source course from Well House Consultants
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[4613] Our best hotel customers help us ... to help them ... be our best customers.
[4603] Happy New Year. Our customers are our ambassadors
[4543] Saturday morning at Well House Manor
[4521] Should we get an AA or Visit Wiltshire hotel assessment?
[4468] Four in a Bed - most popular answers
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[4644] In your room at Well House Manor, Melksham, Wiltshire
[4582] A near-empty plate of pastries - sign of a breakfast enjoyed
[4567] Japanese and Malaysian food in Melksham
[4379] Well House Consultants / Well House Manor - Prices for 2015
[4299] The Best Bed and Breakfast in Melksham?
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[4651] Pressure selling in the fire safety business
[4520] No cold sales calls please - but delighted to hear from others!
[4492] Almost so wrong, but perhaps it's right for some?
[4474] Effect on external factors on traffic to our web sites - an update
[4426] FileMaker Day to Unix Time conversion
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[4673] Separating detailed data code from the main application - Ruby example - (new - 2016-05-16)
[4663] Easy data to object mapping (csv and Python)
[4656] Identifying the first and last records in a sequence
[4652] Testing new algorithms in PHP
[4645] What are callbacks? Why use them? An example in Python
Top or Show all for General Programming Topics

PHP - the language and its application
[4655] Image indexer / thumbnail display scripts in PHP
[4642] A small teaching program - demonstration of principles only
[4627] Caching results in an object for efficiency - avoiding re-calculation
[4626] Singleton design pattern - examples and uses
[4483] Moving from mysql to mysqli - simple worked example
Top or Show all for PHP - the language and its application

Java and the Java Environment
[4428] Using the lead - passing arrays and other collections in Java
[4427] Java example - for loop and conditionals from course exercise
[4422] Objects - from physical to virtual or abstract - Java
[4420] Flexibility in input - read from file, web resource or keyboard
[4419] Java Inheritance example - group of classes - step by step
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[4653] Coats of arms - towns and authorities in Wiltshire
[4622] Frosty morning, beauty of Wiltshire
[4265] A lovely meal in Swindon - just a short walk from the station
[4233] Open for the new year - Imber
[3989] Plenty to see and do - even in Winter - on a Well House Manor weekend
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[4620] Perl 6 - a Practical Extraction and Reporting example!
[4611] Hungarian, Camel, Snake and Kebab - variable naming conventions
[4610] Sorting by key or by comparator - Perl 6
[4609] Mapping an array / list without a loop - how to do it in Perl 6
[4608] Introspecion in Perl 6
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
[4682] One line scripts - Awk, Perl and Ruby - (new - 2016-05-20)
[4681] Ruby testing with RSpec - a new example - (new - 2016-05-19)
[4680] Processing data line by line - iterator in Ruby with yield - (new - 2016-05-19)
[4679] Reading in XML in Ruby with xmlsimple - (new - 2016-05-18)
[4676] Running shell (operating system) commands from within Ruby - (new - 2016-05-18)
[4675] Exceptions in Ruby - throwing, catching and using - (new - 2016-05-17)
[4674] Alternating valuses / flip-flop / toggle - example in Ruby - (new - 2016-05-17)
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[4493] Forgotten / lost MySQL root password
[4481] Extracting data from backups to restore selected rows from MySQL tables
[4436] Accessing a MySQL database from Python with mysql.connector
[4406] Fixing damaged MySQL tables - Error 1712 and Error 2013
[4390] Checking MySQL database backups have worked (not failed)
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[4678] Expect with Ruby - a training example to get you started - (new - 2016-05-18)
[4616] Still teaching Tcl in 2016?
[4525] What does Tcl do if you try to run a command that is not defined?
[4524] Tcl - a new example for data reformatting
[4523] Catching failed commands and not crashing the program in Tcl
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[4575] Learning not just what a program does, but how to design it in the first place.
[4574] repeat until in Lua - a one or more rather than a zero or more loop
[4573] Classic style OO code - in Lua
[4572] Tables with values and code in Lua - looks like an object?
[4571] Lua - using modules to add your own utilities
Top or Show all for Programming in Lua

Python Programming
[4697] Month, Day, Year number to day of week and month names in Python - English and Swedish - (new - 2016-06-23)
[4696] Programming with random numbers - yet re-using the same values for testing - (new - 2016-06-22)
[4668] Sorting a dict in Python
[4662] Recursion in Python - the classic example
[4661] Unique word locator - Python dict example
Top or Show all for Python Programming

And also ...
[4698] Lisa writes - on the referendum vote today - (new - 2016-06-23)
[4666] Spring at Well House Manor
[4646] Sometimes you wonder about people. And perhaps you should not.
[4643] From last July (2015)
[4637] People matter - but there is a tradeoff between different people in there
Top or Show all for And also ...

Public Transport
[4699] Melksham Rail Development Group - a celebration of 20 years - (new - 2016-06-25)
[4687] Melksham Station - as at May 2016 - Part 4 - (new - 2016-05-30)
[4686] Melksham Station - as at May 2016 - Part 3 - (new - 2016-05-29)
[4685] Melksham Station - as at May 2016 - Part 2 - (new - 2016-05-29)
[4684] Melksham Station - as at May 2016 - Part 1 - (new - 2016-05-28)
[4683] Saudi Arabia or Weymouth? - (new - 2016-05-22)
[4677] Swindon, Chippenham and Melksham - day trips by train to Weymouth start for 2016 - (new - 2016-05-18)
Top or Show all for Public Transport

Fun and Flames
[4392] Interview conditions,and other instructions to staff
[4354] Wiltshire Police - assuming someone is guilty just on the say-so of a member of the public?
[4329] Does Santa Claus need a CRB check?
[4304] Please do not ask me to be the chair!
[4282] On tipping - and the expectation of a tip
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
[4576] If it's Tuesday it must be Belgium?
[4509] Throwing a die - exercise in Ruby
[4508] Melksham to London by train - dont buy more than you need
[4484] TransAtlantic crossing - the starter
[4242] A busy January
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 May 2016March 2016January 2016November 2015September 2015July 2015May 2015March 2015January 2015 • 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