简体   繁体   English

python多处理。 长期执行后,游泳池陷入困境

[英]python multiprocessing. Pool got stuck after long execution

I am developing a tool that analyzes huge files. 我正在开发一个分析大文件的工具。 In order to do that faster I introduced multiprocessing on it and everything seems to work fine.In order to do it I am using multiprocessing.pool creating N threads, and they handle different chunks of work I previously created. 为了更快地做到这一点,我在其上引入了多处理,一切似乎都运行正常。为了做到这一点,我使用multiprocessing.pool创建N个线程,并且它们处理我之前创建的不同的工作块。

pool = Pool(processes=params.nthreads)
for chunk in chunk_list:
    pool.apply_async(__parallel_quant, [filelist, chunk, outfilename])

pool.close()
pool.join()

As you can see, this is standard pool execution, with no special usage. 如您所见,这是标准池执行,没有特殊用途。

Lately I find a problem when I am running a really big amount of data. 最近,当我运行大量数据时,我发现了一个问题。 The standard executions take around 2 hours with 16 threads, but I have an special case that takes around 8 hours, due to its really big amount of files and size of them. 标准执行需要大约2个小时,有16个线程,但我有一个特殊情况需要大约8个小时,因为它有大量的文件和大小。

The problem is that lately I found that when I am executing this case, the execution runs fine until the finish, most of the childs finish properly except for one that got stucked on 问题是,最近我发现当我执行这个案例时,执行运行正常,直到完成,大多数孩子正常完成,除了一个被困住的孩子

<built-in method recv of _multiprocessing.Connection object at remote 0x3698db0>

Since this child is not finishing parent doesn't wake up and the execution stops. 由于这个孩子没有完成父母没有醒来,执行停止。

This situation only happens when the input files are very big, so I was wondering if there is any kind of default timeout that can cause this problem. 这种情况只发生在输入文件非常大的情况下,所以我想知道是否存在任何可能导致此问题的默认超时。

I am using python 2.7 multiprocessing 0.70a1 我正在使用python 2.7多处理0.70a1

and my machine is a centos 7 (32 cores, 64GB RAM) 我的机器是一个centos 7(32核,64GB RAM)

Thanks in advance for your help 在此先感谢您的帮助

Jordi 霍尔迪

From the multiprocessing Programming guidelines: 从多处理编程指南:

Avoid shared state 避免共享状态

 As far as possible one should try to avoid shifting large amounts of data between processes. 

If you have to split file processing through several processes, it is better to instruct them on how to retrieve the file chunks rather than sending the chunks themselves. 如果必须通过多个进程分割文件处理,最好指导它们如何检索文件块而不是自己发送块。

Try to pass the chunk offset and the chunk size to the child process. 尝试将块偏移量和块大小传递给子进程。 It can retrieve the chunk from the file with open() and seek(). 它可以使用open()和seek()从文件中检索块。 You will notice a performance improvement and a reduction of the memory footprint as well. 您会注意到性能的提高以及内存占用的减少。

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

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