Net::Server::PreFork



Net::Server::PreFork

NAME
SYNOPSIS
DESCRIPTION
SAMPLE CODE
COMMAND LINE ARGUMENTS
CONFIGURATION FILE
PROCESS FLOW
HOOKS
BUGS
TO DO
AUTHOR
THANKS
SEE ALSO

NAME

Net::Server::PreFork − Net::Server personality

SYNOPSIS

  use Net::Server::PreFork;
  @ISA = qw(Net::Server::PreFork);
  sub process_request {
     #...code...
  }
  __PACKAGE__−>run();

DESCRIPTION

Please read the pod on Net::Server and Net::Server::PreForkSimple first. This module is a personality, or extension, or sub class, of the Net::Server::PreForkSimple class which is a sub class of Net::Server. See Net::Server::PreForkSimple.

This personality binds to one or more ports and then forks "min_servers" child process. The server will make sure that at any given time there are "min_spare_servers" available to receive a client request, up to "max_servers". Each of these children will process up to "max_requests" client connections. This type is good for a heavily hit site, and should scale well for most applications. (Multi port accept is accomplished using flock to serialize the children).

At this time, it does not appear that this module will pass tests on Win32 systems. Any ideas or patches for making the tests pass would be welcome.

SAMPLE CODE

Please see the sample listed in Net::Server.

COMMAND LINE ARGUMENTS

In addition to the command line arguments of the Net::Server base class and the Net::Server::PreForkSimple parent class, Net::Server::PreFork contains several other configurable parameters. You really should also see Net::Server::PreForkSimple.

  Key                 Value                   Default
  min_servers         \d+                     5
  min_spare_servers   \d+                     2
  max_spare_servers   \d+                     10
  max_servers         \d+                     50
  max_requests        \d+                     1000
  serialize           (flock|semaphore|pipe)  undef
  # serialize defaults to flock on multi_port or on Solaris
  lock_file           "filename"              POSIX::tmpnam
  check_for_dead      \d+                     30
  check_for_waiting   \d+                     10
  max_dequeue         \d+                     undef
  check_for_dequeue   \d+                     undef
  child_communication 1                       undef

min_servers

The minimum number of servers to keep running.

min_spare_servers

The minimum number of servers to have waiting for requests. Minimum and maximum numbers should not be set to close to each other or the server will fork and kill children too often.

max_spare_servers

The maximum number of servers to have waiting for requests. See min_spare_servers.

max_servers

The maximum number of child servers to start. This does not apply to dequeue processes.

check_for_waiting

Seconds to wait before checking to see if we can kill off some waiting servers.

check_for_spawn

Seconds between checking to see if we need to spawn more children

min_child_ttl

Minimum number of seconds between starting children and killing a child process

child_communication

Enable child communication to parent via unix sockets. If set to true, will let children write to the socket contained in $self−>{server}−>{parent_sock}. The parent will be notified through child_is_talking_hook where the first argument is the socket to the child. The child’s socket is stored in $self−>{server}−>{children}−>{$child_pid}−>{sock}.

CONFIGURATION FILE

"Net::Server::PreFork" allows for the use of a configuration file to read in server parameters. The format of this conf file is simple key value pairs. Comments and white space are ignored.

  #−−−−−−−−−−−−−− file test.conf −−−−−−−−−−−−−−
  ### server information
  min_servers   20
  max_servers   80
  min_spare_servers 10
  min_spare_servers 15
  max_requests  1000
  ### user and group to become
  user        somebody
  group       everybody
  ### logging ?
  log_file    /var/log/server.log
  log_level   3
  pid_file    /tmp/server.pid
  ### access control
  allow       .+\.(net|com)
  allow       domain\.com
  deny        a.+
  ### background the process?
  background  1
  ### ports to bind
  host        127.0.0.1
  port        localhost:20204
  port        20205
  ### reverse lookups ?
  # reverse_lookups on
  ### enable child communication ?
  # child_communication
  #−−−−−−−−−−−−−− file test.conf −−−−−−−−−−−−−−

PROCESS FLOW

Process flow follows Net::Server until the loop phase. At this point "min_servers" are forked and wait for connections. When a child accepts a connection, finishs processing a client, or exits, it relays that information to the parent, which keeps track and makes sure there are enough children to fulfill "min_servers", "min_spare_servers", "max_spare_servers", and "max_servers".

HOOKS

The PreFork server has the following hooks in addition to the hooks provided by PreForkSimple. See Net::Server::PreForkSimple.
"$self−>run_n_children_hook()"

This hook occurs at the top of run_n_children which is called each time the server goes to start more child processes. This gives the parent to do a little of its own accountting (as desired). Idea for this hook came from James FitzGibbon.

"$self−>parent_read_hook()"

This hook occurs any time that the parent reads information from the child. The line from the child is sent as an argument.

"$self−>child_is_talking_hook()"

This hook occurs if child_communication is true and the child has written to $self−>{server}−>{parent_sock}. The first argument will be the open socket to the child.

"$self−>idle_loop_hook()"

This hook is called in every pass through the main process wait loop, every "check_for_waiting" seconds. The first argument is a reference to an array of file descriptors that can be read at the moment.

BUGS

Tests don’t seem to work on Win32. Any ideas or patches would be welcome.

TO DO

See Net::Server

AUTHOR

Paul T. Seamons paul@seamons.com

THANKS

See Net::Server

SEE ALSO

Please see also Net::Server::Fork, Net::Server::INET, Net::Server::PreForkSimple, Net::Server::MultiType, Net::Server::Single Net::Server::SIG Net::Server::Daemonize Net::Server::Proto






Opportunity


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.





Free Software


Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.


Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.





Free Books


The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.


Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.





Education


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.


Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.