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

feature request: rate limit factor as decorator parameter #12

Open
alafanechere opened this issue May 30, 2024 · 1 comment
Open

feature request: rate limit factor as decorator parameter #12

alafanechere opened this issue May 30, 2024 · 1 comment
Labels
enhancement New feature or request needs refinement We're missing some information here

Comments

@alafanechere
Copy link

Hey, I've been trying out your nice library for a personal project with success.

My use case is to rate limit some tasks which request an upstream API.
I have some tasks which perform multiple API requests.
I'd love to make the TokenBucket aware of it.

# If my task has `factor` set to 2 it means it consumes to tokens from the bucket.
@rate_limit(token_bucket_name="my_bucket", factor=2)
@lociii
Copy link
Member

lociii commented Jun 3, 2024

Great idea. We also thought about that.
The current implementation however has some challenges doing so.

The decorator consumes an item from the queue. AFAIK the kombu queue does not offer to receive multiple items in one call.

message = token_queue.get(no_ack=True)

So let's assume we would iterate and consume as many tokens as requested. Running multiple workers in parallel could lead to the situation that when your bucket is getting close to be empty, the concurrent workers would start consuming from the queue without ever reaching their desired count and all would fail.

If there would be a way to consume multiple items in an atomic transaction, we could go ahead and implement this.
However, I am not aware of one.

@lociii lociii added enhancement New feature or request needs refinement We're missing some information here labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs refinement We're missing some information here
Projects
None yet
Development

No branches or pull requests

2 participants