【问题标题】:CeleryD seems to ignore concurrency argumentCeleryD 似乎忽略了并发参数
【发布时间】:2020-08-19 15:39:39
【问题描述】:

我最近将我的 Django 项目升级到 Celery 4.4.6,但进展并不顺利。 我目前的第一个问题是任务的并发性。因为任务锁定数据库表,而且有些任务非常占用内存,所以不可能同时运行八个任务。我也只有一台 2 处理器机器可用。然而,这就是 celery 要做的事情。

以前我只能同时运行两个任务。

工作人员被守护,只有一名工作人员处于活动状态(一个节点)。我将并发设置为两个。这是我的 /etc/default/celeryd:

#   most people will only start one node:
CELERYD_NODES="worker1"
#   but you can also start multiple and configure settings
#   for each in CELERYD_OPTS
#CELERYD_NODES="worker1 worker2 worker3"
#   alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=3

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/home/ubuntu/dev/bin/python -m celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="match2"
# or fully qualified:
#CELERY_APP="proj.tasks:app"

# Where to chdir at start.
export DJANGO_SETTINGS_MODULE="match2.settings"
CELERYD_CHDIR="/home/ubuntu/dev/match2/match2"

# Extra command-line arguments to the worker
CELERYD_OPTS="--concurrency=2"
# Configure node-specific settings by appending node name to arguments:
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"

# Set logging level to DEBUG
CELERYD_LOG_LEVEL="INFO"

# %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists (e.g., nobody).
CELERYD_USER="ubuntu"
CELERYD_GROUP="users"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

我非常假设这条线会处理可以同时执行多少个任务:CELERYD_OPTS="--concurrency=2" 但它似乎仍然从 RabbitMQ 消息队列中提取了多达 8 个项目。

任何帮助表示赞赏。

【问题讨论】:

    标签: python django celery django-celery


    【解决方案1】:

    所以经过一番折腾,加入了谷歌群,终于得到了答案:

    如果您希望 Celery 表现得像一个优秀的小工人,并且在完成旧任务之前不承担另一项任务,您需要在您的设置文件中同时拥有这两项:

    task_acks_late = True
    worker_prefetch_multiplier = 1
    

    如果您随后在 Django 项目中使用旧式大写设置(请参阅:https://docs.celeryproject.org/en/stable/userguide/configuration.html#new-lowercase-settings),则将其转换为:

    CELERY_WORKER_PREFETCH_MULTIPLIER = 1
    CELERY_TASK_ACKS_LATE = True
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 2021-10-28
      • 2016-09-30
      • 2016-03-16
      相关资源
      最近更新 更多