Jerome Eteve > Class-TLB > Class::TLB

Download:
Class-TLB-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Class::TLB - Transparent load balancing for any resource class.

VERSION ^

Version 0.01

SYNOPSIS ^

    my $tlb = Class::TLB->new() ;

build a set of resource (dummy for instance) and register them

    foreach my $i ( 1 .. 3 ){
      $tlb->tlb_register(Class::TLB::Dummy->new($i)) ;
    }

You can now use the object $tlb the same way you would use a single instance of resource.

Example with instances of Class::TLB::Dummy:

    # doSomething, oneFail and doFail are implemented in the Dummy class.
    $tlb->doSomething() ;

The $tlb object will automatically balance the usage on the set of resources given and will avoid temporary resource failures:

    $tlb->oneFail() ; # This call is ok because only one resource will fail.

    $tlb->doFail()  ; # This call will confess an error because there is an 
                      # implementation error in the resource that makes it fail all the time.

Usage scenario:

You can use a Class::TLB wrapper to balance the usage of a set of similar distant resources.

In case the distant connection breaks in one of them, your client code will not suffer from it since Class::TLB will avoid single resources failures.

For this to work, your resource must die or confess in case of disconnection.

In case there is a logical flaw in a resource method, Class::TLB will die with the error when you call it.

Because Class::TLB will attempt to use each resource instance and fail if all of them are failing.

BEST PRACTICES ^

Fail, but fail fast

If your resources represent a distant service accessed through the network, make sure that the connection failure dies quickly.

Long connection timeouts can cause waiting queries to accumulate in your application and can lead to an interruption of service, even if the other resources of the pool are perfectly healthy.

In particular, if your resources use cURL to connect to the distant service, make sure you set a short CURLOPT_CONNECTTIMEOUT (or CURLOPT_CONNECTTIMEOUT_MS) option.

CAVEATS ^

Your managed resources can not implement any of the methods implemented in Class::TLB.

All Class::TLB methods are prefixed with 'tlb_', making a collision very unlikely.

FUNCTIONS ^

new

isa

Overrides the UNIVERSAL::isa method to allow client code to transparently call isa method on balanced resources.

Usage: if ( $this->isa('Class::TLB::Dummy')){ ... }

can

Overrides the UNIVERSAL::can method to allow client code to transparently call can method on balanced resources.

Usage: if ( $this->can('doSomething')){ ... }

tlb_class

Returns the class of resources being load balanced.

usage: my $class = $tlb->tlb_class() ;

tlb_prototype

Returns an instance of resources being load balanced.

tlb_usecount

Returns the usage statistic hash of all sources.

usage: my $hcount = $tlb->tlb_usecount() ;

tlb_register

Registers a new resource to be managed by this load balancer.

The first call of this methods records the expected resource class. Subsequent calls will fail if the given resource is from a different class.

Usage: $tlb->tlb_register($resource);

AUTHOR ^

Jerome Eteve, <jerome at eteve.net>

BUGS ^

Please report any bugs or feature requests to bug-class-tlb at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-TLB. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Class::TLB

You can also look for information at:

ACKNOWLEDGEMENTS ^

COPYRIGHT & LICENSE ^

Copyright 2010 Jerome Eteve, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: