Giter Club home page Giter Club logo

limiter's Issues

How do I use Jitter? Can we add this to the Readme?

I'm having a hard time understanding jitter as it relates to my other params.

According to Base, DEFAULT_JITTER: = False, and it doesn't seem like DEFAULT_JITTER is ever updated when I call a new Limiter(). I know I can set it as an arg with Limiter(jitter=X).

I also saw in Base in the definition for _get_sleep_duration

def _get_sleep_duration(
  consume: Tokens,
  tokens: Tokens,
  rate: Tokens,
  jitter: Jitter = DEFAULT_JITTER,
  units: UnitsInSecond = MS_IN_SEC
) -> Duration:
  """Increase contention by adding jitter to sleep duration"""
  duration: Duration = (consume - tokens) / rate
  
  match jitter:
    case int() | float():
      return duration - jitter
 
    case bool() if jitter:
      amount: Duration = random() / units
      return duration - amount

  return duration

It's clear that jitter can be a bool, int, or float, but I don't really understand how I should size it with respect to my consume or rate values. I don't want to add too much jitter that it ends up overpowering my sleep duration and I end up with a negative number.

Let's say I have these params:

  • rate = 20 # replenish tokens per second
  • consume = 1 # because I want my function to be allowed to run a maximum of 20 times per second
  • capacity = 300 # because I want my function to be able to run for 15 seconds maximum before it gets limited (function can't get called more than 300 times per minute max)

But according to the _get_sleep_duration calculation, my duration = (1 - 300) / 20 = -14.95 and so I'm already at a negative number.

  • Am I thinking about my params correctly?
  • What's the right way to add jitter as a param?

Add more documentation

I couldn't figure out what the parameter 'consume' meant, it would be great if the readme elaborated some more on that. "The amount of tokens to consume dynamically" - sorry I have no idea what this means. Thank you!

Breaking changes in 0.3.0

0.3.0 will break pretty much all of it's consumers if they haven't pinned the release. The changelog simply says "Update API".

ImportError: cannot import name 'get_limiter' from 'limiter'

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.