NAME

Distributed::Process - a framework for running a process simultaneously on several machines.

VERSION

Version 0.05

SYNOPSIS

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 __task {
	my $self = shift;
	# do something
	$self->result('report on what happened');
    }

    sub run {
	my $self = shift;
	$self->__task();
    }

All methods whose names start with a double underscore will be run on the remote machines (the clients).

Write a small server that uses this MyWorker class.

    # Server
    use Distributed::Process;
    use Distributed::Process::Server;
    use Distributed::Process::Master;
    use MyWorker;

    $master = new Distributed::Process::Master -worker_class => 'MyWorker',
	-in_handle => \*STDIN, -out_handle => \*STDOUT,
	-n_workers => 2;
    $server = new Distributed::Process::Server -port => 8147, -master => $master;

    $server->listen();

Write a small client as well 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();

DESCRIPTION

This modules distribution provides a framework to run tasks simultaneously on several computers, while centrally keeping control from another machine.

Architecture Overview

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, but not to perform the tasks directly, only to give the "schedule" of the sub-tasks to run. The sub-tasks themselves will be implemented in other methods, whose names start with a double underscore, and called from within the run() method.

Server Side

On the server side, a D::P::Server object will handle the network connections, i.e. sockets or handles. 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.

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, and it also maintains one D::P::MasterWorker.

The D::P::RemoteWorker objects are in fact instances of the MyWorker class, but with its inheritance changed so that it now derives from D::P::RemoteWorker. Basically, invoking one of their methods that start with a double underscore will in fact send a command on the network socket, instead of running the real method.

The D::P::MasterWorker is a subclass of the custom MyWorker. It overrides its double-underscore methods so that they call the method by the same name on all connected D::P::RemoteWorker objects, effectively resulting in broadcasting the command.

When the D::P::Master receives the /run command (on standard input), it invokes the run() method of its D::P::MasterWorker object. This method is the same as the run() method of MyWorker, except that any call to a __method() will result in a command being broadcasted to the connected D::P::RemoteWorker objects.

After the run() is over, the D::P::MasterWorker broadcasts the /get_result command and gathers the results from all D::P::Worker objects. And the D::P::Master prints out the results.

Client Side

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.

When the client receives a command from the server, it executes it, i.e., it invokes the requested method on its MyWorker object, and keeps the results in memory. The results will be sent later back to the server, when receiving the /get_result command.

Constructor

new LIST

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);

Exports

This module exports the DEBUG() function that is a no op by default. If you import the :debug special tag, the DEBUG() function is turned into one that prints its arguments to standard error.

You need importing :debug 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 will become active everywhere.

Functions

DEBUG LIST

By default, this function does nothing. However, if at some point the :debug tag was imported, DEBUG() will print its arguments to standard error, prepended with the Process ID, the fully qualified name of its caller, and the thread id, e.g.:

3147:Package::function(1): message

AUTHOR

Cédric Bouvier, <cbouvi@cpan.org>

BUGS

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.

COPYRIGHT & LICENSE

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:

Around line 230:

Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252