Set::Cluster - Distribute items across nodes in a load balanced way and show takeovers in failure scenarios
# Hash of items, with relative weighting $h = { 'Oranges' => 17, 'Apples' => 3, 'Lemons' => 10, 'Pears' => 12 }; $c = Set::Cluster->new; $c->setup( nodes => [qw(A B C)], items => $h ); $c->calculate(2); # Go 2 levels deep # Functions to parse $c->results @takeover = $c->takeover( node => "A", fail => "C" ); # Items taken over due to a failure of C @items = $c->items( node => "A", fail => "B" ); # All items for A, when B has failed $node = $c->hash_by_item( fail => "" ); # Returns a hash where $node->{$item} returns the node name $results = $c->results; # Returns a hash with how items are split across the nodes # This structure may change in future
This is an attempt at abstracting clustering. The idea is that you can define a list of items with relative weightings, and a list of nodes that the items should be spread across.
The plugin then calculates where items will be distributed to balance the weightings. If you calculate more than 1 level, it will show what happens if there is a failure. When a node fails, its items are distributed amongst the remaining nodes.
The algorithm used is simple: sort the items by the largest weight, then add to the node with the lowest total weight so far.
There is a limitation in that nodes that have not failed should not redistribute their items - this is because of my main reason for creating this module (see HISTORY).
This is not the best algorithm in the world, so if you can implement a better one, I'd love to hear.
Sets the list of nodes and all the items.
Sets the list of nodes and items. The only restriction for the item objects is that it must support a weight method, in order to get the weight value of each object.
Works out all the possible failure scenarios. A level of 0 means just distribute, a level of 1 works out a single point of failure scenario, etc.
Returns an unordered list of items that were added to the specified node at the failure scenario specified.
Returns an unordered list of items that the specified node has at the time of the failure scenario.
Returns a hash ref where the index is item with value of node.
Returns the hash ref holding all the results. The structure is:
'' => Set::Cluster::Result=HASH(0x84e01c4) 'A' => ARRAY(0x84eb370) 0 'Oranges' 1 'Lemons' 'B' => ARRAY(0x84e0050) 0 'Strawberries' 1 'Melons' 2 'Apples' 'C' => ARRAY(0x84dffb4) 0 'Pears' 1 'Bananas' 2 'Kiwis' 'A' => Set::Cluster::Result=HASH(0x84eb328) 'B' => ARRAY(0x84ebaa8) 0 'Strawberries' 1 'Melons' 2 'Apples' 3 'Oranges' 'C' => ARRAY(0x84ebad8) 0 'Pears' 1 'Bananas' 2 'Kiwis' 3 'Lemons' ...
The first section shows a distribution with no failures. The second section is what happens when node A fails. If there is more than one failure, the key will be "failure1,failure2".
This is for curious minds. The preferred way to access this data is via the other methods, as this structure may change in future.
When using objects as the node or the items, the stringification of the object must be unique, otherwise funny things will happen!
This plugin was originally designed for generating Nagios (http://nagios.org) configurations for clustered slave monitoring servers. The items are hosts, with the weighting as the number of services monitored on each host.
As this module can predict what would happen in failure scenarios, an event handler can be setup to start monitoring particular hosts in a takeover situation.
If you have a different use for this module, I would be interested to hear.
Only methods listed in this documentation are public.
These modules are experimental and so the interfaces may change up until Set::Cluster hits version 1.0, but every attempt will be made to make backwards compatible.
Ton Voon, <ton.voon@altinity.com>
Copyright (C) 2006 by Altinity Limited
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
To install Set::Cluster::Result, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Set::Cluster::Result
CPAN shell
perl -MCPAN -e shell install Set::Cluster::Result
For more information on module installation, please visit the detailed CPAN module installation guide.