简体   繁体   English

Python多重处理的局限性

[英]Limits of Python multiprocessing.Pool

I am running a time consuming program a lot of times. 我经常运行耗时的程序。 I have the chance to have access to a cluster where I can require 504 processors, but customer service is let's say slow, so I turn to you SO. 我有机会访问需要504个处理器的群集,但是客户服务速度很慢,所以我向您求助。 I am using a very simple application as follow: 我正在使用一个非常简单的应用程序,如下所示:

import multiprocessing

def function(data):
    data = complicated_function_I_was_given(data)
    with open('unique_id', 'w') as f:
        f.write(data)

pool = multiprocessing.Pool(504)
pool.map(function, data_iterator)

Now, although I can see the processes start (the 'complicated_function_I_was_given' writes a bunch of scrap, but with unique names so I am sure there is no clash), the process seems really slow. 现在,尽管我可以看到过程开始了(“ complicated_function_I_was_given”写了很多废话,但使用了唯一的名称,因此我确信不会发生冲突),但是过程似乎真的很慢。 I am expecting some data in data_iterator to be processed immediately, although some will take days, yet after 1 day nothing has been produced. 我希望data_iterator某些data可以立即处理,尽管有些数据需要几天的时间,但是1天后什么也没产生。 Could it be that multiprocessing.Pool() has a limit? 可能是multiprocessing.Pool()有限制吗? Or that it doesn't distributes the processes over different nodes (I know each node has 12 cores)? 还是它没有将进程分布在不同的节点上(我知道每个节点都有12个核心)? And I am using python2.6.5. 我正在使用python2.6.5。

Or that it doesn't distributes the processes over different nodes (I know each node has 12 cores)? 还是它没有将进程分布在不同的节点上(我知道每个节点都有12个核心)? And I am using python2.6.5. 我正在使用python2.6.5。

I think this is your problem: unless your cluster architecture is very unusual, and all the processors appear to be on the same logical machine, then multiprocessing will only have access to the local cores. 我认为这是您的问题:除非您的集群体系结构非常不寻常,并且所有处理器似乎都在同一台逻辑机上,否则多处理只能访问本地核心。 You probably need to use a different parallelisation library. 您可能需要使用其他并行化库。

See also the answers to this question . 另请参阅此问题答案

您可能会尝试使用Python的许多并行库之一来扩展工作,我还没有听说过可以通过多处理在这么多的处理器上扩展工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM