gpt4 book ai didi

rabbitmq - 用 Celery 制作的临时队列

转载 作者:行者123 更新时间:2023-12-02 15:27:04 25 4
gpt4 key购买 nike

我正在将 Celery 与 RabbitMQ 一起使用。最近,我注意到出现了大量的临时队列。

因此,我进行了实验,发现当任务失败(即任务引发异常)时,会形成一个具有随机名称(如 c76861943b0a4f3aaa6a99a6db06952c)的临时队列,并且该队列将保留。

在rabbitmqadmin中找到的临时队列的一些属性如下-

自动删除:真消费者:0耐用:假消息:1messages_ready:1

每当任务失败(即引发异常)时,就会创建一个这样的临时队列。如何避免这种情况呢?因为在我的生产环境中形成了大量这样的队列。

最佳答案

听起来您正在使用 amqp 作为结果后端。来自 docs以下是使用该特定设置的陷阱:

  • Every new task creates a new queue on the server, with thousands of tasks the broker may be overloaded with queues and this will affect
    performance in negative ways. If you’re using RabbitMQ then each
    queue will be a separate Erlang process, so if you’re planning to
    keep many results simultaneously you may have to increase the Erlang
    process limit, and the maximum number of file descriptors your OS
    allows
  • Old results will not be cleaned automatically, so you must make sure to consume the results or else the number of queues will eventually go out of control. If you’re running RabbitMQ 2.1.1 or higher you can take advantage of the x-expires argument to queues, which will expire queues after a certain time limit after they are unused. The queue expiry can be set (in seconds) by the CELERY_AMQP_TASK_RESULT_EXPIRES setting (not enabled by default).

根据我在 changelog 中读到的内容,这不再是版本 >=2.3.0 中的默认后端,因为用户会因为这种行为而陷入后端困境。如果这不是您需要的功能,我建议更改结果后端。

关于rabbitmq - 用 Celery 制作的临时队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com