简体   繁体   English

多处理池生成初始化非常慢,16 个进程为 100 秒

[英]Multiprocessing pool spawn initialization very slow, 100s for 16 processes

In my program I need to spawn 16 multiprocessing pools, to utilise 16 cores on my 3950x.在我的程序中,我需要生成 16 个多处理池,以在我的 3950x 上使用 16 个内核。 I have an initialiser which initialises three global variables in the spawn child processes (totalling around 300kb).我有一个初始化器,它初始化生成子进程中的三个全局变量(总共大约 300kb)。

Before the using the initialiser each process took about 1s to spawn.在使用初始化程序之前,每个进程大约需要 1 秒才能生成。 Now 16 process takes around 100s in total?现在 16 个过程总共需要大约 100 秒? Any idea why this is now so slow: Sample code below:知道为什么现在这么慢:下面的示例代码:

def set_mp_global_vars(bc, bm, bf_n):
    """mp initialiser which sets global vars to reduce mp overhead"""
    global base_comps, base_matches, bf_names
    base_comps = bc
    base_matches = bm
    bf_names = bf_n

int_pool_workers = mp.cpu_count()
pool = mp.Pool(processes=int_pool_workers, initializer=set_mp_global_vars,
               initargs=(base_comps, base_matches, bf_names))

Using Python 3.9.2 on Windows 10 and spawning 30 processes on Threadripper CPU take 23s with Pycharm debugging on.在 Windows 10 上使用 Python 3.9.2 并在 Threadripper CPU 上生成 30 个进程,在 ZE47D298C46B582C0F8D0F6930664F051 上调试需要 23 秒。 If I run without debugging, it takes 0.21s.如果我在不调试的情况下运行,则需要 0.21 秒。

pydev debugger slows down mp.Pool by a factor of 100x. pydev 调试器将 mp.Pool 减慢 100 倍。

You may also look at: python-3-6-multiprocessing-pool-very-slow-to-start-using-windows您还可以查看: python-3-6-multiprocessing-pool-very-slow-to-start-using-windows

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

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