问题
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