The Well House Newsletter - Thursday, 1st July 2010
About us and this newsletter [link] ...
Previous editions: May 2010March 2010January 2010November 2009September 2009July 2009May 2009March 2009January 2009 • 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
[2768] Carrying a long URL around - looking for memorable shorts - (new - 2010-05-17)
[2753] You do not just fly - that is just part of the journey - (new - 2010-05-06)
[2728] Redirecting a home page using mod_rewrite
[2596] Http protocol - what does a web server send
[2552] Web site traffic - real users, or just noise?
Top or Show all for Apache HTTP and Tomcat Servers

C and C++ Programming
[2843] String functions in C - (new - 2010-06-30)
[2842] Staring a C course with Hello World - why? - (new - 2010-06-30)
[2841] C Course exercise and sample answer - source in 2 files - (new - 2010-06-30)
[2763] Our C and C++ training course are on Open Source platforms - (new - 2010-05-13)
[2674] Make and makefiles - a commented example to help you learn
Top or Show all for C and C++ Programming

Melksham
[2837] Lorry Parking in Melksham - (new - 2010-06-29)
[2829] Dauncey Gardens, Melksham - (new - 2010-06-27)
[2827] Melksham - a gem in Wiltshire - (new - 2010-06-26)
[2782] Tell the Melksham Chamber or you only have yourself to blame - (new - 2010-05-26)
[2779] The history and future of Melksham Chamber of Commerce - (new - 2010-05-25)
[2770] Melksham Chamber of Commerce - Presidents report to AGM - (new - 2010-05-19)
[2748] Monitoring the success and traffic of your web site - (new - 2010-05-01)
Top or Show all for Melksham

Training from Well House Consultants
[2839] Software versions used - June 2010 - (new - 2010-06-30)
[2835] A course is more than just a chap giving a lecture - (new - 2010-06-28)
[2810] A course review - for the tutor to complete - (new - 2010-06-14)
[2784] Course Lunches - (new - 2010-05-27)
[2777] Blowing our own trumpet - (new - 2010-05-23)
[2775] Declarations of interest - knowing where you stand with people - (new - 2010-05-22)
[2772] Graham Ellis - Summary of Training Record - (new - 2010-05-21)
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[2828] Sharing our programs - easy. Sharing our data - harder. - (new - 2010-06-26)
[2793] They do weddings, we do courses. - (new - 2010-06-04)
[2724] Escapee Grandparents welcome - Henfield and Melksham
[2650] Getting a phone line changed ...
[2598] An excuse for making a sales call
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[2838] Respecting our customers anonimity - (new - 2010-06-29)
[2794] The Farming Industry pictured around Melksham - (new - 2010-06-04)
[2762] Well House - Mission and Policy summaries - (new - 2010-05-13)
[2705] Hotel booking in Melksham made easy!
[2663] Improve your PHP on a weekend away
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[2823] Where have all the bloggers gone? - (new - 2010-06-24)
[2820] Netiquette for forum newcomers - (new - 2010-06-20)
[2781] The 500 pound question to get you started - (new - 2010-05-26)
[2751] Going off at a tangent, for a ramble - (new - 2010-05-04)
[2743] Public Open Source Training Courses running this summer and autumn in Melksham
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[2844] Learning about Regular Expressions in C through examples - (new - 2010-06-30)
[2834] Teaching examples in Perl - third and final part - (new - 2010-06-27)
[2806] Macho matching - do not do it! - (new - 2010-06-13)
[2804] Regular Expression Myths - (new - 2010-06-13)
[2800] The Merchants And - (new - 2010-06-09)
[2769] Easy - but for whom? - (new - 2010-05-18)
[2758] But what will you DO with all those pictures? - (new - 2010-05-09)
[2755] Books in the store in the USA - still a portent of the UK market to come? - (new - 2010-05-08)
[2747] Containment, Associative Objects, Inheritance, packages and modules - (new - 2010-04-30)
Top or Show all for General Programming Topics

PHP - the language and its application
[2774] PHP - Object Oriented Design in use - (new - 2010-05-21)
[2773] Dynamically watching your web site via a PHP wrapper - (new - 2010-05-21)
[2742] A simple server benchmark script
[2738] What is all this SESSION stuff about? (PHP)
[2729] Uploading a document or image to its own URL via a browser
Top or Show all for PHP - the language and its application

Java and the Java Environment
[2735] Type checking, Java arrays and collections
[2734] for and foreach in Java
[2654] Java - from applets to servlets. JSPs and more
[2653] Java Server Pages - putting it all together
[2652] Reading and writing cookies in Java Servlets and JSPs
Top or Show all for Java and the Java Environment

Around, about and nearby to Wiltshire
[2830] Poulshot Village Fete - (new - 2010-06-27)
[2750] Views of Wessex - (new - 2010-05-03)
[2713] History is all around us
[2687] A lovely spring afternoon
[2685] Stairs
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[2840] Just pass a pointer - do not duplicate the data - (new - 2010-06-30)
[2836] Perl - the duplicate key problem explained, and solutions offered - (new - 2010-06-28)
[2833] Fresh Perl Teaching Examples - part 2 of 3 - (new - 2010-06-27)
[2832] Are you learning Perl? Some more examples for you! - (new - 2010-06-27)
[2825] Perl course - is it tailored to Linux, or Microsoft Windows? - (new - 2010-06-25)
[2821] Chancellor George Osborne inspires Perl Program - (new - 2010-06-22)
[2818] File open and read in Perl - modernisation - (new - 2010-06-19)
[2817] Setting a safety net or fallback value in Perl - (new - 2010-06-19)
[2816] Intelligent Matching in Perl - (new - 2010-06-18)
[2815] switch and case, or given and when in Perl - (new - 2010-06-17)
[2813] Iterating over a Perl list and changing all items - (new - 2010-06-15)
[2812] What is Perl? - (new - 2010-06-15)
[2811] Igloos melt in the summer, but houses do not - (new - 2010-06-15)
[2805] How are you getting on? - (new - 2010-06-13)
[2801] Binary data handling with unpack in Perl - (new - 2010-06-10)
[2798] Perl - skip the classics and use regular expressions - (new - 2010-06-08)
[2783] The Perl Survey - (new - 2010-05-27)
Top or Show all for The Perl Programming Language and its use

Client Side Languages (HTML, CSS, Javascript)
[2675] Redirecting to your main domain for correct security keys
[2628] An example of an injection attack using Javascript
[2554] Adding retrospective ALT attributes to IMG
[2390] Dynamic / changing images on your web page
[2223] CSS Style Diagrams - working out where attributes come from
Top or Show all for Client Side Languages (HTML, CSS, Javascript)

Ruby and Ruby on Rails
[2826] Ruby - training for automated testing users - (new - 2010-06-25)
[2714] A simple example - XML from a Ruby program
[2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast
[2651] Calculation within objects - early, last minute, or cached?
[2623] Object Oriented Ruby - new examples
Top or Show all for Ruby and Ruby on Rails

SQL and MySQL
[2749] Delegate Question - defining MySQL table relationships as you create the tables - (new - 2010-05-02)
[2647] Removing duplicates from a MySQL table
[2645] Optimising and caching your MySQL enquiries
[2644] Counting rows in joined MySQL tables
[2643] Relating tables with joins in MySQL
Top or Show all for SQL and MySQL

Tcl, Tcl/Tk and Expect
[2681] Tcl - a great engineering language
[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
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[2727] Making a Lua program run more than 10 times faster
[2723] Returning multiple values from a function - Lua
[2710] __index and __newindex in Lua - metatable methods
[2706] Error trapping in Lua - no exceptions.
[2703] Lua Metatables
Top or Show all for Programming in Lua

Python Programming
[2822] Python training courses for use with ESRI ArcMap software - (new - 2010-06-23)
[2814] Python - splitting and joining strings - (new - 2010-06-16)
[2790] Joining a MySQL table from within a Python program - (new - 2010-06-02)
[2786] Factory methods and SqLite in use in a Python teaching example - (new - 2010-05-29)
[2785] The Light bulb moment when people see how Object Orientation works in real use - (new - 2010-05-28)
[2780] Formatted Printing in Python - (new - 2010-05-25)
[2778] Learning to program in Python 2 ... and / or in Python 3 - (new - 2010-05-24)
[2766] Optional and named parameters to Python functions/methods - (new - 2010-05-15)
[2765] Running operating system commands from your Python program - (new - 2010-05-14)
[2764] Python decorators - your own, staticmethod and classmethod - (new - 2010-05-14)
[2746] Model - View - Controller demo, Sqlite - Python 3 - Qt4 - (new - 2010-04-29)
Top or Show all for Python Programming

And also ...
[2824] A pint of Black Rat, and a lazy barman - (new - 2010-06-25)
[2819] Some more pictures ... - (new - 2010-06-19)
[2809] Frankfurt in 90 minutes - (new - 2010-06-13)
[2807] Canal through Melksham - the options and issues - (new - 2010-06-13)
[2803] Travelling across Europe - (new - 2010-06-12)
[2802] After the Perl course in Nurnberg - (new - 2010-06-11)
[2799] Nuremberg - some pictures - (new - 2010-06-08)
[2797] Sur la T.G.V. - (new - 2010-06-07)
[2795] Simon says - (new - 2010-06-05)
[2792] Should Government compete with private industry? - (new - 2010-06-03)
[2787] Sleeping in on Sunday - (new - 2010-05-30)
[2776] Regional Spatial Strategy and the next 20 years - Whence Wiltshire under the new government? - (new - 2010-05-22)
[2767] Back from a Python course in Glasgow - (new - 2010-05-16)
[2760] Views of Scotland - (new - 2010-05-11)
[2759] Touching base - (new - 2010-05-10)
[2757] Bodicea, Lincoln, and our new MP - (new - 2010-05-09)
[2756] Same subject - different pictures - (new - 2010-05-09)
[2754] At Arlington and the Pentagon - (new - 2010-05-07)
[2752] Voting day - UK General Election - (new - 2010-05-06)
Top or Show all for And also ...

Public Transport
[2808] From home to Nurnberg - journey pictures - (new - 2010-06-13)
[2796] Sunday - waiting for the ferry. - (new - 2010-06-06)
[2791] Bath to Melksham buses - times - (new - 2010-06-03)
[2789] Melksham to London (Heathrow, and Central London) - (new - 2010-06-02)
[2771] Melksham to Calne by public transport - (new - 2010-05-20)
Top or Show all for Public Transport

Fun and Flames
[2788] Cost of Sales - (new - 2010-06-01)
[2761] A small business, facing a big government questionnaire - (new - 2010-05-12)
[2676] Changing Times
[2626] On Malachite Green
[2625] Both feet on the same pavement
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
[2831] Recording (a macro) in vi - (new - 2010-06-27)
[2639] su or su - ... what is the difference?
[2638] Finding what has changed - Linux / Unix
[2636] Linux - useful tips including history and file name completion
[2599] Telling Apache web servers apart / notes for the non-technical
[2595] Twelve skills / knowledges needed for the design of a web site
[2494] Making Linux Politically correct
[2491] Root is root for a reason!
[2479] Accidentally typed ci rather than vi?
[2301] Mistaken identity?
[2300] What does x on a linux directory mean?
[2299] How much space does my directory take - Linux
[2203] Always use su with minus. And where do programs come from?
[2201] Running straight from the jar, but not from a tar
[2182] What Linux run level am I in?
[2150] Routers, Firewalls and multilayer servers
[2149] Routing Network Traffic - Proxies, Redirects and DNS
[2139] OS Commerce install made simple
[2130] Javascript - move cursor over image to change a different image.
[2117] Choosing a railway station fairly in PHP
[2035] 1234567890 ... coming up on Friday 13th
[2023] sw_vers - what version of OSX am I running?
[1903] daemons - what is running on my Linux server?
[1902] sstrwxrwxrwx - Unix and Linux file permissions
[1893] Some Linux and Unix tips
[1803] FTP passive mode - a sometimes cure for upload hangs
[1801] Will your backups work if you have to restore them?
[1774] What is my real and my effective ID? [Linux]
[1765] Dialects of English and Unix
[1764] Yank and Push - copy and move in vi
[1719] A special day - last Friday in July
[1712] As different as night and tyres
[1700] FTP server on Fedora Linux
[1690] Conversion of c/r line ends to l/f line ends
[1666] Slow boot and terminal start on Linux boxes
[1660] Korn shell - some nuggets
[1659] String, Integer, Array, Associative Array - ksh variables
[1658] Some useful variables and settings in the Korn Shell
[1651] ls command - favourite options
[1650] Looking for files with certain characteristics (Linux / Unix)
[1648] The tourists guide to Linux
[1592] Setting up a new user - Linux or Unix
[1527] Selecting file names in a shell - one word or another
[1439] Linux / Unix - layout of operating system files
[1438] Copy and paste / cut and paste and other vi techniques
[1408] Wireless hotel tips - FTP and Skype connections failing
[1367] korn tips - some useful korn shell techniques
[1366] awk - a powerful data extraction and manipulation tool
[1361] Korn shell course
[1288] Linux run states, shell special commands, and directory structures
[1259] Where am I and how did I get here?
[1028] Linux / Unix - process priority and nice
[1023] Finding public writeable things on your linux file system
[1013] Copy multiple files - confusing error message from cp
[1012] Moving files between Windows / DOS and Linux / Unix
[984] Cardinal numbers and magic numbers
[827] No news is good news with Unix and Linux
[770] Splash!
[768] Our new .eu top level domain
[735] Boys will be boys, saved by Ubuntu
[711] THE home directory or MY home directory
[705] Disc Partitioning
[703] Copying files and preserving ownership
[686] Name Services - telling your LDAP from your DNS
[683] Supporting users on Linux and Unix
[679] More or less on the edge of the page
[593] Finding where the disc space has gone
[544] Repeating tasks with crontab
[511] Domain Forwarding - 2 ways of doing it
[506] What are DHCP and DNS?
[476] May I be politically incorrect?
[442] How far away is that server?
[431] File permissions of Linux and Unix systems
[430] Linux commands - some basics
[367] Ajax
[267] Searching security holes
[249] An easy way out
[166] Acronyms
[153] Linux - where to put swap space
[152] Aladdin, or careful what you wish.
[74] pushd and popd
[73] vi - full circle
[71] Comparators in Linux and Unix
[64] Shell Script for CGI on the web
[63] Almost like old times
[37] Security and Safety
[34] Linux / LAMP course
[11] A bolt of lightning on Multicasting
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 2010March 2010January 2010November 2009September 2009July 2009May 2009March 2009January 2009 • 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