Take the following section of code:
$pid = open($firsh_child, "-|"); if ($pid) { while (<$first_child>) { $lines .= $_; } } else { foreach (@gets) { $i = 0; $cpid[$i] = fork; unless ($cpid[$i]) { print `perl $_`; exit; } $i++; } exit; }
@gets contains a list of outside perl programs that are to be called, where the response is printed back to the main program. Everything works as it should. The forked processes merrily create their children and run concurrently. But I'm running into a performance issue.

If I run one program, running time is usually 1-3 seconds. However, if I pass a number of programs, the speed of each program drops dramatically, frequently double or more the time to run each program. So, instead of having a process take 1-3 seconds, it'll take 2-6, sometimes more. In fact, once the number of called programs exceeds 4, the programs called last tend to take 6-8 seconds to run.

I've considered the fact that this may be a memory related issue, but I don't know how to check the memory usage while this is running (UNIX environment). I'd prefer to have something that can print to STDERR while running so that I can check values while the main program runs.

Anyone out there with any code tuning experience that can give me some pointers here?


In reply to Code and Process Efficency by mcogan1966

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.