我有一个CPU密集型Celery任务。 我想在许多EC2实例中使用所有处理能力(核心)来更快地完成这项工作(我认为芹菜并行分布式多任务处理任务)。
术语,线程,多处理,分布式计算,分布式并行处理都是我想要更好理解的术语。
示例任务:
@app.task
for item in list_of_millions_of_ids:
id = item # do some long complicated equation here very CPU heavy!!!!!!!
database.objects(newid=id).save()
使用上面的代码(如果可能的话,有一个例子)如何使用Celery分配这个任务,允许利用云中所有可用机器的所有计算CPU能力分离这一任务?
我认为MapReduce是专为您的应用程序类型而设计的:console.aws.amazon.com/elasticmapreduce/vnext/:
你的目标是:
将您的工作分配给许多机器(分布式
计算/分布式并行处理)
在所有CPU上分配给定计算机上的工作
(多处理/线程)
芹菜可以很容易地为你做这两件事。首先要了解的是,默认情况下,每个芹菜工作者都配置为运行与系统上可用的CPU核心一样多的任务:
Concurrency is the number of prefork worker process used to process
your tasks concurrently, when all of these are busy doing work new
tasks will have to wait for one of the tasks to finish before it can
be processed.
The default concurrency number is the number of CPU’s on that machine
(including cores), you can specify a custom number using -c option.
There is no recommended value, as the optimal number depends on a
number of factors, but if your tasks are mostly I/O-bound then you can
try to increase it, experimentation has shown that adding more than
twice the number of CPU’s is rarely effective, and likely to degrade
performance instead.
这意味着每个单独的任务都不需要担心使用多处理/线程来使用多个CPU /核心。相反,芹菜将同时运行足够的任务来使用每个可用的CPU。
完成后,下一步是创建一个处理list_of_