GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Parallel::Prefork::SpareWorkers(3) User Contributed Perl Documentation Parallel::Prefork::SpareWorkers(3)

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_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;

"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.

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.

min_spare_workers

minimum number of spare workers (mandatory)

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.

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.

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

2014-05-13 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.