Parall...Workers(3pm)

πŸ“¦
version 0.18 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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