How to put a rate limit on a celery queue?

Vikash Singh picture Vikash Singh · Jan 30, 2015 · Viewed 12.4k times · Source

I read this in the celery documentation for Task.rate_limit:

Note that this is a per worker instance rate limit, and not a global rate limit. To enforce a global rate limit (e.g., for an API with a maximum number of requests per second), you must restrict to a given queue.

How do I put a rate limit on a celery queue?

Answer

Vikash Singh picture Vikash Singh · Feb 7, 2015

Turns out it cant be done at queue level for multiple workers. IT can be done at queue level for 1 worker. Or at queue level for each worker.

So if u say 10 jobs/ minute on 5 workers. Your workers will process upto 50 jobs per minute collectively.

So to have only 10 jobs running at a time you either chose one worker. Or chose 5 workers with a limit of 2/minute.