Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26 Implemented leaky bucket rate limiter #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kevkevy3000
Copy link
Contributor

  • Added in new leaky bucket rate limiting functionality
  • Added in new test cases for the leaky bucket rate limiting component

class LeakyBucket:
"""
Leaky Bucket Logic
Leak tokens as time passes on. If there is space in the bucket, executions can be allowed.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevkevy3000 according to my understanding this implementation looks like token bucket rather than leaky bucket.

In leaky bucket, consumers are collected in a bucket as long as bucket size allows (and get rejected if not) In the meanwhile, as time goes on, we let some of these waiting consumers to execute. So in some way, it's more complicated flow than token bucket.

I would imagine this being implemented in a similar way to asyncio.Queue.
Concretely, we maintain a queue of waiters. We add a consumer to the queue on attempt to "take" a token. It seems like we also need to have a separate task that will wake up waiters as time goes on.
This way we could really smooth incoming requests.

Does this make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Implement leaky bucket rate limiter
2 participants