Comments (4)
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.
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.
Version 1.5 has been built and should show up in maven central within the next few hours.
from token-bucket.
I'm simply amazed by your responsiveness and efficiency. Thanks again!
from token-bucket.
Related Issues (9)
- Performance problem HOT 3
- To make TokenBucketImpl serializable HOT 2
- Issue should be ignored and deleted HOT 1
- FixedIntervalRefillStrategy assumes period to be starting at 0. HOT 1
- getNumTokens() not returning capacity() initially HOT 8
- Support programmatically refilling token buckets HOT 2
- Provide snapshot of numTokens / duration until next refill HOT 4
- Should the yielding sleep strategy call Thread.yield()? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from token-bucket.