python - 在不阻塞其他任务的情况下限制 celery 任务的速率

我正在尝试限制一个 celery 任务的速率。这是我的做法:

from project.celery import app

app.control.rate_limit('task_a', '10/m')

它运行良好。但是,有一个陷阱。该工作人员负责的其他任务也被阻止。

比方说,100 个task_a 已被安排。由于它有速率限制,执行所有这些操作需要 10 分钟。在此期间,task_b 也已安排好。在 task_a 完成之前,它不会被执行。

是否可以不阻止 task_b

从外观上看,这就是它的工作原理。我只是在阅读后没有那种印象 the documentation .

其他选项包括:

  • 仅为此任务分离工作人员和队列
  • eta 添加到任务 task_a 中,以便所有任务都安排在夜间运行

这种情况下的最佳做法是什么?

最佳答案

这应该是任务声明的一部分,以便在每个任务的基础上工作。您通过 control 执行此操作的方式可能是它对其他任务产生这种副作用的原因

@task(rate_limit='10/m')
def task_a():
    ...

阅读更多之后

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.

您可能必须在单独的队列中执行此操作

https://stackoverflow.com/questions/62653315/

相关文章:

java - 在 springboot 中创建名为 'org.springframework.boo

amazon-web-services - AWS Lambda 上的 Apollo graphql

c++ - 为什么 glBufferSubData 很慢?

c# - 是否可以从 .NET Core 中间件检索 Controller 的操作结果?

django - React 和 Nginx 在使用 axios 时弄乱了 url,不正确的 API

node.js - 如何在服务器端渲染中使用 Mongodb

amazon-web-services - 使用 bitbucket codestar 连接手动触发

testing - 在 Cypress 中运行测试的所有断言

python - 在 Django 项目中从 Scrapy 获取蜘蛛列表

c# - CreatedAtAction 结果为 "No route matches the sup