Huge delay when using Celery + Redis

匆匆过客 提交于 2020-01-07 04:37:06

问题


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?


回答1:


I found solution is source code: http://docs.celeryproject.org/en/latest/_modules/celery/result.html#AsyncResult.get

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.

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


来源:https://stackoverflow.com/questions/15386431/huge-delay-when-using-celery-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!