Algorithm-LeakyBucket

 view release on metacpan or  search on metacpan

lib/Algorithm/LeakyBucket.pm  view on Meta::CPAN

	 $bucket->seconds(5);
     }
 }


=head1 CONSTRUCTOR

There are two required options to get the module to do anything useful.  C<ticks> and C<seconds> set the number of 
ticks allowed per that time period.  If C<ticks> is 3 and C<seconds> is 14, you will be able to run 3 ticks every 14 
seconds.  Optionally you can pass C<memcached_servers> and C<memcached_key> to distribute the limiting across multiple
processes.


 my $bucket = Algorithm::LeakyBucket->new( ticks => $ticks, seconds => $every_x_seconds,
                                  memcached_key => 'some_key',
                                  memcached_servers => [ { address => 'localhost:11211' } ] );

=DESCRIPTION

Implements leaky bucket as a rate limiter.  While the code will do rate limiting for a single process, it was intended
as a limiter for multiple processes. (But see the BUGS section)

The syntax of the C<memcached_servers> argument should be the syntax expected by the local memcache module.  If
Cache::Memcached::Fast is installed, use its syntax, otherwise you can use the syntax for Cache::Memcached.  If 
neither module is found it will use a locally defined set of vars internally to track rate limiting.  Obviously
this keeps the code from being used across processes. 

This is an alpha version of the code.  Some early bugs have been ironed out and its in produciton in places, so we would
probably transition it to beta once we have seen it work for a bit. 

=cut

use 5.008008;
use strict;
use warnings;
use Carp qw(cluck);



( run in 0.227 second using v1.01-cache-2.11-cpan-8d75d55dd25 )