如何在芹菜中并行运行许多任务?

问题描述

我有这样的功能

def fetch_data(number):
    ( I/O bound operation .get data from API and insert to Redis )

def starter():
    for i in range(100):
        fetch_data(i)

代码需要 250 秒才能完成。我用芹菜写了代码,像这样:

@shared_task
def fetch_data(number):
    ( I/O bound operation. get data from API and insert to Redis )


def starter():
    for i in range(100):
        fetch_data.delay(i)

然后我开始我的芹菜工人:

celery -A my_app worker -l info -c 4

我花了大约 260 秒,这两种方式没有任何区别。 我想打破 260 到 50 秒。有人可以帮我吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)