gpt4 book ai didi

redis - 使用 Celery + Redis 时出现巨大延迟

转载 作者:可可西里 更新时间:2023-11-01 11:22:35 24 4
gpt4 key购买 nike

我正在测试 Django + Celery, Hello World 示例。使用 RabbitMQ celery 工作正常,但是当我切换到 Redis 代理/结果时,我得到以下信息:

%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

上面的测试有没有问题?

最佳答案

我发现解决方案是源代码: 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.

默认为 0.5 秒。您可以手动更改它,但不推荐运行任务的方式:

%timeit add.delay(1,2).get(interval=0.001)
100 loops, best of 3: 3.92 ms per loop

关于redis - 使用 Celery + Redis 时出现巨大延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15386431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com