Thank you very much for this in-depth explanation.

Update:

I applied your advice:

karls-mac-mini:monks karl$ ./buks_patch.pl 0.01 processes: 4 fork: 13.8262140750885 karls-mac-mini:monks karl$ ./buks_patch.pl 0.25 processes: 4 fork: 13.9020979404449 karls-mac-mini:monks karl$ ./buks_patch.pl 0.5 processes: 4 fork: 15.0743520259857 karls-mac-mini:monks karl$ ./buks_patch.pl 1.0 processes: 4 fork: 20.0701560974121

It seems like it works as expected, very nice!

For completeness, the modified code:

#!/usr/bin/env perl use strict; use warnings; use Math::BigInt; use Parallel::ForkManager; use Time::HiRes qw ( time ); use feature qw(say); my $sleep_period = shift; my $processes = qx(sysctl -n hw.ncpu); chomp $processes; my $pm = Parallel::ForkManager->new($processes); $pm->set_waitpid_blocking_sleep($sleep_period); say qq(processes: $processes); my $start = time; for my $number ( 1 .. 50 ) { $pm->start($number) and next; my $factorial = Math::BigInt->bfac(2000) for 1 .. 10; $pm->finish(0); } $pm->wait_all_children; say qq(fork: ), time - $start;

ForkManager.pm:

sub _waitpid_blocking { my $self = shift; # pseudo-blocking if( my $sleep_period = $self->{waitpid_blocking_sleep} ) { while() { my $pid = $self->_waitpid_non_blocking; return $pid if $pid; # sleep $sleep_period; select( '','','', $sleep_period ); } } return waitpid -1, 0; }

My best regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re^8: Useful number of childs revisited by karlgoethebier
in thread Useful number of childs revisited [SOLVED] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.