Celery 中的rate_limit 是如何执行的?

发布于 2024-12-06 14:30:14 字数 288 浏览 1 评论 0原文

我正在运行一个 Django 网站,在其中使用 Celery 来实现预防性缓存 - 也就是说,我什至在用户请求结果之前就计算并缓存结果。

然而,在某些情况下,我的 Celery 任务之一可能会被调用很多(实际上,我想说比它平均完成的速度要快得多)。我想对它进行rate_limit,这样当它实际上没那么有用时,它就不会消耗大量资源。

不过,我想首先了解 Celery 的 celery.task.base.Task.rate_limit 属性是如何强制执行的。任务是否被拒绝?他们是否被推迟并稍后执行?

提前致谢!

I'm running a Django website where I use Celery to implement preventive caching - that is, I calculate and cache results even before they are requested by the user.

However, one of my Celery tasks could, in some situation, be called a lot (I'd say sightly quicker than it completes on average, actually). I'd like to rate_limit it so that it doesn't consume a lot of resources when it's actually not that useful.

However, I'd like first to understand how Celery's celery.task.base.Task.rate_limit attribute is enforced. Are tasks refused? Are they delayed and executed later?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的绿洲 2024-12-13 14:30:14

速率受限的任务永远不会被丢弃,它们在工作线程中内部排队,以便它们在被允许运行时立即执行。

令牌桶算法没有指定任何有关丢弃数据包的信息(这是一个选项,但 Celery 没有这样做)。

Rate limited tasks are never dropped, they are queued internally in the worker so that they execute as soon as they are allowed to run.

The token bucket algorithm does not specify anything about dropping packets (it is an option, but Celery does not do that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文