Acme-Parataxis
view release on metacpan or search on metacpan
eg/fork_offload.pl view on Meta::CPAN
delivered => $delivered,
killed => $killed,
kill_took => $kill_took,
kill_err => $err,
after_kill => $after_kill,
};
}
);
# The concurrency cap, reconstructed from the windows each child reported. Walk
# the start/stop endpoints and take the deepest overlap; with $POOL children
# allowed it must never exceed $POOL, and it must exceed zero or the closures
# did not really overlap at all.
my $high = 0;
{
my @events = map { ( [ $_->{start}, +1 ], [ $_->{end}, -1 ] ) } @{ $rv->{out} };
my $depth = 0;
for my $e ( sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @events ) {
$depth += $e->[1];
$high = $depth if $depth > $high;
}
t/031_spawn_blocking_fork.t view on Meta::CPAN
return [ map { $_->await } @fs ];
}
);
# Concurrency cannot be counted with a shared integer here: the children are separate processes and a counter
# they increment lands in their own copy, which is precisely the copy-in copy-out this test keeps asserting.
# So each child reports the wall-clock window it was actually running in, and the depth is computed here.
is scalar @$rv, 6, 'all six closures completed';
is scalar( keys %{ { map { $_->[2] => 1 } @$rv } } ), 6, 'and each ran in its own process';
# The cap is 2, so at no instant may three of them be running. Walk the endpoints and take the depth.
#
# What is deliberately NOT asserted is that the closures *did* overlap. The permit is taken in the parent at spawn
# and released only once the parent's harvester has read the payload and reaped the child, so the real ceiling on
# concurrency is parent-side teardown cost, not child work. On Linux fork and reap are cheap enough that two
# children overlap; on a macOS x64 leg every child finished before the next one started, which reported zero
# overlapping pairs and a peak depth of 1 while the pool was obeying its cap exactly as written. Asserting overlap
# would have been asserting that macOS forks as fast as Linux's, which is a claim about the OS, not about this
# code. Depth 1 is a legitimate outcome of a working cap: it means the batch serialised, which is slower and still
# correct. The ceiling is the contract; how much of it gets used is the platform's business.
my @events = map { ( [ $_->[0], +1 ], [ $_->[1], -1 ] ) } @$rv;
( run in 2.704 seconds using v1.01-cache-2.11-cpan-99fa8243a42 )