Distributed::Process - a framework for running a process simultaneously on several machines.
Version 0.20
First, write a subclass of Distributed::Process::Worker that will implement the tasks to be run remotely in its run() method.
package MyWorker; use Distributed::Process; use Distributed::Process::Worker; sub run { my $self = shift; # do interesting stuff ... # report about what happened $self->result("logs the results"); }
Write a small server to pilot the workers:
# Server use Distributed::Process; use Distributed::Process::Server; use Distributed::Process::Master; use MyWorker; $master = new Distributed::Process::Master -in_handle => \*STDIN, -out_handle => \*STDOUT, -worker_class => 'MyWorker', -n_workers => 2; $server = new Distributed::Process::Server -port => 8147, -master => $master; $server->listen();
Write a small client as well that uses the custom worker class and install it on all the client machines:
# Client use Distributed::Process; use Distributed::Process::Client; use MyWorker; $client = new Distributed::Process::Client -worker_class => 'MyWorker', -host => 'the-server', -port => 8147; $client->run();
This modules distribution provides a framework to run tasks simultaneously on several computers, while centrally keeping control from another machine.
The tasks to run are implemented in a "worker" class, that derives from D::P::Worker; let's call it MyWorker. The subclass must overload the run() method that will be invoked from the server.
D::P::Worker
MyWorker
On the server side, a D::P::Server object will handle the network connections, i.e. sockets. Each handle is associated with a D::P::Interface object. This object can be either be a D::P::Master, or a D::P::RemoteWorker.
D::P::Server
D::P::Interface
D::P::Master
D::P::RemoteWorker
Instead of being bound to a network socket, the D::P::Master object is typically bound to the standard input and output, and can thus receive orders from the user and give feedback on the terminal. It maintains a list of D::P::RemoteWorker objects, one for each network connection.
The D::P::RemoteWorker objects implement the communication between the server and the clients. Its inheritance is changed at run-time, so that it is a subclass of the MyWorker class, and thus benefits from all the methods implemented in the worker class.
When the D::P::Master receives the /run command (on standard input), it invokes the run() method on each of the D::P::RemoteWorker objects, which in turn will send a /run command to their connected client.
/run
After the run() is over, the D::P::Master broadcasts the /get_result command and gathers the results from all D::P::RemoteWorker objects, and prints out the results.
/get_result
On the client side, a D::P::Client object manages to connection to the server and instanciates the MyWorker class, derived from D::P::Worker.
D::P::Client
When the client receives the /run command from the server, it invokes the run() method of the MyWorker class. This method can in turn invoke methods from D::P::LocalWorker (which it derives from) to talk back to the server:
D::P::LocalWorker
Although this class is not supposed to be instanciated, it provides a constructor for its subclasses to inherit from. This constructor takes a LIST of named arguments. The names will be converted to lowercase and stripped off from their leading hyphens, if any. The constructor then calls the method by the same name with the value as argument. These calls are the same:
$obj = new Distributed::Process method => $value; $obj = new Distributed::Process -method => $value; $obj = new Distributed::Process -METHOD => $value; $obj = new Distributed::Process; $obj->method($value);
This module exports the DEBUG(), ERROR(), WARN() and INFO() functions that are no ops by default. If you import the :debug, :error, :warn and/or :info special tags, the corresponding functions are turned into one that prints its arguments to standard error.
:debug
:error
:warn
:info
You need importing the special tags only once for this to take effect. For exemple the main program can say:
use Distributed::Process qw/ :debug /;
While all the other modules just say:
use Distributed::Process;
Still, the DEBUG function will become active everywhere.
DEBUG
By default, these functions do nothing. However, if at some point the :debug, :error, :warn, or :info tag were imported, these functions will print their arguments to standard error, prepended with the Process ID, the fully qualified name of its caller, and the thread id, e.g.:
<DBG>3147:Package::function(1): message <ERR>3147:Package::function(1): message <WRN>3147:Package::function(1): message <INF>3147:Package::function(1): message
If the global variable $ID is declared in the main program, it will be used instead of the Process ID:
our $ID = 'server'; <DBG>server:Package::function(1): message <ERR>server:Package::function(1): message <WRN>server:Package::function(1): message <INF>server:Package::function(1): message
Cédric Bouvier, <cbouvi@cpan.org>
<cbouvi@cpan.org>
Please report any bugs or feature requests to bug-distributed-process@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-distributed-process@rt.cpan.org
Copyright 2005 Cédric Bouvier, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252
To install Distributed::Process, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Distributed::Process
CPAN shell
perl -MCPAN -e shell install Distributed::Process
For more information on module installation, please visit the detailed CPAN module installation guide.