我有一个使用Parallel::ForkManager
. 然而,即使在所有子进程都完成之后,wait_all_children() 进程也会花费非常长的时间。我知道的方法是打印出一些时间戳(见下文)。有谁知道可能导致这种情况的原因(我的机器上有 16 个 CPU 内核)?
my $pm = Parallel::ForkManager->new(16);
for my $i (1..16) {
$pm->start($i) and next;
... do something within the child-process ...
print (scalar localtime), " Process $i completed.\n";
$pm->finish();
}
print (scalar localtime), " Waiting for some child process to finish.\n";
$pm->wait_all_children();
print (scalar localtime), " All processes finished.\n";
显然,我将Waiting for some child process to finish
首先收到带有时间戳的消息,例如7:08:35
. 然后我会得到一个Process i completed
消息列表,最后一个在7:10:30
. All Processes finished
但是,直到7:16:33
(!)我才收到消息。为什么在 7:10:30 和 7:16:33 之间会有 6 分钟的延迟?谢谢!