Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Algorithm-TokenBucket CPAN distribution.

Report information
The Basics
Id: 94879
Status: open
Priority: 0/
Queue: Algorithm-TokenBucket

People
Owner: Nobody in particular
Requestors: perl [...] pied.nu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Calling ->count() with a negative number
First, thank you for this module. I'm using it to implement rate limiting for sending invoices. Second, the API is a bit akward for what I want to do. It would be nice to have an interface that would allow one to ask "I have $N tokens to process" and the answer would be "oh no, you can only do $burst of those tokens". Currently I use while ($N) { last unless $limiter->conform( 1 ); $limiter->count(1); $N--; process( $todo->[$N] ); } Lastly, in testing I noticed it worked differently from what I expected. It starts out with an empty token bucket. Normaly this isn't a problem; in operation, the system will reach $burst by the time a batch of invoices need to be sent. But if there is a batch of pending invoices at startup, they trickle through. The solution is $limiter->count( -$burst ); This will "fill" the token bucket, but is an artifact of implementation. While this usage be deprecated at some point?
Hi! I think both your requests are quite reasonable. 1) Maybe conform() should return the number of tokens currently allowed. 2) Maybe new() should accept a non-default option to start with a full bucket instead of empty. Care to implement it? :) Thanks! Суб Апр 19 13:51:25 2014, GWYN писал: Show quoted text
> First, thank you for this module. I'm using it to implement rate > limiting for sending invoices. > > Second, the API is a bit akward for what I want to do. It would be > nice to have an interface that would allow one to ask "I have $N > tokens to process" and the answer would be "oh no, you can only do > $burst of those tokens". Currently I use while ($N) { last unless > $limiter->conform( 1 ); $limiter->count(1); $N--; process( $todo->[$N] > ); } > > Lastly, in testing I noticed it worked differently from what I > expected. It starts out with an empty token bucket. Normaly this > isn't a problem; in operation, the system will reach $burst by the > time a batch of invoices need to be sent. But if there is a batch of > pending invoices at startup, they trickle through. The solution is > $limiter->count( -$burst ); This will "fill" the token bucket, but is > an artifact of implementation. While this usage be deprecated at some > point?