Closed MementoRC closed 2 years ago
I usually wouldn't suggest overriding those as they're private and might change without notice (not that I'm planning to change it but still).
What do you mean by filling bucket though? What are you trying to achieve?
What I meant is that in my app, I may need to use a variety of limiters, so if I want to have both, I would have a new class that inherit from yours and in that class I'd override the methods, they can thus change in the base class
One of the API that I use is using the lazy-fill method, it fills the bucket with time instead of leaking it and uses the tokens in the bucket per request instead of filling the bucket with requests. It is basically the opposite (as far as i can understand it) to the Leaky method. I don't see that there is a difference, but on the other hand, it seems to simple to modify (even for me) that I would rather say "I use exactly what the API say", rather than "Well, the rate limiter is theoretically the same" to my code reviewers Actually, you commented on another aiolimiter from mjpieters and another user asked a PR: https://github.com/mjpieters/aiolimiter/pull/74, which was summarily closed Thanks a lot for your reply
On Sun, Sep 4, 2022 at 11:27 AM Bar Harel @.***> wrote:
I usually wouldn't suggest overriding those as they're private and might change without notice (not that I'm planning to change it but still).
What do you mean by filling bucket though? What are you trying to achieve?
— Reply to this email directly, view it on GitHub https://github.com/bharel/asynciolimiter/issues/3#issuecomment-1236374465, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGZEZ3JN6MV7ZHHLFPWU2TV4TEXLANCNFSM6AAAAAAQECU57I . You are receiving this because you authored the thread.Message ID: @.***>
Well it sounds exactly the same to be honest.
Full bucket in the API's algorithm == an empty leaky bucket. Every 'tick' the leaky bucket drains until empty, and yours fills until full. The only difference that might be is the starting condition, but I believe the API starts like a full bucket, which is equivalent to an empty leaky bucket.
I can add documentation showing the exact similarities.
Regarding overriding private methods - if the "wait()" method changes and no longer uses '_wake_up' and '_maybe_lock' (which it can as long as wait still works the same), it will cause a bug in your code. It's not planned and shouldn't be too much of an issue but you should know about it and make sure you write the code well including version pinning and good tests :-)
Thanks, I couldn't find a conceptual difference either. I don't know how popular is the lazy-fill version, it could be helpful to mention it, for general audience. We can close this issue, since it's not one Regards
On Fri, Sep 9, 2022, 8:14 PM Bar Harel @.***> wrote:
Well it sounds exactly the same to be honest.
Full bucket in the API's algorithm is equivalent to an empty leaky bucket. Every 'tick' the leaky bucket drains until empty, and yours fills until full. The only difference that might be is the starting condition, but I believe the API starts like a full bucket, which is equivalent to an empty leaky bucket.
I can add documentation showing the exact similarities.
— Reply to this email directly, view it on GitHub https://github.com/bharel/asynciolimiter/issues/3#issuecomment-1242585426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGZEZ2MWEX2BOKQNP4PBFLV5POF3ANCNFSM6AAAAAAQECU57I . You are receiving this because you authored the thread.Message ID: @.***>
I can't seem to find any mention of it anywhere.
Hopefully I managed to help you a bit :-)
Just FYI, a few references. The API where I first saw it mentioned is Coinbase https://www.quinbay.com/blog/understanding-rate-limiting-algorithms https://dev.to/satrobit/rate-limiting-using-the-token-bucket-algorithm-3cjh Thanks for the discussion
On Sat, Sep 10, 2022 at 6:37 AM Bar Harel @.***> wrote:
I can't seem to find any mention of it anywhere.
— Reply to this email directly, view it on GitHub https://github.com/bharel/asynciolimiter/issues/3#issuecomment-1242711129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGZEZ2YEG6D6RKRKOZAO63V5RXJFANCNFSM6AAAAAAQECU57I . You are receiving this because you authored the thread.Message ID: @.***>
Thank you.
So the algorithm is called token bucket, and according to Wikipedia, it is exactly equivalent to the leaky bucket as a meter, meaning exact same input and exact same output with no difference at all :-)
Fundamentally, the two algorithms are the same, and will, if implemented correctly and given the same parameters, see exactly the same packets as conforming and nonconforming.
Basically it's another analogy meant only to confuse us 😋
I am interested in having a filling bucket rather than a draining one. Would it make sense to derive from the Leaky and override '_maybe_lock()' and '_wake_up()', or would you advise a simpler method?