in reply to Re^2: Useful number of childs revisited
in thread Useful number of childs revisited [SOLVED]

BTW: The simple cure for the problem would be to switch sleep for select( '','','', $timeout ), which would allow the timeout to be specified in fractional seconds; and set the default to something like 0.01. (Without adding a dependency upon Time::HiRes )


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^4: Useful number of childs revisited
by karlgoethebier (Abbot) on May 08, 2015 at 18:30 UTC
    "...to switch sleep for select( '','','', $timeout )..."

    Unfortunately i must admit that i don't understand this.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      i don't understand this.

      See the "Blocking calls" section of the P::FM docs.

      By default; the parent process polls to see if one fo the existing kids has completed; and sleeps between polls. And by default, sleeps's smallest granularity is 1 second. Thus, it does not notice when a child process has finished for upto 1 second after it has.

      For processes as in (my version of) your example where the processing takes 0.142s to complete; that means each process that gets waited for takes 85% longer in elapsed time before its replacement gets started.

      If the module used the 4-arg select instead of sleep to control it polling loop; it would be able to used a much smaller timeout, and notice when child processes finished in a more timely manner.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        Now i feel like i'm walking on very thin ice.

        You suggested to set $pm->set_waitpid_blocking_sleep(0);  # true blocking calls enabled.

        After setting this in my/your script it seems as it behaves like as expected, right?

        You suggest to switch sleep for select( '','','', $timeout ).

        I assume that you refer to line 782 of the sources:

        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; # should be line 782 } } return waitpid -1, 0; }

        The author names it $sleep_period instead of $timeout.

        Do you mean that sleep $sleep_period should be replaced with select( '','','', $sleep_period )?

        I'm sorry if it looks like i got a true block. Please correct me if i'm wrong.

        Update: Do'h! It's too late tonight!

        Edit: No reason to complain.

        Thank you very much for further advice and best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»