Am using Parallel::ForkManager using ActiveState Perl 5.10.1 (1006) on Vista Home Premium SP1 and have been getting something rather strange happen.

When initiated in "debug"

my $pm = new Parallel::ForkManager(0);

the code runs in about 11 seconds to run - but if I tell it to run any number of instances (including 1)

my $pm = new Parallel::ForkManager(1); my $pm = new Parallel::ForkManager(5);

then the run time INCREASES ("1" takes seconds and "5" takes many hours to run) rather than the expected decrease (given that I'm running the code on a quad core system doing naff all otherwise ... and the Windows Performance Monitor suggests that the other cores come alive as expected).

Which suggests that I'm doing summat odd - but I've tried to implement code that is based on reference model provided in the ForkManager documentation.

sub scoring { return 1; } my @results = (); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident ) = @_; $results[$ident] = $exit_code; } ); for ( my $i = 0; $i < 1000000; $i++ ) { my $pid = $pm->start($i) and next; my $result = scoring(); $pm->finish($result); } $pm->wait_all_children;

This is cut down PoC code - the real version does much more processing in the child, but the runtime issue is the same... massively increased run-time when actually forking.

Any ideas ?


In reply to ForkManager Running Real Slow by zacc

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.