芹菜。减少进程数量

时间:2012-08-31 10:38:33

标签: python django celery

有没有办法限制celery中的工人数量?我有小型服务器,芹菜总是在1个核心处理器上创建10个进程。我想将这个数字限制为3个进程。

4 个答案:

答案 0 :(得分:27)

我尝试在settings.py文件中将并发设置为1并将max_tasks_per_child设置为1,并同时运行3个任务。它只是作为用户产生1个过程而另外2个产生芹菜。它应该只运行1个进程,然后等待它完成,然后再运行另一个进程。

我正在使用django芹菜。

编辑 {

我通过在settings.py文件中编写CELERYD_CONCURRENCY = 1来分配并发性。但是当我使用“tail -f /var/log/celery/w1.log”查看celery日志文件时,我看到了8分配给并发的值。这告诉我,setting.py不会改变并发性。 为了解决这个问题,我在“/ etc / default / celeryd”文件中添加了以下行。

# Extra arguments to celeryd
CELERYD_OPTS="--concurrency=1"

现在队列中的第二个任务一直等到第一个任务结束。

}

答案 1 :(得分:8)

celery worker - concurrency 选项允许指定处理队列的子进程数。

答案 2 :(得分:1)

我的celeryd-config文件中有这个

CELERYD_NODES=2

导致

$ ps -ef | grep "celery" | grep -v "grep"
www-data  1783     1  0 17:50 ?        00:00:46 /usr/bin/python /opt/webapps/repo/manage.py celeryd --loglevel=INFO -n celery1.xxx-31-39-06-74-75 --logfile=/var/log/celery/1.log --pidfile=/var/run/celery/1.pid 
www-data  1791  1783  0 17:50 ?        00:00:01 /usr/bin/python /opt/webapps/repo/manage.py celeryd --loglevel=INFO -n celery1.xxx-31-39-06-74-75 --logfile=/var/log/celery/1.log --pidfile=/var/run/celery/1.pid
www-data  1802     1  0 17:50 ?        00:00:52 /usr/bin/python /opt/webapps/repo/manage.py celeryd --loglevel=INFO -n celery2.xxx-31-39-06-74-75 --logfile=/var/log/celery/2.log --pidfile=/var/run/celery/2.pid 
www-data  1858  1802  0 17:50 ?        00:00:01 /usr/bin/python /opt/webapps/repo/manage.py celeryd --loglevel=INFO -n celery2.xxx-31-39-06-74-75 --logfile=/var/log/celery/2.log --pidfile=/var/run/celery/2.pid

有四个过程,而不是两个,但有两个工人。看起来每个工作线程都有两个进程。因此,假设您将CELERYD_NODES设置为3,您将获得3个工作人员但只有6个流程。

答案 3 :(得分:0)

您应该在celery选项参数中尝试--autoscale = 3。

相关问题