--- AnyEvent-Fork/Fork.pm 2013/04/06 08:29:43 1.23 +++ AnyEvent-Fork/Fork.pm 2013/04/06 08:32:23 1.24 @@ -6,8 +6,45 @@ use AnyEvent::Fork; - ################################################################## - # create a single new process, tell it to run your worker function + AnyEvent::Fork + ->new + ->require ("MyModule") + ->run ("MyModule::server", my $cv = AE::cv); + + my $fh = $cv->recv; + +=head1 DESCRIPTION + +This module allows you to create new processes, without actually forking +them from your current process (avoiding the problems of forking), but +preserving most of the advantages of fork. + +It can be used to create new worker processes or new independent +subprocesses for short- and long-running jobs, process pools (e.g. for use +in pre-forked servers) but also to spawn new external processes (such as +CGI scripts from a web server), which can be faster (and more well behaved) +than using fork+exec in big processes. + +Special care has been taken to make this module useful from other modules, +while still supporting specialised environments such as L +or L. + +=head1 WHAT THIS MODULE IS NOT + +This module only creates processes and lets you pass file handles and +strings to it, and run perl code. It does not implement any kind of RPC - +there is no back channel from the process back to you, and there is no RPC +or message passing going on. + +If you need some form of RPC, you can either implement it yourself +in whatever way you like, use some message-passing module such +as L, some pipe such as L, use +L on both sides to send e.g. JSON or Storable messages, +and so on. + +=head1 EXAMPLES + +=head2 Create a single new process, tell it to run your worker function. AnyEvent::Fork ->new @@ -27,8 +64,7 @@ # in the original prorcess. have fun! } - ################################################################## - # create a pool of server processes all accepting on the same socket +=head2 Create a pool of server processes all accepting on the same socket. # create listener socket my $listener = ...; @@ -63,12 +99,11 @@ } } - ################################################################## - # use AnyEvent::Fork as a faster fork+exec +=head2 use AnyEvent::Fork as a faster fork+exec - # this runs /bin/echo hi, with stdout redirected to /tmp/log - # and stderr to the communications socket. it is usually faster - # than fork+exec, but still let's you prepare the environment. +This runs /bin/echo hi, with stdout redirected to /tmp/log and stderr to +the communications socket. It is usually faster than fork+exec, but still +let's you prepare the environment. open my $output, ">/tmp/log" or die "$!"; @@ -91,35 +126,6 @@ my $stderr = $cv->recv; -=head1 DESCRIPTION - -This module allows you to create new processes, without actually forking -them from your current process (avoiding the problems of forking), but -preserving most of the advantages of fork. - -It can be used to create new worker processes or new independent -subprocesses for short- and long-running jobs, process pools (e.g. for use -in pre-forked servers) but also to spawn new external processes (such as -CGI scripts from a web server), which can be faster (and more well behaved) -than using fork+exec in big processes. - -Special care has been taken to make this module useful from other modules, -while still supporting specialised environments such as L -or L. - -=head1 WHAT THIS MODULE IS NOT - -This module only creates processes and lets you pass file handles and -strings to it, and run perl code. It does not implement any kind of RPC - -there is no back channel from the process back to you, and there is no RPC -or message passing going on. - -If you need some form of RPC, you can either implement it yourself -in whatever way you like, use some message-passing module such -as L, some pipe such as L, use -L on both sides to send e.g. JSON or Storable messages, -and so on. - =head1 PROBLEM STATEMENT There are two ways to implement parallel processing on UNIX like operating