Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Running local code on other machines

by spx2 (Chaplain)
on Apr 07, 2010 at 10:53 UTC ( #833253=perlquestion: print w/ replies, xml ) Need Help??
spx2 has asked for the wisdom of the Perl Monks concerning the following question:

I need to have a central machine and several other machines that do work for it. Now the central machine will send each machine data for it to start processing and a filter function.

I basically need to delegate work to the machines and expect them when they finish to send back results serialized in some way so I can use them.

How do I send this filter function(sub) across the network ? I am thinking maybe of using POE but not sure if it has what I need ? What module(s) should I be using ?

Thanks

Comment on Running local code on other machines
Re: Running local code on other machines
by marto (Bishop) on Apr 07, 2010 at 11:02 UTC
      yes, but how do I serialize a sub and send it on the socket ?
        Umm, serializing a sub is not easy in perl as far as I know, but what about storing your sub's source as a string, send it over the socket as plain text, then eval at the other end of the socket?
        my $sub_str = q{ sub { my $n = shift; return $n + 1; } }; # send the string through the socket # at the far end of the socket: my $sub_ref = eval $sub_str; print $sub_ref->(2), "\n";

        Be aware that unless your sub is very trivial, you have much more to do than just serialising the sub. If that sub make use of any modules, you'll also have to arrange for those modules to be loaded and initialised at the other machine also. And if those modules use any modules...


        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.
        Put it in a module, and use a source control system. (git, hg, svn, cvs, ...)
Re: Running local code on other machines
by tirwhan (Abbot) on Apr 07, 2010 at 14:57 UTC

    The easy way to do this IMO would be to have your central machine turn these subroutines into simple runnable Perl scripts, and send these over the wire in text form. Then have your remote slaves execute these scripts with the appropriate input and send back the output. Whether this is an appropriate way of doing things depends on what exactly these subroutines should do and how often they are run.


    All dogma is stupid.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://833253]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-28 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls