Parall...Workers(3pm)
π Parall...Workers(3pm) β aka Parallel::Prefork::SpareWorkers π
okay so bestie, you found a page from the User Contributed Perl Documentation pile, titled Parall...Workers(3pm) (yes the terminal chopped the name, that's just how it renders, the real one is Parallel::Prefork::SpareWorkers(3pm)). sit down, hydrate, and let me tell you about the prefork server framework that finally gets spare workers right π«Ά
β¨ NAME β¨
Parallel::Prefork::SpareWorkers β a prefork server framework with support for (min|max)spareservers, no cap π
πΈ SYNOPSIS πΈ
look at her. she's gorgeous. copy-paste ready:
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_received 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;
π¦ DESCRIPTION π¦
"Parallel::Prefork::SpareWorkers" is a subclass of "Parallel::Prefork", and what it brings to the group chat is support for setting a minimum and maximum number of spare worker processes β the kind of feature you've literally always seen in network servers but maybe never knew had a name. π
On top of that, the module adds several initialization parameters to "Parallel::Prefork", some constants, and a method to set the state of the worker processes. so it's giving glow-up, not replacement β¨
π METHODS π
π new
Instantiation, babes. "Parallel::Prefork::ShpareWorkers" recognizes the following parameters in addition to those defined by "Parallel::Prefork". And yes, the parameters can be accessed using accessors with same names as well β so you can read them back later, iconic behaviour fr fr.
min_spare_workersβ minimum number of spare workers. this one is mandatory, so no skipping it πmax_spare_workersβ maxmum number of spare workers (default:max_workers)heartbeatβ a fractional period (in seconds) of child amount checking. Do not use very small numbers to avoid frequent use of CPU (default:0.25) β οΈscoreboard_fileβ filename of scoreboard. If not set,"Parallel::Prefork::SpareWorkers"will create a temporary file.
π set_status
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. don't do it. don't even think about it π
β CONSTANTS β
π STATUS_NEXIST
scoreboard status character '.', meaning no worker process is assigned to the slot of the scoreboard. Applications should never set this value directly. hands off, bestie π
π STATUS_IDLE
scoreboard status character '_', meaning that a worker process is in idle state π
π§ LICENSE π§
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
and that's the whole page, periodt π
this one's perl v5.34.0, dated 2022-05-24, and it lives under the Parall...Workers(3pm) title in the User Contributed Perl Documentation section β go be a main character with your spare workers, ily π«Άπβ¨
π¦ where this page comes from
- debian bookworm: libparallel-prefork-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libparallel-prefork-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libparallel-prefork-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparallel-prefork-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparallel-prefork-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms