Skip to content

Starting with a full bucket #6

Description

@grr

Algorithm::TokenBucket always starts with an empty bucket, so processing will always start with a delay. That's not immediately apparent unless you're familiar with the algorithm details. It would be nice if you could specify in the constructor to start with a full bucket. An undocumented way to do this is to call count with a negative token count. Looking at other implementations in other languages, this is not an uncommon desire. In fact some implementations default to starting with a full bucket (like golang.org/x/time/rate).

Also, after looking at the example in the docs using 2 rate limiters together, it might be convenient to make until smarter to deal with multiple buckets, e.g. $rl1->until(1, $rl2, ...). And internally it would compute max($rl1->until(1), $rl2->until(1), ...).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions