Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I require suggestions for writing a perl script which reduces or uses less CPU & Memory utilization during execution of a program .

I have a perl script which executes fine but this script has to validate around 1000 files daily for every 5 minutes. So I have written a simple shell script with a simple for loop

for i in 1 2 3 4 5 . . . . . . 1000 do $i done

As it needs to validate 1000 files where each executes for 10sec's and it's taking more time then 5 minutes as they are executed sequentially .

So I have changed the syntax to execute the validation script in background mode to run parallely (1000 processes related to execute at the same time for a minute)

for i in 1 2 3 4 5 . . . . . . 1000 do nohup $i & done

Now it executes all the processes parallely but it's causing high CPU & Memory Utilization .In simple the server crashes because of high cpu & memory utilization. As one processes takes around 0.1% cpu & memory utilization 1000 processes almost uses 100% of utilization .

Is there a better way where I can write the shell script in perl and it should execute the in parallel for all the inputs with less cpu & memory utilization during execution .

Please let me know what would be the best way to start working on it .

In reply to require sugesstions for writing a perl script by lazydev

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2018-06-25 12:35 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.