考虑以下脚本
tasks.py:
from celery import Celery
from celery import group
app = Celery()
app.conf.update(
broker_url='pyamqp://guest@localhost//',
result_backend='redis://localhost',
)
@app.task
def my_calc(data):
for i in range(100):
data[0]=data[0]/1.04856
data[1]=data[1]/1.02496
return data
def compute(parallel_tasks):
tasks=[]
for i in range(parallel_tasks):
tasks.append([i+1.3,i+2.65])
job = group([my_calc.s(task) for task in tasks])
results = job.apply_async().join(timeout=120)
#for result in results:
# print(result.get(timeout=20))
def start(parallel_tasks,iterations):
for i in range(iterations):
print(i)
compute(parallel_tasks)
该脚本使用celery的group function以给定数量的迭代(parallel_tasks
)执行给定数量的任务(iterations
)
问题在于,我在单次迭代中提交的任务越多(parallel_tasks
输入参数越大),由于未知原因,批处理的执行可能会超时。当超时发生时,工作人员不会变得超负荷。
致电start(2,100000)
很好。
调用start(20,40)
会在第10次迭代时停止。
该问题与代理和后端类型无关。我的主要配置使用RabbitMQ作为代理,使用Redis作为后端,但是反之亦然,仅RabbitMQ和仅Redis配置。
我以标准方式启动工作程序:worker -A tasks -l info
环境:
Miniconda - Python 3.6.6 (see requirements.txt for details below)
Debian 9 running in Virtualbox. VM Config: 4 cores and 8GB RAM
Redis 4.0.11
RabbitMQ 3.6.6 on Erlang 19.2.1
**Output of celery -A tasks report**
software -> celery:4.2.1 (windowlicker) kombu:4.2.1 py:3.6.6
billiard:3.5.0.4 py-amqp:2.3.2
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:redis://localhost/
RabbitMQ日志包含以下错误:
=ERROR REPORT==== 7-Sep-2018::17:31:42 ===
closing AMQP connection <0.1688.0> (127.0.0.1:52602 -> 127.0.0.1:5672):
missed heartbeats from client, timeout: 60s