Subject: | Feature request: min_items parameter |
Hello,
I would like to request support for a "min_items" parameter to
Data::Throttler.
This would allow the use of Data::Throttler to be used in what I would
describe as "threshold mode," as well as the current "throttle" mode.
Basically:
If min_items is defined, try_push will return false unless there are at
least min_items events counted in the buckets. However, the try_push()
call will still increment the current bucket's count, even if the
min_items threshold was not reached yet.
(This would implicitly make max_items optional if min_items was specified.)
I would be using this for rate limiting of events other than data
output. The way I would use this would be to create restrictions such
as, "an event X won't happen unless it has happened at least 3 times in
an hour." For example: if an error condition occurs too many times,
send an e-mail notification to someone about it.
It is almost adequate to test !$throttler->try_push() instead of
modifying Data::Throttler. However, the reason this will not work is
because once $throttler->try_push starts returning false, the events are
no longer counted. In this case, even if the event happens many times,
and the Throttler should remain above the threshold limit, the events
aren't recorded, so the buckets empty out and try_push() starts
returning true (so the event threshold is no longer reached).
You may consider this feature request to be outside the scope of what
you intended to do with Data::Throttler. However, your module is
already very useful for generic event rate limiting outside the realm of
data transit, and supporting min_items would make it even more useful in
this regard.
Thanks!
Alan Ferrency