[Israel.pm] performance problems - Win32::Process which runs perl

Sagiv Barhoom sagivba at 012.net.il
Sat Sep 16 10:02:45 PDT 2006


Hi Gavor it is not a busy waiting
BTW 
the sleep solve this problem on that code - I will have to check it at work 
and see if it does the same on my application.
On *nix I do somthing like this:

# - - - - - - - - - - - - - Linux style  - - - - - - - - - - - - - - - - - - - 

foreach my $p ( 1..$NUM_OF_PRCS  ) {
    if (!defined($kidpid = fork())) {
        warn "Cannot fork: $!";
    } elsif ($kidpid == 0) {
       # sleep 3;
        # do whatever U do	
        exit 0;
    }
    else {
        push @CHLDRN,$kidpid;
         if (scalar @CHLDRN>$MAX_PRCSS_AT_THE_SAME_TIME){
            my $d=wait ();
            $CHLDRN[ index_of( $d) ] = $CHLDRN[$#CHLDRN];	
            delete $CHLDRN[$#CHLDRN];
        }
    }
}               # -----  end foreach  -----


and on windows I do it like that:

# - - - - - - - - - - - - - - Windows style - - - - - - - - - - - - - - - - - 

foreach my $p ( 1..$NUM_OF_PRCS  ) {

	my $process_obj;
	#sleep 1; 
	foreach my $x (1..1000){;}
	Win32::Process::Create($process_obj,
			                    $PERL_EXE,
                                qq{perl -e "print "$$  \n" },		
		# this is like do somthing above
                                0,
                                NORMAL_PRIORITY_CLASS,
                                ".")|| die ErrorReport();

    
    	push @CHLDRN,$process_obj;
      
	if (scalar @CHLDRN>$MAX_PRCSS_AT_THE_SAME_TIME){
		$process_obj=shift @CHLDRN; 
		$process_obj->Wait(INFINITE);
	}
Regards Sagiv
On Saturday 16/9/2006 19:05, Gabor Szabo wrote:
> On 9/15/06, Sagiv Barhoom <sagivba at 012.net.il> wrote:
> > Start:
> >         Get records for DB
> >         foreach $rec (@records){
> >                 create from the record  a script;
> >                 wait until less then $MAX_NUMBER_AT_SAME_TIME chidren
> > scripts are running (at the same time)
> >                 run that script you have just created;
> >         }
> > End;
>
> ho do you "wait"? Like this?
>
> while (1) {
>    my $num = get_children();
>    last if $num < $MAX_NUMBER_AT_SAME_TIME
> }
>
> Or do you have a sleep in there too ?
>
> Gabor
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

-- 
שמיים כחולים אוויר צח
שגיב




More information about the Perl mailing list