some questions about AnyEvent::Fork

Marc Lehmann schmorp at schmorp.de
Fri Apr 19 11:31:16 CEST 2013


On Fri, Apr 19, 2013 at 09:02:39AM +0000, Dietmar Maurer <dietmar at proxmox.com> wrote:
> > - use normal fork, and somehow deal with the fallout, by e..g not using
> >   AnyEvent in the workers, or not using AnyEvent in the tasks (and neither
> >   IO::AIO and so on).
> > - use new_exec, higher startup time, but no extra processes, but you
> >   have to serialise things (AnyEvent::Fork::RPC can help).
> > - use template processes somehow.
> 
> I just want that my master listens for fork requests. I know it is save to fork there, so
> why should I waste resources by creating a template?

Well, if everything already works for you, why bother looking for another
solution?

There is nothing wrong from having a master that preloads modules and
forks. All that AnyEvent::Fork does is to make this easy, and enable you
to do that from a process that already uses AnyEvent or other things that
prevent fork from being useful.

For example, your worker would run into this trouble when forking a task
process.

> Also, both workers and tasks should connect to the master for new fork requests.
> 
> Why do you thing that is a problem to implement?

I don't think it's a problem to implement, but I don't quite see what
AnyEvent::Fork would help there - AnyEvent::Fork does just that, solving a
few of the annoying problems along the road.

If you already have a process and can fork from there, AnyEvent::Fork
cannot improve on that - create a socketpair, fork, close, and you are
settled.

You probably see something in AnyEvent::Fork that you would like to have
and you don't have right now, the question is, what is it? :)

AnyEvent::Fork doesn't implement distributed communications, so it can't
help you with telling your master to fork from a worker. For this, you
still need to use some other form of communication.

What AnyEvent::Fork could help you with is creating task processes from
worker processes when both use AnyEvent for example, by exec'ing a new
perl interpreter. That's the only way to avoid template processes, because
when you started to use AnyEvent, fork is no longer an option.

You could do away with exec'ing (by using AnyEvent::Fork::Early or
::Template), but only at the cost of having a template process.

Or, you could always fork your master, but AnyEvent::Fork would just be
overhead for that case, as you cna just call socketpair and fork yourself,
which is probably shorter than sing AnyEvent::Fork for anything.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list