Celery 和 Redis 总是内存不足

发布于 2024-12-25 15:35:00 字数 973 浏览 6 评论 0原文

我有一个部署到 Heroku 的 Django 应用程序,有一个运行 celery 的工作进程(+ 用于监控的 celerycam)。我使用 RedisToGo 的 Redis 数据库作为代理。我注意到 Redis 总是内存不足。

这就是我的 procfile 的样子:

web: python app/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3
worker: python lipo/manage.py celerycam & python app/manage.py celeryd -E -B --loglevel=INFO

这是 KEYS '*' 的输出:

  1. "_kombu.binding.celeryd.pidbox"
  2. "celeryev.643a99be-74e8-44e1-8c67-fdd9891a5326"
  3. “celeryev.f7a1d511-448b-42ad-9e51-52baee60e977”
  4. “_kombu.binding.celeryev”
  5. “celeryev.d4bd2c8d-57ea-4058-8597-e48f874698ca”
  6. `_kombu.binding.celery”

celeryev.643a99be-74e8-44e1-8c67-fdd9891a5326 充满了这些消息:

{"sw_sys": "Linux", "clock": 1, "timestamp": 1325914922.206671, "hostname": "064d9ffe-94a3-4a4e-b0c2-be9a85880c74", "type": "worker-online", "sw_ident": "celeryd", "sw_ver": "2.4.5"}

知道我可以做什么来定期清除这些消息吗?

I have a Django app deployed to Heroku, with a worker process running celery (+ celerycam for monitoring). I am using RedisToGo's Redis database as a broker. I noticed that Redis keeps running out of memory.

This is what my procfile looks like:

web: python app/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3
worker: python lipo/manage.py celerycam & python app/manage.py celeryd -E -B --loglevel=INFO

Here's the output of KEYS '*':

  1. "_kombu.binding.celeryd.pidbox"
  2. "celeryev.643a99be-74e8-44e1-8c67-fdd9891a5326"
  3. "celeryev.f7a1d511-448b-42ad-9e51-52baee60e977"
  4. "_kombu.binding.celeryev"
  5. "celeryev.d4bd2c8d-57ea-4058-8597-e48f874698ca"
  6. `_kombu.binding.celery"

celeryev.643a99be-74e8-44e1-8c67-fdd9891a5326 is getting filled up with these messages:

{"sw_sys": "Linux", "clock": 1, "timestamp": 1325914922.206671, "hostname": "064d9ffe-94a3-4a4e-b0c2-be9a85880c74", "type": "worker-online", "sw_ident": "celeryd", "sw_ver": "2.4.5"}

Any idea what I can do to purge these messages periodically?

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

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

发布评论

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

评论(1

梨涡 2025-01-01 15:35:00

这是一个解决方案吗?

  1. 除了_kombu.bindings.celeryev 设置之外,还会有例如celeryev.i-am-alive。具有 TTL 设置的按键(例如 30 秒);
  2. celeryev 进程将自身添加到绑定中并定期(例如每 5 秒)更新 celeryev.i-am-alive。 TTL复位键;
  3. 在发送事件工作进程之前,不仅检查 _kombu.bindings.celeryev 上的成员,还检查单个 celeryev.i-am-alive。密钥也是如此,如果密钥未找到(过期),则它会从 _kombu.bindings.celeryev 中删除(并且可能会执行 del celeryev. 或 expire celeryev. 命令)。

我们不能只使用keys命令,因为它是O(N),其中N是数据库中键的总数。 Redis 上的 TTL 可能很棘手2.1 不过。

芹菜过期。而不是德尔塞列耶夫。可以用来让临时离线的 celeryev 消费者复活,但我不知道这是否值得。

作者

Is that a solution?

  1. in addition to _kombu.bindings.celeryev set there will be e.g. celeryev.i-am-alive. keys with TTL set (e.g. 30sec);
  2. celeryev process adds itself to bindings and periodically (e.g. every 5 sec) updates the celeryev.i-am-alive. key to reset the TTL;
  3. before sending the event worker process checks not only smembers on _kombu.bindings.celeryev but the individual celeryev.i-am-alive. keys as well and if key is not found (expired) then it gets removed from _kombu.bindings.celeryev (and maybe the del celeryev. or expire celeryev. commands are executed).

we can't just use keys command because it is O(N) where N is the total number of keys in DB. TTLs can be tricky on redis < 2.1 though.

expire celeryev. instead of del celeryev. can be used in order to allow temporary offline celeryev consumer to revive, but I don't know if it worths it.

author

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