Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Do I need threads?

by BrowserUk (Patriarch)
on Dec 21, 2011 at 16:00 UTC ( [id://944654]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Do I need threads?
in thread Do I need threads?

my thought is to: first, immediately fire a command to every one of them at once, asking every one of them at once to cvs update themselves and then to send back a notification, of success or of failure, by some appropriate means.... heck, maybe you literally use e-mail to do it.

But now you're inventing a new process.

He already has a process. One that works. Whatever mechanisms he uses -- he mentions a "shell script" which generally means invoking one or more executables -- it currently does one at a time and waits for the process to finish logging the progress as it goes and the checking the log locally for errors.

Whilst kicking the jobs off in parallel using '>logN &' is a very simple extension of what he has now, it has the caveat of now needing to institute some mechanism by which it can wait for all the jobs to finish so the logs can be checked; or add the checking into each of the background processes plus some mechanism for notification of failures; etc. etc.

Alternatively, it is easy to convert most most existing shell scripts to Perl scripts. That's the basic raison d'etre for Perl's existence. It is easy to envisage his current shell script looking something like (ignore the syntax, csh isn't my thing):

foreach $webserver ( `cat servers` ) { $result = `ssh server cvs update ... `; if( echo $result | grep Error ) { echo 'problem with server $webserver' } }

and easily converting that to something like:

#! perl my @webservers = <>; for my $job ( @webserver ) { my $result = `ssh $job cvs update ...`; print "Server $job had errors" if $result =~ m[Error]; }

And it is a trivial extension of that, to do the same thing concurrently using threads:

#! perl use threads; my @webservers = <>; my @threads; for my $job ( @webserver ) { push @threads, async{ my $result = `ssh $job cvs update ...`; print "Server $job had errors" if $result =~ m[Error]; }; } $_->join for @threads.

It's just the path of least resistance really.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://944654]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2025-11-17 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.