如何对芹菜队列设置速率限制?
How to put a rate limit on a celery queue?
我在 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.
如何对 celery 队列设置速率限制?
事实证明它不能在多个工作人员的队列级别完成。
IT 可以在 1 个工作人员的队列级别完成。或者在每个工作人员的队列级别。
所以如果你说 5 个工人每分钟 10 个工作。您的工作人员每分钟最多可处理 50 个作业。
所以一次只有 10 个工作 运行 你要么选择一个工人。或者选择5个工人,限制为2个/分钟。
更新:如何准确地将限制放入 settings/configuration:
task_annotations = {'tasks.<task_name>': {'rate_limit': '10/m'}}
或对所有任务进行相同的更改:
task_annotations = {'*': {'rate_limit': '10/m'}}
10/m
表示每分钟 10 个任务,/s
表示每秒。此处有更多详细信息:Task annotations setting
嘿,我正在尝试找到一种对队列进行速率限制的方法,但我发现 Celery 无法做到这一点,但是 Celery 可以控制每个任务的速率,请参见:
http://docs.celeryproject.org/en/latest/userguide/workers.html#rate-limits
因此,作为解决方法,也许您可以为每个队列设置一个任务(这在很多情况下都有意义),并对任务施加限制。
您可以在花 > 工人窗格中设置此限制。
有一个指定的空白 space 用于在那里输入您的限制。
建议使用的格式也如下:
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.
我在 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.
如何对 celery 队列设置速率限制?
事实证明它不能在多个工作人员的队列级别完成。 IT 可以在 1 个工作人员的队列级别完成。或者在每个工作人员的队列级别。
所以如果你说 5 个工人每分钟 10 个工作。您的工作人员每分钟最多可处理 50 个作业。
所以一次只有 10 个工作 运行 你要么选择一个工人。或者选择5个工人,限制为2个/分钟。
更新:如何准确地将限制放入 settings/configuration:
task_annotations = {'tasks.<task_name>': {'rate_limit': '10/m'}}
或对所有任务进行相同的更改:
task_annotations = {'*': {'rate_limit': '10/m'}}
10/m
表示每分钟 10 个任务,/s
表示每秒。此处有更多详细信息:Task annotations setting
嘿,我正在尝试找到一种对队列进行速率限制的方法,但我发现 Celery 无法做到这一点,但是 Celery 可以控制每个任务的速率,请参见:
http://docs.celeryproject.org/en/latest/userguide/workers.html#rate-limits
因此,作为解决方法,也许您可以为每个队列设置一个任务(这在很多情况下都有意义),并对任务施加限制。
您可以在花 > 工人窗格中设置此限制。 有一个指定的空白 space 用于在那里输入您的限制。 建议使用的格式也如下:
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.