【发布时间】: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