Concurrency and AnyEvent::MPRPC

Tobias Nissen tn at movb.de
Tue Sep 13 19:48:45 CEST 2011


Tobias Nissen wrote:
> I'm using AnyEvent::MPRPC and I'd like for each remotely called method
> to be executed as a separate thread on the server (with a limitation
> on the number of concurrently running threads, of course). Now I spent
> much of the day reading about the different possible threading
> approaches, including Coro, but I think I'm more disoriented than
> before :-)
> 
> Could you push me into the right direction? What would be relatively
> easy and straightforward to use and how would I integrate it?

OK, I'm now using Parallel::ForkManager (and decided against threads,
at least for now) approximately like this:

  my $concprocs = 7;
  my $childpid;
  my $pm = new Parallel::ForkManager($concprocs);

  foreach my $n (1..$concprocs) {
      print "n=$n\n";
      ($childpid->{$n} = $pm->start) and next;
      AnyEvent->condvar->recv;
      $pm->finish;
  }

  $pm->wait_all_children;

The condvar business might get more complex once I progress.

I'd like to know if there are arguments against the way I'm doing it
right now. Can you think of problems that might arise using AnyEvent
with ForkManager like this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20110913/84cf5cb2/attachment.pgp>


More information about the anyevent mailing list