For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > Perl Asyn









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl Asyn
Todd English

2006-09-27, 6:59 pm

<cross posting to these two groups as posting to comp.lang.perl.modules
has failed to result in a response>

Group,

I work for a company as security developer and have recently been asked
to streamline our build process. The build process is driven by a
single machine which connects to all the build hosts and builds our
products.

The driver was written in Perl and does all of this sequentially. I
found the Async Perl package from Google (perl+async) and tried to use
it to optimize our process so that building would only take as long as
the slowest platform.

Here is where things get interesting. I implemented everything, and
started seeing that the proc result was blank for allot of our build
results. I'm very new to Perl (as in this is my 4th day using it) so I
broke out a simple program to reproduce the results. Originally, for
the long computation, I was sleeping (as per the example) and the
example worked just fine. I figured it must be my problem and spent a
couple more days learning Perl. I just happened to run the test program
once more today and noticed that one platform didn't respond. So,
instead of sleeping I did something a little more random (as far as
when the function will return) and boom, it happens all the time now.

I would be very willing to help explore this problem, test patches or
even the async fix code (which I tried, unsuccessfully), but I will
need a little direction to do this. Perhaps I am using the package
incorrectly and someone could point out my mistake?

Any help would be appreciated. Thank you for taking the time to read
this,

Todd English

-----------Sample Code------------

#!/usr/bin/perl -w

use Async;

sub long_running_computation {
# This function simulates a computation that takes a long time to
run
my ($name, $host) = @_;
system qq{find ./ -type f 2>&1 >/dev/null};
# if we sleep instead of do something more unpredictable, then works
most of the time
# sleep 10;
return "$name $host has Failed";
}

my %host =
(
'rhel3-ia32' => 'gray',
'rhel4-ia32' => 'x.x.x.x',
'sles9-ia32' => 'y.y.y.y',
'sles10-ia32' => 'maroon',
'rhel3-x64' => 'white',
'rhel4-x64' => 'ivory',
'sles9-x64' => 'skyblue',
'sles10-x64' => 'orange',
'rhel3-ia64' => 'chartreuse',
'rhel4-ia64' => 'cyan',
'sles9-ia64' => 'goldenrod',
'rhel4-s390' => 'rh4as',
'sles9-s390' => 'mambo',
'sol10-x64' => 'brown',
'sol10-sparc' => 'green',
'sol8-sparc' => 'blue',
'sol7-sparc' => 'red',
'sol9-sparc' => 'black',
'hpux-parisc' => 'purple',
'hpux11-ia64' => 'yellow'
);

my %proc_result;
my %build_result;

while (my ($name, $host) = each %host)
{
$proc_result{$name} = Async->new(sub{ long_running_computation
($name, $host) } );
}

# This doesn't work
#while ( (my $name, $proc) = each %proc_result)
#{
# $build_result{$name} = $proc->result('1');
#}

#neither does this
while( 0 < scalar(keys %proc_result) )
{
my @host_list_to_delete;
while( ($name) = each %proc_result)
{
print "checking if $name is ready\n";
if($proc_result{$name}->ready)
{
my $error;
if($error = $proc_result{$name}->error)
{
#$build_result{$name} = $error;
$build_result{$name} = "Async indicates a failure error
occured: $error !";
}
else
{
$build_result{$name} = $proc_result{$name}->result;
}
push(@host_list_to_delete, $name);

undef $proc_result{$name}; #not sure why this is here, but
is was in the sample docs
}
}

foreach my $item (@host_list_to_delete)
{
delete ( $proc_result{$item} );
}

sleep 10;
}

print "done with long running computation\n";
while (my($host_name, $result) = each %build_result)
{
printf "%s\t%s\n", $host{$host_name}, $result;
}

btatnall@gmail.com

2006-09-28, 6:57 pm

Todd English wrote:
> # This doesn't work
> # while ( (my $name, $proc) = each %proc_result)


Did you mean:

while ( my ($name, $proc) = each %proc_result )

notice the location of my

Todd English

2006-09-29, 6:57 pm


btatnall@gmail.com wrote:
> Todd English wrote:
>
> Did you mean:
>
> while ( my ($name, $proc) = each %proc_result )
>
> notice the location of my


Doh, typo on my part. That was what I meant and that was what I tested
(it doesn't work either). Thank you for the reply though, you are the
only person thus far to do so. Any other comments or ideas? I've
written to Mark-Jason Dominus (the author) several times and have not
heard back from him.

Anything would be helpful.

-T

DJ Stunks

2006-09-29, 6:57 pm

Todd English wrote:
> btatnall@gmail.com wrote:
>
> Doh, typo on my part. That was what I meant and that was what I tested
> (it doesn't work either). Thank you for the reply though, you are the
> only person thus far to do so. Any other comments or ideas? I've
> written to Mark-Jason Dominus (the author) several times and have not
> heard back from him.
>
> Anything would be helpful.


Could you boil all this down into one _short_ but _complete_ script
which exhbits the problem you're describing? I, and I'm sure others as
well due to your lack of responses, can't be bothered to wade through
134 lines of code and problem description to try and figure out what it
is you're trying to do and what's not working as you intended it.

Be absolutely sure that whatever you post compiles and runs clean with
both use warnings and use strict in effect.

HTH,
-jp

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com