NAME
Sub::Throttler::Rate::EV - throttle by rate (quantity per time)
SYNOPSIS
use Sub::Throttler::Rate::EV;
# default limit=1, period=1
my $throttle = Sub::Throttler::Rate::EV->new(period => 0.1, limit => 42);
my $limit = $throttle->limit;
$throttle->limit(42);
my $period = $throttle->period;
# --- Activate throttle for selected subrouties
$throttle->apply_to_functions('Some::func', 'Other::func2', …);
$throttle->apply_to_methods('Class', 'method', 'method2', …);
$throttle->apply_to_methods($object, 'method', 'method2', …);
$throttle->apply_to(sub {
my ($this, $name, @params) = @_;
...
return undef or $key or ($key,$quantity) or \@keys or (\@keys,\@quantities);
});
# --- Manual resource management
if ($throttle->acquire($id, $key, $quantity)) {
...
$throttle->release($id);
$throttle->release_unused($id);
}
my $quantity = $throttle->used($key);
$throttle->used($key, $quantity);
DESCRIPTION
This is a plugin for Sub::Throttler providing simple algorithm for throttling by rate (quantity per time) of used resources.
This algorithm works like Sub::Throttler::Limit with one difference: when current time is divisible by given period value all used resources will be made available for acquiring again.
It use EV::timer, but tries to avoid keeping your event loop running when it doesn't needed anymore by stopping timer watcher at end of period if there are no acquired resources.
EXPORTS
Nothing.
INTERFACE
Sub::Throttler::Rate::EV inherits all methods from Sub::Throttler::Limit and implements new or replaces the following ones.
- new
-
my $throttle = Sub::Throttler::Rate::EV->new; my $throttle = Sub::Throttler::Rate::EV->new(period => 0.1, limit => 42);
Create and return new instance of this algorithm.
Default
period
is1.0
,limit
is1
.See "new" in Sub::Throttler::Limit for more details.
- period
-
my $period = $throttle->period;
Get current
period
.
BUGS AND LIMITATIONS
No bugs have been reported.
SUPPORT
Please report any bugs or feature requests through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sub-Throttler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
AUTHOR
Alex Efros <powerman@cpan.org>
LICENSE AND COPYRIGHT
Copyright 2014 Alex Efros <powerman@cpan.org>.
This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.