Comments (10)
Thanks! I'll check it out.
from leaky-bucket.
Added your code using an explicit coordinator as a test case to #6.
from leaky-bucket.
Thanks for the quick turn around!
BTW, if in my app I want to create and destroy
LeakyBucket
rate limiters, is there a way to tear it down?
Or should I use the explicit coordinator approach, or it's OK to use the static one?
You should use the explicit coordinator, and spawn it within the runtime as appropriate. I've added documentation to hopefully explain this, and released 0.8.0
with it along with some other changes.
Thanks for the report!
from leaky-bucket.
Released in 0.8.1
. Hope it helps!
from leaky-bucket.
So I'm like 90% sure this is because the static
feature (LeakyBucket::builder()
relies on) uses whatever runtime is available to spawn the coordinator background thread, and each test case annotated with tokio::test
uses a separate runtime. Once the runtime is dropped, the coordinator task is dropped with it.
There's two readily available solutions:
- Use an explicit coordinator in the test case or environment where multiple runtimes are used.
- We change it so that it spawns a static runtime to run the coordinator thread on. Something I'm not very keen on honestly.
At the very least I'll add a description to the documentation that this is a potential footgun with the static
feature for now.
from leaky-bucket.
Thanks for the quick turn around!
BTW, if in my app I want to create and destroy LeakyBucket
rate limiters, is there a way to tear it down?
Or should I use the explicit coordinator approach, or it's OK to use the static one?
from leaky-bucket.
Okay, I finally integrated the library and seems to work:
e.g. I can run a load test with an increasing ladder. But if I upgrade the library to 0.8
it panics:
$ perf-gauge -r 100 -d 5s http http://localhost:8088/10kb --conn_reuse
thread 'tokio-runtime-worker' panicked at 'new task queue ended', /Users/xnuter/.cargo/registry/src/github.com-1ecc6299db9ec823/leaky-bucket-0.8.0/src/lib.rs:200:67
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at 'Unexpected LeakyBucket.acquire error: "Failed to send task to coordinator"', src/bench_run.rs:96:18
P.S. BTW, it seems that the coordinator never exits, even on dropping the rate limiter, as these log messages are never printed: https://github.com/xnuter/perf-gauge/blob/2204689a29fc7bb6133372d952f5438ac0e525ef/src/rate_limiter.rs#L45-L50
from leaky-bucket.
Ah, yeah. The coordinator was never designed to shut down 😄 . But now I see that's indeed possible since the coordinator task sheds the LeakyBucketsInner
.
I've added some code to handle this in #7. I think this should fix it. Thanks again!
from leaky-bucket.
Great, thanks for the quick response! Now it works and I can see that the coordinator gracefully exits on dropping the rate limiter. But now a new issue, the rate is wrong. E.g. the same rate 2,000 per second works correctly in 0.7
but in 0.8
it never goes above 200 rps
, no matter what rate I specify:
0.7
:
➜ perf-gauge git:(master) ✗ cargo build --release && ./target/release/perf-gauge -c 2 -r 2000 -d 10s http http://localhost:8088/ --conn_reuse
Duration 10.002314489s
Requests: 19978
Request rate: 1997.338 per second
Success rate: 100.000%
Total bytes: 199.8 MB
Bitrate: 159.787 Mbps
0.8.1
:
➜ perf-gauge git:(master) ✗ cargo build --release && ./target/release/perf-gauge -c 2 -r 2000 -d 10s http http://localhost:8088/ --conn_reuse
Duration 10.002537332s
Requests: 2000
Request rate: 199.949 per second
Success rate: 100.000%
Total bytes: 20.0 MB
Bitrate: 15.996 Mbps
from leaky-bucket.
from leaky-bucket.
Related Issues (7)
- Wrong example in readme HOT 2
- How to call in Future HOT 1
- Allow modifying the drip interval of an existing RateLimiter
- Allow manually refilling a RateLimiter HOT 3
- Allow a way for the rate limiter to return error without blocking if enough tokens are not available HOT 10
- Rate limiter doesn't hit its target
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 leaky-bucket.