Comments (8)
Is the API that you're trying to throttle really giving one request per second?
Thanks for the response. Yes, I need to access to API, that limit is one request per second. I reset tasks queue (it was 39247 refill tasks in queue) 5 hours ago, and it works correctly for now. Can't determine when it starts to grow for now, will trying to investigate.
from django-celery-token-bucket.
Thanks for the report. We've never tried running the refill every second. I can imagine that this will run into some race conditions.
We're running the following schedule without any issues
CELERY_TOKEN_BUCKETS: Dict[str, TokenBucket] = {
"xxx": TokenBucket(
name="xxx",
schedule=schedules.crontab(minute=0),
amount=3000,
maximum=3000,
)
}
Is the API that you're trying to throttle really giving one request per second?
from django-celery-token-bucket.
I set the refill task (with the same config) to run once per 2 seconds. Nothing changed, it works correctly 5-8 hours and then starts to grow in exponents.
/data # redis-cli llen celery
(integer) 19067
from django-celery-token-bucket.
Ok, I'm ending up with separate queue for refill task and looks like it working ok now.
One moment will be nice, if we can use "exponential backoff" for countdown argument, or at least a random jitter countdown.
Thank you for your work!
from django-celery-token-bucket.
race conditions.
Yes, you are right. Task execution time sometimes exceed 1 second, so second task starts before stop previous one. So, it's starts to grow in exponents.
Looks like, I need external script (management command may be) to refill queue.
from django-celery-token-bucket.
![Screenshot 2023-10-02 at 21 16 18](https://private-user-images.githubusercontent.com/955994/272051981-b83905e6-2d1b-4855-9c16-f7bf758e98d4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcyNTI3ODcsIm5iZiI6MTcxNzI1MjQ4NywicGF0aCI6Ii85NTU5OTQvMjcyMDUxOTgxLWI4MzkwNWU2LTJkMWItNDg1NS05YzE2LWY3YmY3NThlOThkNC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjAxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYwMVQxNDM0NDdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mOWE3ODNmOWE1NTAzZDgyNjQxOGUzMTNjZTFhZTY1NDY1YWFmNzVjOTdkNGNkNjVhNDM1ZWUzMzFmZGIwNWFjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.UWBEQMe12vz_UE0Eex_hUrgBcDcZpDKPQwze2sN2Fd8)
BTW, I need to purge queue before refill it. That's why I have a ton of messages, really. Any reason you didn't do it?
from django-celery-token-bucket.
![Screenshot 2023-10-02 at 21 31 41](https://private-user-images.githubusercontent.com/955994/272060458-b16a914f-1588-46a6-828c-fbd1031a5654.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcyNTI3ODcsIm5iZiI6MTcxNzI1MjQ4NywicGF0aCI6Ii85NTU5OTQvMjcyMDYwNDU4LWIxNmE5MTRmLTE1ODgtNDZhNi04MjhjLWZiZDEwMzFhNTY1NC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjAxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYwMVQxNDM0NDdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hODVmNzg5NjBiN2Q0ZTNkNTczYTRlZTgzNmY0YTM5YjkzMWIwYjRiYmE5Yjc4ZDdjOWEzZGE2YTY2NzY0ZDg3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.IgHLswehxumydovhw8IhC37ktc9VtQnAFLugo2lYmq8)
Random countdown. Useful feature as for me.
from django-celery-token-bucket.
BTW, I need to purge queue before refill it. That's why I have a ton of messages, really. Any reason you didn't do it?
This seems pretty weird. The kombu queue is set to only hold a certain maximum of messages.
See https://github.com/RegioHelden/django-celery-token-bucket/blob/main/django_celery_token_bucket/bucket.py#L34
Random countdown. Useful feature as for me.
I'd implement that a bit differently but could make sense sometimes.
from django-celery-token-bucket.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-celery-token-bucket.