Giter Site home page Giter Site logo

Comments (4)

bbeck avatar bbeck commented on May 20, 2024

The getCapacity and getNumTokensRemaining methods would be really easy to add.

The getNextRefillTimestamp method would be substantially harder and require some non-backwards compatible redesigning as the refill strategy is abstracted away from the actual token bucket implementation. Can you share the use case that requires you to know how long until you'll receive tokens?

from token-bucket.

mmadson avatar mmadson commented on May 20, 2024

Thanks for the response!

The use case I'm considering using this for is rate limiting a web service API. Ideally we'd like to respond to successful requests with the following response headers:

RateLimit-Limit
RateLimit-Remaining
RateLimit-Cost
RateLimit-Reset

Limit would be the max capacity for a user's token bucket, i.e., how many tokens they get when the current interval ends thus refilling their bucket.

Remaining would be the current size of the token bucket, i.e., number of tokens remaining in the bucket for the current interval.

Cost is how many tokens a user needs to make a the request.

Reset is the UTC timestamp for when the current interval ends and the user's token bucket is set to Limit (capacity).

So the only missing piece of the puzzle is getting the timestamp of the next refill.

What about adding an accessor for the timestamp to both the TokenBucket and the RefillStrategy and having the TokenBucket call it to get the time of the next refill. For RefillStrategies that are not time based, they could return null or 0?

Thanks!

from token-bucket.

bbeck avatar bbeck commented on May 20, 2024

Version 1.5 has been built and should show up in maven central within the next few hours.

from token-bucket.

mmadson avatar mmadson commented on May 20, 2024

I'm simply amazed by your responsiveness and efficiency. Thanks again!

from token-bucket.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.