<?xml version="1.0" encoding="windows-1252"?>
<node id="1021991" title="require sugesstions for writing a perl script" created="2013-03-06 06:00:15" updated="2013-03-06 06:00:15">
<type id="115">
perlquestion</type>
<author id="1021986">
lazydev</author>
<data>
<field name="doctext">
&lt;p&gt;
I require suggestions for writing a perl script which reduces or uses less CPU &amp; Memory utilization during execution of a program .
&lt;/p&gt;

&lt;p&gt;
I have a validation.pl 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 
&lt;/p&gt;
&lt;p&gt;
for i in 1 2 3 4 5 . . . . . . 1000
do
validation.pl $i
done
&lt;/p&gt;

As it needs to validate 1000 files where each validation.pl executes for 10sec's and  it's taking more time then 5 minutes as they are executed sequentially . 
&lt;/p&gt;
&lt;p&gt;
So I have changed the syntax to execute the validation script in background mode to run parallely (1000 processes related to validation.pl execute at the same time for a minute)
&lt;/p&gt; 
&lt;code&gt;
for i in 1 2 3 4 5 . . . . . . 1000
do
nohup validation.pl $i &amp; 
done   
&lt;/code&gt;

&lt;p&gt;
Now it executes all the processes parallely but it's causing high CPU &amp; Memory Utilization .In simple the server crashes because of high cpu &amp; memory utilization. 
As one processes takes around 0.1% cpu &amp; memory utilization 1000 processes almost uses 100% of utilization . 
&lt;/p&gt;

&lt;p&gt;
Is there a better way where I can write the shell script in perl and it should execute the validation.pl in parallel for all the inputs 
with less cpu &amp; memory utilization during execution . &lt;/p&gt; 

&lt;p&gt; Please let me know what would be the best way to start working on it .  &lt;/p&gt;



</field>
</data>
</node>
