NAME
Sub::Throttler::Periodic::EV - throttle by rate (quantity per time)
VERSION
This document describes Sub::Throttler::Periodic::EV version v0.2.10
SYNOPSIS
use Sub::Throttler::Periodic::EV;
# default limit=1, period=1
my $throttle = Sub::Throttler::Periodic::EV->new(period => 0.1, limit => 42);
my $limit = $throttle->limit;
$throttle->limit(42);
my $period = $throttle->period;
$throttle->period(0.1);
# --- 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; # OR
return { key1=>$quantity1, ... };
});
# --- Manual resource management
if ($throttle->try_acquire($id, $key, $quantity)) {
...
$throttle->release($id);
$throttle->release_unused($id);
}
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 uses EV::periodic, but will avoid keeping your event loop running when it doesn't needed anymore (if there are no acquired resources).
EXPORTS
Nothing.
INTERFACE
Sub::Throttler::Periodic::EV inherits all methods from Sub::Throttler::algo and implements the following ones.
new
my $throttle = Sub::Throttler::Periodic::EV->new;
my $throttle = Sub::Throttler::Periodic::EV->new(period => 0.1, limit => 42);
Create and return new instance of this algorithm.
Default period
is 1.0
, limit
is 1
.
See "new" in Sub::Throttler::algo for more details.
period
my $period = $throttle->period;
$throttle = $throttle->period($period);
Get or modify current period
.
limit
my $limit = $throttle->limit;
$throttle = $throttle->limit(42);
Get or modify current limit
.
load
my $throttle = Sub::Throttler::Periodic::EV->load($state);
Create and return new instance of this algorithm.
See "load" in Sub::Throttler::algo for more details.
save
my $state = $throttle->save();
Return current state of algorithm needed to restore it using "load" after application restart.
See "save" in Sub::Throttler::algo for more details.
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at https://github.com/powerman/perl-Sub-Throttler/issues. You will be notified automatically of any progress on your issue.
Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests.
https://github.com/powerman/perl-Sub-Throttler
git clone https://github.com/powerman/perl-Sub-Throttler.git
Resources
MetaCPAN Search
CPAN Ratings
AnnoCPAN: Annotated CPAN documentation
CPAN Testers Matrix
CPANTS: A CPAN Testing Service (Kwalitee)
AUTHOR
Alex Efros <powerman@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2014- by Alex Efros <powerman@cpan.org>.
This is free software, licensed under:
The MIT (X11) License