I use the regular Parallel::ForkManager module in Perl. I execute around 10 children processes. 'passes_thresholds' function take few milliseconds or nanoseconds (checked it). In case i run all processes one by one (without Parallel::ForkManager) the whole process took 80-250 milliseconds. In case i run them as parallel, the whole process takes at lease 1 second. I found that the Fork spend 1 second to start the 'finish' function. I put a timer when the child process finished his job and should go to 'finish' function. One second is too much for my development.
sub parallel_execute {
my $this = shift;
foreach my $a (@a_array) {
my $pid = $this->{fork_manager}->start and next;
my $res = $a->passes_thresholds();
$a->{timer} = Benchmark::Timer->new();
$svc->{timer}->start;
$this->{fork_manager}->finish(0,{a => $a, plugin_result => $re
+s});
}
}
$this->{fork_manager}->run_on_finish( sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_stru
+cture_reference) = @_;
my $a = $data_structure_reference->{a};
if (exists $a->{timer}) {
$a->{timer}->stop;
debug "took: " . $a->{timer}->report;
}
});
Do you have any idea why it took at least 1 second to start the 'finish' command?
(I am using Unix server, and perl 5.10)