使用芹菜+ Redis的巨大延迟 [英] Huge delay when using Celery + Redis
问题描述
我正在测试Django + Celery,您好是世界示例。使用RabbitMQ芹菜可以正常工作,但是当我切换到Redis经纪人/结果时,我得到以下信息:
I'm testing Django + Celery, hello world examples. With RabbitMQ celery works fine, but when I switched to Redis broker/result I get following:
%timeit add.delay(1,2).get()
1 loops, best of 3: 503 ms per loop
settings.py
CELERY_RESULT_BACKEND = "redis"
BROKER_URL = 'redis://localhost:6379'
tasks.py
@task()
def add(x, y):
return x + y
上面的测试中是否有任何问题?
Is there any issues in test above?
推荐答案
我发现解决方案是源代码:
http://docs.celeryproject.org/en/latest/_modules/celery/result.html#AsyncResult.get
I found solution is source code: http://docs.celeryproject.org/en/latest/_modules/celery/result.html#AsyncResult.get
时间间隔 –重试检索结果之前的等待时间(以秒为单位)。请注意,这在使用
amqp结果存储后端时没有任何作用,因为它不使用轮询。
interval – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
默认情况下为0.5秒。您可以手动更改它,但是不建议使用这种方法来运行任务:
By default it is 0.5 sec. You can change it manually, but it's not recommended way for running tasks:
%timeit add.delay(1,2).get(interval=0.001)
100 loops, best of 3: 3.92 ms per loop
这篇关于使用芹菜+ Redis的巨大延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!