Hi,

I have forwarded the response I got from Elizabeth Mattijsen, the author
of the "forks" module (and many of the Thread::* modules on CPAN).

"forks" and "forks::shared" are modules which are drop-in replacements
for "threads" and "threads::shared".  They implement the perl threads
API in multiple processes instead of multiple threads of the same
process.  One use for them is to allow people to learn the Perl
threads API even on a non-threaded build of perl.  Another use for
them is when you wish to share variables and synchronize processing
between a group of related (via fork()) processes.
Communication between the processes is done by sockets.

"forks" is indeed suitable for communication between Apache children
according to Elizabeth's statement below.  Of course, you would not
typically use the forks->new() method to create processes, but you
could still share variables using the threads-style calls.

In the Apache parent:

  my (%shared_hash);
  share(%shared_hash);

In the Apache children:

  {
     lock(%shared_hash);
     if ($shared_hash{key1} == 0} {
        $shared_hash{key1} = 1;
     }
  }  # unlocks the variable when the lock goes out of scope

It looks interesting to me for a variety of server-type applications.

Stephen
_____________________________

>At 15:23 -0500 12/30/03, Stephen Adkins wrote:
>I have been playing around with "forks" and "forks::shared".
>They look very promising.
> * Do you have experience using these in real applications?

No, not yet, not myself.  But people have been very enthousiastic about
it: you seldom get "thank you" emails for a module on CPAN, and I got
several of these for forks.    The only negative feedback I got from
forks users where:

- people trying to use it on Win32 systems.  Then you got emulating
threads with fork(), which in turn is emalated with threads.  Doesn't
make sense, and apparently doesn't work (very well, anyway).  Whether
that is a problem with fork() or sockets on Win32, I don't know, I don't
do Windows myself anymore.

- older versions of forks::shared did not support the " : shared"
attribute.  Newer versions do.

- support for Perl 5.6.0 was initially broken.  That is also fixed now,
even with the ":shared" attribute (using a source filter).

> * Are they stable (i.e. "production-worthy")?

I think so.  When I release something to CPAN, I think it's production
ready unless I state differently in the documentation.  If it doesn't
work, please let me know!

> * Would you like ongoing feedback on how they work or don't
>   work for me?

Definitely.  Please.

>P.S. I think there might be a great opportunity for Apache/mod_perl
>developers to use forks/forks::shared to share data between Apache
>child processes.

That's one of the situations I'm planning on using it in production for
a client myself.  But please beware that all accesses to shared
variables cause traffic on a socket, which will cause latency.  I have
been looking at using a named pipe for the communication (which should
inherently be faster), but haven't gotten around to doing that.  Patches
are welcome  ;-)

Kind regards,

Elizabeth Mattijsen

On Thu, 2004-01-01 at 21:41, Stas Bekman wrote:
> Stephen Adkins wrote:
> [...]
> > Does anyone have experience with these ("forks"/"forks::shared")?
> > Are they stable (i.e. "production-worthy" at VERSION 0.10)?
> 
> You should probably ask this questions at the [EMAIL PROTECTED] list 
> where Liz can answer your questions.
> 
> I won't judge the quality of the module by its version number. There are quite 
> a few modules with version number 0.01 which are of a production quality.
> 
> > Anyone thought of using them with Apache/mod_perl to share data
> > between Apache child processes?
> 
> I haven't tried Liz's work, but you certainly can't use it with mod_perl, 
> since the fork() is already done by Apache.
> 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
> 


Reply via email to