Giter Site home page Giter Site logo

Performance problem about token-bucket HOT 3 CLOSED

bbeck avatar bbeck commented on July 28, 2024
Performance problem

from token-bucket.

Comments (3)

bbeck avatar bbeck commented on July 28, 2024

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.

savinov avatar savinov commented on July 28, 2024

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.

bbeck avatar bbeck commented on July 28, 2024

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)

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.