Coder Social home page Coder Social logo

Comments (8)

LennyLip avatar LennyLip commented on July 21, 2024 1

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.

lociii avatar lociii commented on July 21, 2024

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,
    )
}

image

Is the API that you're trying to throttle really giving one request per second?

from django-celery-token-bucket.

LennyLip avatar LennyLip commented on July 21, 2024

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.

LennyLip avatar LennyLip commented on July 21, 2024

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.

LennyLip avatar LennyLip commented on July 21, 2024

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.

LennyLip avatar LennyLip commented on July 21, 2024
Screenshot 2023-10-02 at 21 16 18

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.

LennyLip avatar LennyLip commented on July 21, 2024
Screenshot 2023-10-02 at 21 31 41

Random countdown. Useful feature as for me.

from django-celery-token-bucket.

lociii avatar lociii commented on July 21, 2024

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 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.