Parallel::Prefork::SpareWorkers - A prefork server framework with support for (min|max)spareservers
use Parallel::Prefork::SpareWorkers qw(:status); my $pm = Parallel::Prefork::SpareWorkers->new({ max_workers => 40, min_spare_workers => 5, max_spare_workers => 10, trap_signals => { TERM => 'TERM', HUP => 'TERM', USR1 => undef, }, }); while ($pm->signal_recieived ne 'TERM') { load_config(); $pm->start and next; # do what ever you like, as follows while (my $sock = $listener->accept()) { $pm->set_status('A'); ... $sock->close(); $pm->set_status(STATUS_IDLE); } $pm->finish; } $pm->wait_all_children;
Parallel::Prefork::SpareWorkers is a subclass of Parallel::Prefork that supports setting minimum and maximum number of spare worker processes, a feature commonly found in network servers. The module adds to Parallel::Prefork several initialization parameters, constants, and a method to set state of the worker processes.
Parallel::Prefork::SpareWorkers
Parallel::Prefork
Instantiation. Parallel::Prefork::ShpareWorkers recognizes the following parameters in addition to those defined by Parallel::Prefork. The parameters can be accessed using accessors with same names as well.
Parallel::Prefork::ShpareWorkers
minimum number of spare workers (mandatory)
maxmum number of spare workers (default: max_workers)
filename of scoreboard. If not set, Parallel::Prefork::SpareWorkers will create a temporary file.
sets a single-byte character state of the worker process. Worker processes should set any character of their choice using the function (but not one of the reserved characters) to declare that it is running some kind of task. Or the state should be set to STATUS_IDLE '_' once the worker enters idle state. The other reserved character is STATUS_NEXIST '.' which should never be set directly by applications.
STATUS_IDLE
STATUS_NEXIST
scoreboard status character '.', meaning no worker process is assigned to the slot of the scoreboard. Applications should never set this value directly.
scoreboard status character '_', meaning that a worker process is in idle state
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Parallel::Prefork, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parallel::Prefork
CPAN shell
perl -MCPAN -e shell install Parallel::Prefork
For more information on module installation, please visit the detailed CPAN module installation guide.