Giter VIP home page Giter VIP logo

Comments (10)

udoprog avatar udoprog commented on August 26, 2024 1

Thanks! I'll check it out.

from leaky-bucket.

udoprog avatar udoprog commented on August 26, 2024 1

Added your code using an explicit coordinator as a test case to #6.

from leaky-bucket.

udoprog avatar udoprog commented on August 26, 2024 1

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.

udoprog avatar udoprog commented on August 26, 2024 1

Released in 0.8.1. Hope it helps!

from leaky-bucket.

udoprog avatar udoprog commented on August 26, 2024

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.

xnuter avatar xnuter commented on August 26, 2024

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.

xnuter avatar xnuter commented on August 26, 2024

Okay, I finally integrated the library and seems to work:

https://github.com/xnuter/perf-gauge/blob/2204689a29fc7bb6133372d952f5438ac0e525ef/src/rate_limiter.rs#L42

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.

udoprog avatar udoprog commented on August 26, 2024

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.

xnuter avatar xnuter commented on August 26, 2024

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.

udoprog avatar udoprog commented on August 26, 2024

@xnuter moved to #9

from leaky-bucket.

Related Issues (7)

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.