Comments (3)
Hi Guram, thanks for reporting your issue. I've just performed a release of version 1.2 that provides a fix for your problem. Version 1.2 introduces the ability to choose a strategy for determining how to sleep when no tokens are available. The existing strategy is still present, and is the default, but a new busy wait strategy is available via the builder class inside of TokenBuckets
. Please be aware that the busy wait strategy will consume a lot of CPU in order to be more accurate.
from token-bucket.
It's the problem: to have needed precision and to allow CPU to do other work. I think sleep intrval for a few microseconds is enough for the most users. But it should not eat a lot of CPU time.
from token-bucket.
Guram, both sleep strategies are present. You can use the yielding sleep strategy if you prefer something that doesn't consume lots of CPU, but might be a bit less precise. If you require as precise of a solution as possible, then you can use the busy wait strategy -- it gains precision at the sacrifice of CPU time.
// Using the yielding sleep strategy
TokenBucket bucket = TokenBuckets.builder()
.withCapacity(...)
.withFixedIntervalRefillStrategy(...)
.withYieldingSleepStrategy()
.build();
// Using the busy wait sleep strategy
TokenBucket bucket = TokenBuckets.builder()
.withCapacity(...)
.withFixedIntervalRefillStrategy(...)
.withBusyWaitSleepStrategy()
.build();
from token-bucket.
Related Issues (9)
- To make TokenBucketImpl serializable HOT 2
- Issue should be ignored and deleted HOT 1
- FixedIntervalRefillStrategy assumes period to be starting at 0. HOT 1
- Add accessors for next refill timestamp, number tokens remaining in bucket and capacity HOT 4
- 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.