If you have many tasks with a long duration you want the multiplier value to be 1, which means it will only reserve one task per worker process at a time.
If you have a combination of long- and short-running tasks, the best option is to use two worker nodes that are configured separately, and route the tasks according to the run-time.
When using early acknowledgement (default), a prefetch multiplier of 1 means the worker will reserve at most one extra task for every active worker process.
When users ask if it’s possible to disable “prefetching of tasks”, often what they really want is to have a worker only reserve as many tasks as there are child processes.
它不是一个bug或一个特性(更有可能是一个特性),它只是配置错误。
正如documentation所说,工人可以为自己保留一些任务,以加快处理消息的速度。但这只对小而快速的任务有意义-它不向代理请求新消息,而是立即启动保留消息。
但对于长期任务来说,这可能会导致你的问题中所描述的情况。
因此,您需要在celery的设置中设置
CELERYD_PREFETCH_MULTIPLIER = 1
。但是
我还建议将
CELERY_ACKS_LATE = True
设置为仅在任务完成后发送ACK命令。这样,工作线程就不会保留任何额外的任务,但当前正在执行的任务将被标记为仅保留。尽管这有一个副作用-如果工作线程在执行任务的过程中崩溃/终止,任务将再次标记为未启动,任何其他工作线程都可以从头开始重新启动它。所以确保你有
idempotent
任务。请再看一次docs。相关问题 更多 >
编程相关推荐