How to put rate limit on a celery queue?

China☆狼群 提交于 2019-11-30 17:23:16

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.

hey I am trying to find a way to do rate limit on queue, and I find out Celery can't do that, however Celery can control the rate per tasks, see this:

http://docs.celeryproject.org/en/latest/userguide/workers.html#rate-limits

so for a workaround, maybe you can set up one tasks per queue(which makes sense in a lot of situations), and put the limit on task.

You can set this limit in the flower > worker pane. there is a specified blank space for entering your limit there. The format that is suggested to be used is also like the below:

The rate limits can be specified in seconds, minutes or hours by appending “/s”, >“/m” or “/h” to the value. Tasks will be evenly distributed over the specified >time frame.

Example: “100/m” (hundred tasks a minute). This will enforce a minimum delay of >600ms between starting two tasks on the same worker instance.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!