Sub::Throttler::Rate::AnyEvent - throttle by rate (quantity per time)
This document describes Sub::Throttler::Rate::AnyEvent version v0.2.10
use Sub::Throttler::Rate::AnyEvent; # default limit=1, period=1 my $throttle = Sub::Throttler::Rate::AnyEvent->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); }
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: resources acquired earlier than given period value will be made available for acquiring again.
It uses AE::timer, but will avoid keeping your event loop running when it doesn't needed anymore (if there are no acquired resources).
For throttling sync subs this algorithm can be used even without event loop, but if you'll use huge amount of unique resource names in long-running application then some memory will leak.
Nothing.
Sub::Throttler::Rate::AnyEvent inherits all methods from Sub::Throttler::algo and implements the following ones.
my $throttle = Sub::Throttler::Rate::AnyEvent->new; my $throttle = Sub::Throttler::Rate::AnyEvent->new(period => 0.1, limit => 42);
Create and return new instance of this algorithm.
Default period is 1.0, limit is 1.
period
1.0
limit
1
See "new" in Sub::Throttler::algo for more details.
my $period = $throttle->period; $throttle = $throttle->period($period);
Get or modify current period.
my $limit = $throttle->limit; $throttle = $throttle->limit(42);
Get or modify current limit.
NOTE: After decreasing limit in some case maximum of limits used while current period may be used instead of current limit for next period.
my $throttle = Sub::Throttler::Rate::AnyEvent->load($state);
See "load" in Sub::Throttler::algo for more details.
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.
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.
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
MetaCPAN Search
https://metacpan.org/search?q=Sub-Throttler
CPAN Ratings
http://cpanratings.perl.org/dist/Sub-Throttler
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Sub-Throttler
CPAN Testers Matrix
http://matrix.cpantesters.org/?dist=Sub-Throttler
CPANTS: A CPAN Testing Service (Kwalitee)
http://cpants.cpanauthors.org/dist/Sub-Throttler
Alex Efros <powerman@cpan.org>
This software is Copyright (c) 2014- by Alex Efros <powerman@cpan.org>.
This is free software, licensed under:
The MIT (X11) License
To install Sub::Throttler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Throttler
CPAN shell
perl -MCPAN -e shell install Sub::Throttler
For more information on module installation, please visit the detailed CPAN module installation guide.