Dear Monks,

I've written a program that collects stats using system commands (SE Toolkit examples), re-formats the output, and sticks it into an RRD. However, it takes 10 seconds for each to run (since I'm collecting 5 second averages, & the first line of output is useless to me), and I don't want to wait 40 secs for each datapoint.

I'd like to run each of these commands in parallel, and I've looked at the Parallel:ForkManager module, but I don't think it applies since I want to run several different commands.

I also read about using the pipe function to get output back from a child process, but I need to do six at a time. I could just write 6 scipts, but that would mean an RRD for each script. Here's an example of what I'm running now (in serial):

sub Vmstat { $vmoutput_time = time; open (VMOUT, "$vmstat |"); $vmoutput = <VMOUT>; close (VMOUT); } sub Cpustat { $cpuoutput_time = time; open (CPUOUT, "$cpustat |"); @cpuoutput = <CPUOUT>; close (CPUOUT); } ... Vmstat () Cpustat ()
Is there a way to run multiple subroutines at once, and keep the output? Any assistance would be greatly appreciated.

In reply to Running Subroutines in Parallel by yid

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.