.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::Server::Prefork 3pm" .TH Mojo::Server::Prefork 3pm "2013-04-15" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Server::Prefork \- Preforking non\-blocking I/O HTTP and WebSocket server .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Server::Prefork; \& \& my $prefork = Mojo::Server::Prefork\->new(listen => [\*(Aqhttp://*:8080\*(Aq]); \& $prefork\->unsubscribe(\*(Aqrequest\*(Aq); \& $prefork\->on(request => sub { \& my ($prefork, $tx) = @_; \& \& # Request \& my $method = $tx\->req\->method; \& my $path = $tx\->req\->url\->path; \& \& # Response \& $tx\->res\->code(200); \& $tx\->res\->headers\->content_type(\*(Aqtext/plain\*(Aq); \& $tx\->res\->body("$method request for $path!"); \& \& # Resume transaction \& $tx\->resume; \& }); \& $prefork\->run; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Server::Prefork is a full featured, \s-1UNIX\s0 optimized, preforking non-blocking I/O \s-1HTTP\s0 and WebSocket server, built around the very well tested and reliable Mojo::Server::Daemon, with \f(CW\*(C`IPv6\*(C'\fR, \f(CW\*(C`TLS\*(C'\fR, \f(CW\*(C`Comet\*(C'\fR (long polling), \f(CW\*(C`keep\-alive\*(C'\fR, connection pooling, timeout, cookie, multipart and multiple event loop support. Note that the server uses signals for process management, so you should avoid modifying signal handlers in your applications. .PP Optional modules \s-1EV\s0 (4.0+), IO::Socket::IP (0.16+) and IO::Socket::SSL (1.75+) are supported transparently through Mojo::IOLoop, and used if installed. Individual features can also be disabled with the \s-1MOJO_NO_IPV6\s0 and \s-1MOJO_NO_TLS\s0 environment variables. .PP See Mojolicious::Guides::Cookbook for more. .SH "SIGNALS" .IX Header "SIGNALS" Mojo::Server::Prefork can be controlled at runtime with the following signals. .SS "Manager" .IX Subsection "Manager" .IP "\s-1INT\s0, \s-1TERM\s0" 2 .IX Item "INT, TERM" Shutdown server immediately. .IP "\s-1QUIT\s0" 2 .IX Item "QUIT" Shutdown server gracefully. .IP "\s-1TTIN\s0" 2 .IX Item "TTIN" Increase worker pool by one. .IP "\s-1TTOU\s0" 2 .IX Item "TTOU" Decrease worker pool by one. .SS "Worker" .IX Subsection "Worker" .IP "\s-1INT\s0, \s-1TERM\s0" 2 .IX Item "INT, TERM" Stop worker immediately. .IP "\s-1QUIT\s0" 2 .IX Item "QUIT" Stop worker gracefully. .SH "EVENTS" .IX Header "EVENTS" Mojo::Server::Prefork inherits all events from Mojo::Server::Daemon and can emit the following new ones. .SS "finish" .IX Subsection "finish" .Vb 4 \& $prefork\->on(finish => sub { \& my ($prefork, $graceful) = @_; \& ... \& }); .Ve .PP Emitted when the server shuts down. .PP .Vb 4 \& $prefork\->on(finish => sub { \& my ($prefork, $graceful) = @_; \& say $graceful ? \*(AqGraceful server shutdown\*(Aq : \*(AqServer shutdown\*(Aq; \& }); .Ve .SS "heartbeat" .IX Subsection "heartbeat" .Vb 4 \& $prefork\->on(heartbeat => sub { \& my ($prefork, $pid) = @_; \& ... \& }); .Ve .PP Emitted when a heartbeat message has been received from a worker. .PP .Vb 4 \& $prefork\->on(heartbeat => sub { \& my ($prefork, $pid) = @_; \& say "Worker $pid has a heartbeat"; \& }); .Ve .SS "reap" .IX Subsection "reap" .Vb 4 \& $prefork\->on(reap => sub { \& my ($prefork, $pid) = @_; \& ... \& }); .Ve .PP Emitted when a child process dies. .PP .Vb 4 \& $prefork\->on(reap => sub { \& my ($prefork, $pid) = @_; \& say "Worker $pid stopped"; \& }); .Ve .SS "spawn" .IX Subsection "spawn" .Vb 4 \& $prefork\->on(spawn => sub { \& my ($prefork, $pid) = @_; \& ... \& }); .Ve .PP Emitted when a worker process is spawned. .PP .Vb 4 \& $prefork\->on(spawn => sub { \& my ($prefork, $pid) = @_; \& say "Worker $pid started"; \& }); .Ve .SS "wait" .IX Subsection "wait" .Vb 4 \& $prefork\->on(wait => sub { \& my $prefork = shift; \& ... \& }); .Ve .PP Emitted when the manager starts waiting for new heartbeat messages. .PP .Vb 5 \& $prefork\->on(wait => sub { \& my $prefork = shift; \& my $workers = $prefork\->workers; \& say "Waiting for heartbeat messages from $workers workers"; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Server::Prefork inherits all attributes from Mojo::Server::Daemon and implements the following new ones. .SS "accept_interval" .IX Subsection "accept_interval" .Vb 2 \& my $interval = $prefork\->accept_interval; \& $prefork = $prefork\->accept_interval(0.5); .Ve .PP Interval in seconds for trying to reacquire the accept mutex and connection management, defaults to \f(CW0.025\fR. Note that changing this value can affect performance and idle \s-1CPU\s0 usage. .SS "accepts" .IX Subsection "accepts" .Vb 2 \& my $accepts = $prefork\->accepts; \& $prefork = $prefork\->accepts(100); .Ve .PP Maximum number of connections a worker is allowed to accept before stopping gracefully, defaults to \f(CW1000\fR. Setting the value to \f(CW0\fR will allow workers to accept new connections indefinitely. Note that up to half of this value can be subtracted randomly to improve load balancing, and that worker processes will stop sending heartbeat messages once the limit has been reached. .SS "graceful_timeout" .IX Subsection "graceful_timeout" .Vb 2 \& my $timeout = $prefork\->graceful_timeout; \& $prefork = $prefork\->graceful_timeout(15); .Ve .PP Maximum amount of time in seconds stopping a worker gracefully may take before being forced, defaults to \f(CW20\fR. .SS "heartbeat_interval" .IX Subsection "heartbeat_interval" .Vb 2 \& my $interval = $prefork\->heartbeat_intrval; \& $prefork = $prefork\->heartbeat_interval(3); .Ve .PP Heartbeat interval in seconds, defaults to \f(CW5\fR. .SS "heartbeat_timeout" .IX Subsection "heartbeat_timeout" .Vb 2 \& my $timeout = $prefork\->heartbeat_timeout; \& $prefork = $prefork\->heartbeat_timeout(2); .Ve .PP Maximum amount of time in seconds before a worker without a heartbeat will be stopped gracefully, defaults to \f(CW20\fR. .SS "lock_file" .IX Subsection "lock_file" .Vb 2 \& my $file = $prefork\->lock_file; \& $prefork = $prefork\->lock_file(\*(Aq/tmp/prefork.lock\*(Aq); .Ve .PP Full path of accept mutex lock file prefix, to which the process id will be appended, defaults to a random temporary path. .SS "lock_timeout" .IX Subsection "lock_timeout" .Vb 2 \& my $timeout = $prefork\->lock_timeout; \& $prefork = $prefork\->lock_timeout(1); .Ve .PP Maximum amount of time in seconds a worker may block when waiting for the accept mutex, defaults to \f(CW0.5\fR. .SS "multi_accept" .IX Subsection "multi_accept" .Vb 2 \& my $multi = $prefork\->multi_accept; \& $prefork = $prefork\->multi_accept(100); .Ve .PP Number of connections to accept at once, defaults to \f(CW50\fR. .SS "pid_file" .IX Subsection "pid_file" .Vb 2 \& my $file = $prefork\->pid_file; \& $prefork = $prefork\->pid_file(\*(Aq/tmp/prefork.pid\*(Aq); .Ve .PP Full path of process id file, defaults to a random temporary path. .SS "workers" .IX Subsection "workers" .Vb 2 \& my $workers = $prefork\->workers; \& $prefork = $prefork\->workers(10); .Ve .PP Number of worker processes, defaults to \f(CW4\fR. A good rule of thumb is two worker processes per \s-1CPU\s0 core. .SH "METHODS" .IX Header "METHODS" Mojo::Server::Prefork inherits all methods from Mojo::Server::Daemon and implements the following new ones. .SS "check_pid" .IX Subsection "check_pid" .Vb 1 \& my $pid = $prefork\->check_pid; .Ve .PP Get process id for running server from \f(CW\*(C`pid_file\*(C'\fR or delete it if server is not running. .PP .Vb 1 \& say \*(AqServer is not running\*(Aq unless $prefork\->check_pid; .Ve .SS "run" .IX Subsection "run" .Vb 1 \& $prefork\->run; .Ve .PP Run server. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .