The Well House Newsletter - Tuesday, 1st September 2015
About us and this newsletter [link] ...
Previous editions: July 2015May 2015March 2015January 2015November 2014September 2014July 2014May 2014March 2014 • 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
[4487] Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it.
[4405] Backup procedures - via backup server
[4400] Commenting out an echo killed my bash backup script
[4259] Upgrading our training systems to all the current stable versions
[4063] Backups by crossover between network centres - setting up automatic scp transfers
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
[4466] Moving from C to C++ - Structured to Object Oriented - a lesson for engineers
[4465] Sockets, time handling and keyboard interrupt handling in C
[4377] Designing a base class and subclasses, and their extension, in C++
[4372] Template / design pattern for C++ constructor and accessors
[4355] C++ in 2 days
Top or Show all for C and C++ Programming

Melksham
[4513] Yesterday, Weymouth - (new - 2015-08-02)
[4512] The Weymouth Wizard - Saturdays in August from Wiltshire - (new - 2015-07-31)
[4510] Learning from the others - Community Rail - (new - 2015-07-12)
[4506] Peak weekend - where there are still rooms near Melksham
[4500] The TransWilts Community Intergrated Transport Corridor
Top or Show all for Melksham

Training from Well House Consultants
[4416] Challenging the IT course business model
[4415] Buffet review - taking the price into account
[4375] Final examples for 2014 - and a look at our 2015 training course options
[4358] A brilliant finish to 2014 training and business guests, and a look to 2015
[4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++
Top or Show all for Training from Well House Consultants

Running a training and hotel company
[4468] Four in a Bed - most popular answers
[4443] Seventh stay away this year - and it's still only February!
[4373] A long and disappointing evening
[4348] Taking my life in my hands in Swansea
[4321] Are administration / review charges on hotel guests acceptable?
Top or Show all for Running a training and hotel company

Well House Manor - Hotel and Training Centre
[4379] Well House Consultants / Well House Manor - Prices for 2015
[4299] The Best Bed and Breakfast in Melksham?
[4264] Weekend breaks by train to Melksham, Wiltshire
[4175] An alternative format for a new train service timetable
[4174] What would the extra trains from Melksham mean to your journey?
Top or Show all for Well House Manor - Hotel and Training Centre

For the Webmaster, Postmaster and moderator
[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
[4403] The unbalanced relationship between customer and provider
[4385] A booking that looks too good to be true? It probably is too good to be true!
Top or Show all for For the Webmaster, Postmaster and moderator

General Programming Topics
[4505] Regular Expressions for the petrified - in Ruby
[4457] Test framework for TCL - Tcltest - some examples
[4448] What is the difference between a function and a method?
[4430] The spirit of Java - delegating to classes
[4421] How healthy are the stars of stage and screen?
Top or Show all for General Programming Topics

PHP - the language and its application
[4483] Moving from mysql to mysqli - simple worked example
[4437] Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP
[4366] Changing what operators do on objects - a comparison across different programming languages
[4356] Object factories in C++, Python, PHP and Perl
[4319] PHP - some quick fixes if scripts have issues, and how to use our support
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
[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
[3884] Pictures - across the park, French Weir and River Tone, Taunton
[3800] Fancy a weekend away? Try Well House Manor in Melksham, Wiltshire
Top or Show all for Around, about and nearby to Wiltshire

The Perl Programming Language and its use
[4395] Preparing data through a little bit of Perl
[4301] Perl - still a very effective language indeed for extracting and reporting
[4296] Polishing the Perl courses - updated training
[4100] Perl Dancer - from installation to your first real application
[4099] Perl Dancer - a Perl Framework - Installation and first test
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
[4504] Where does Ruby load modules from, and how to load from current directory
[4503] Separating your code for easier testing, understanding and re-use; example in Ruby
[4502] Reading and parsing a JSON object in Ruby
[4501] Defining the behaviour of your web site and testing that it works
[4499] Significant work - beyond helloworld in Ruby
[4498] Ruby - where one statement ends and the next begins
[4402] Finding sum, minimum, maximum and average in Python (and Ruby)
[4389] Cucumber example - test::unit, scenario outlines, datafile driven test
[4388] Global Regular Expression matching in Ruby (using scan)
[4386] Guide exercise to help you learn Gherkin, Cucumber and Rspec
[4384] Installing Cucumber on Ubuntu - cannot load such file -- mkmf (LoadError) message
[4383] Improved test in Cucumber with RSpec
[4382] Second step Cucumber and Gherkin - beyond Hello World
[4381] Installing Cucumber (Ruby)
[4370] Conditionals, loops and methods in Ruby - a primer with simple examples
[4369] Ruby - the second rung of learning the language
[4368] Shuffling a list - Ruby and Python
[4294] A bright new gem - updated Ruby training
[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
[3783] Load path, load and require in Ruby, and a change from 1.8 to 1.9
[3782] Standard methods available on all objects in Ruby
[3781] Private, Protected, Public in Ruby. What about interfaces and abstract classes in Ruby?
[3780] Ruby of Rails - cleanly displaying model data in the view
[3779] Adding validation to form entries and sticky fields - Ruby on Rails
[3778] Providing a form to allow the user to add data to the model - Ruby on Rails
[3777] Multiple views in a single appication - sharing common parts of the template - Ruby on Rails
[3773] Ruby on the web - a simple example using CGI
[3772] Hello World - Ruby on Rails - a checklist of each step
[3769] Muttable v immutable and implications - Ruby
[3760] Why you should use objects even for short data manipulation programs in Ruby
[3758] Ruby - standard operators are overloaded. Perl - they are not
[3757] Ruby - a teaching example showing many of the language features in short but useful program
[3756] Ruby on Rails - how it flows, and where the files go
[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
[3432] 3 digit HTTP status codes - what are they, which are most common, which should be a concern?
[3431] Ruby at both extremes of your website
[3430] Sigils - the characters on the start of variable names in Perl, Ruby and Fortran
[3428] How many days to Christmas?
[3426] Automed web site testing scripted in Ruby using watir-webdriver
[3424] Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP
[3422] Assigning values to variables within other statements - Ruby
[3421] Ruby off the Rails?
[3260] Ruby - a training example that puts many language elements together to demonstrate the whole
[3255] Process every member of an array, and sort an array - Ruby
[3254] Multiple inputs, multiple out, ruby functions
[3253] Is this number between? Does this list include? - Ruby
[3158] Ruby training - some fresh examples for string handling applications
[3156] Splitting data reading code from data processing code - Ruby
[3155] Rake - a build system using code written in Ruby
[3154] Changing a class later on - Ruby
[2980] Ruby - examples of regular expressions, inheritance and polymorphism
[2979] Ruby - yield; parallel routines
[2977] What is a factory method and why use one? - Example in Ruby
[2976] Creating, extending, traversing and combining Ruby arrays
[2975] Why do I need brackets in Ruby ... or Perl, Python, C or Java
[2974] Formatting your output - options available in Ruby
[2893] Exclamation marks and question marks on ruby method names
[2892] Alternative loops and conditionals in Ruby and Perl
[2866] Ruby - how does it compare and where is it the right language?
[2826] Ruby - training for automated testing users
[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
[2621] Ruby collections and strings - some new examples
[2620] Direct access to object variable (attributes) in Ruby
[2619] Passing code to procedures and yield in Ruby
[2618] What are Ruby Symbols?
[2617] Comparing floating point numbers - a word of caution and a solution
[2615] String to number conversion with error trapping in Ruby
[2614] Neatly formatting results into a table
[2613] Constants in Ruby
[2610] Cheat Sheet - what do you need for Ruby on Rails?
[2609] Scope of variables - important to Ruby on Rails
[2608] Search and replace in Ruby - Ruby Regular Expressions
[2607] Answers on Ruby on Rails
[2606] Sorting arrays and hashes in Ruby
[2605] Ruby on Rails - a sample application to teach you how
[2603] Ruby objects - a primer
[2601] Ruby - is_a? v instance_of? - what is the difference?
[2296] Variable scope - what is it, and how does it Ruby?
[2293] Regular Expressions in Ruby
[2292] Object Orientation in Ruby - intermediate examples
[2291] Collection objects (array and hash) in Ruby
[2290] Opening and reading files - the ruby fundamentals
[2287] Learning to program in Ruby - examples of the programming basics
[2286] New to programming? It is natural (but needless) for you to be nervous
[2104] Ruby Programming and Rails - 4 different courses in one
[1891] Ruby to access web services
[1890] MySQL database from Ruby - an example
[1889] Ruby mixins, modules, require and include
[1887] Ruby Programming Course - Saturday and Sunday
[1875] What are exceptions - Python based answer
[1720] Some Ruby lesser used functions
[1588] String interpretation in Ruby
[1587] Some Ruby programming examples from our course
[1586] Variable types in Ruby
[1582] Ruby, C, Java and more - getting out of loops
[1302] Ruby, Ruby, Ruby. Rails, Rails, Rails.
[1050] The HTML++ Metalanguage
[1041] Learnt in London - Ruby, Martini, Coral and the Core
[1027] Cue the music, I'm happy.
[995] Ruby's case - no break
[991] Adding a member to a Hash in Ruby
[990] Ruby - Totally Topical
[987] Ruby v Perl - interpollating variables
[986] puts - opposite of chomp in Ruby
[985] Equality in Ruby - == eql? and equal?
[983] Blessing in Perl / Member variable in Ruby
[962] Breaking a loop - Ruby and other languages
[960] 1st, 2nd, 3rd revisited in Ruby
[664] Ruby course - oops - it's not happening
[550] 2006 - Making business a pleasure
[184] MTBF of coffee machines
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
[4462] Server program written in Tcl using sockets
[4461] Reading from a URL, and reading Json, from your Tcl script
[4460] Using Object Oriented Tcl and the Tk toolkit together - real life example
[4459] Managing the window size (and layout) in Tcl/Tk
[4458] A new Tcl/tk example - a window to show system status
Top or Show all for Tcl, Tcl/Tk and Expect

Programming in Lua
[4297] Lua courses - an update
[4274] String formatting in Lua - string.format as a wrapper for sprintf
[4273] Dot or Colon separator between table name and member in Lua - what is the difference?
[4272] Lazy operators in Lua - what they mean, and examples
[4271] Line, block and nested comments - Lua compared to other languages
Top or Show all for Programming in Lua

Python Programming
[4470] Testing in Python 3 - unittest, doctest and __name__ == __main__ too.
[4469] Sorting in Python 3 - and how it differs from Python 2 sorting
[4452] Binary data handling - Python and Perl
[4451] Running an operating system command from your Python program - the new way with the subprocess module
[4450] Deciding whether to use parameters, conditional statements or subclasses
Top or Show all for Python Programming

And also ...
[4507] In favour of adoption rather than puppy purchase - dogs!
[4490] What and where are the Azores?
[4489] Election results - what if we had a party list system?
[4488] Election day, 2015
[4485] Misusing statistics? - the seedy side of election campaigning
Top or Show all for And also ...

Public Transport
[4511] The Royal Albert Bridge as you do not normally see it - (new - 2015-07-12)
[4496] Sunday train times - 17th May to 6th September 2015
[4495] Swindon to Westbury train services - Saturdays from 23rd May 2015
[4486] Newark to New York - the PATH suburban railway
[4478] Home in Melksham to Gatwick Airport - easy by public transport
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
[4509] Throwing a die - exercise in Ruby - (new - 2015-07-01)
[4508] Melksham to London by train - dont buy more than you need
[4484] TransAtlantic crossing - the starter
[4242] A busy January
[4237] Why the long gap?
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 July 2015May 2015March 2015January 2015November 2014September 2014July 2014May 2014March 2014 • 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