Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rate limiter TokenBucket::auto_replenish() #3370

Merged

Commits on Jan 17, 2023

  1. fix: Rate limiter TokenBucket::auto_replenish()

    Frequently calling `auto_replenish` will reset `self.last_update` each
    time and `tokens` may be a fractional value (0 since it is a `u64`), in
    this case no tokens will replenished.
    
    To avoid this we increment `self.last_update` by the minimum time
    required to generate `tokens`, in the case where we have the time to
    generate `1.8` tokens but only generate `x` tokens due to integer
    arithmetic this will carry the time required to generate 0.8th of a
    token over to the next call, such that if the next call where to
    generate `2.3` tokens it would instead generate `3.1` tokens. This
    minimizes dropping tokens at high frequencies.
    
    Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
    JonathanWoollett-Light committed Jan 17, 2023
    Configuration menu
    Copy the full SHA
    4d2edfa View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2023

  1. Configuration menu
    Copy the full SHA
    50fe13b View commit details
    Browse the repository at this point in the history