NAME

AnyEvent::ProcessPool - Asynchronously runs code concurrently in a pool of perl processes

VERSION

version 0.01

SYNOPSIS

  use AnyEvent::ProcessPool;

  my $pool = AnyEvent::ProcessPool->new(
    workers => 8,
    limit   => 10,
  );

  my $condvar = $pool->async(sub{
    # do task type stuff...
  });

  # Block until result is ready
  my $result = $condvar->recv;

  if ($result eq '...') {
    ...
  }

DESCRIPTION

Executes code using a pool a forked Perl subprocesses. Supports configurable pool size, automatically restarting processes after a configurable number of requests, and closures (with the caveat that changes are not propagated back to the parent process).

ATTRIBUTES

workers

Required attribute specifying the number of worker processes to launch. Must be a positive integer.

limit

Optional attribute that causes a worker process to be restarted after performing limit tasks. This can be useful when calling code which may be leaky. When unspecified or set to zero, worker processes will only be restarted if it unexpectedly fails.

METHODS

async

Executes the supplied code ref in a worker sub-process. Returns a condvar that will block and return the task result when recv is called on it.

DIAGNOSTICS

Task errors

Error messages resulting from a die or croak in task code executed in a worker process are rethrown in the parent process when the condition variable's recv method is called.

"AnyEvent::ProcessPool::Worker: ..." (warning)

When a worker sub-process emits output to STDERR, the process pool warns the message out to its own STDERR.

"error launching worker process: ..."

Thrown when a worker sub-process failed to launch due to an execution error.

"worker terminated in response to signal: ..."

Thrown when a worker sub-process exits as a result of a signal received.

"worker terminated with non-zero exit status: ..."

Thrown when a worker sub-process terminates with a non-zero exit code. The worker will be automatically restarted.

ALTERNATIVES

Parallel::ForkManager

Highly reliable, but somewhat arcane, blocking, and can be tricky to integrate into non-blocking code.

Coro::ProcessPool

Similar in function, but runs only under Coro (which as of 6.513 has experimental support for 5.22).

AUTHOR

Jeff Ober <sysread@fastmail.fm>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Jeff Ober.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.