1Mojo::Server::HypnotoadU(s3e)r Contributed Perl DocumentaMtoijoon::Server::Hypnotoad(3)
2
3
4
6 Mojo::Server::Hypnotoad - A production web serv...ALL GLORY TO THE
7 HYPNOTOAD!
8
10 use Mojo::Server::Hypnotoad;
11
12 my $hypnotoad = Mojo::Server::Hypnotoad->new;
13 $hypnotoad->run('/home/sri/myapp.pl');
14
16 Mojo::Server::Hypnotoad is a full featured, UNIX optimized, pre-forking
17 non-blocking I/O HTTP and WebSocket server, built around the very well
18 tested and reliable Mojo::Server::Prefork, with IPv6, TLS, SNI, UNIX
19 domain socket, Comet (long polling), keep-alive, multiple event loop
20 and hot deployment support that just works. Note that the server uses
21 signals for process management, so you should avoid modifying signal
22 handlers in your applications.
23
24 To start applications with it you can use the hypnotoad script, which
25 listens on port 8080, automatically daemonizes the server process and
26 defaults to "production" mode for Mojolicious and Mojolicious::Lite
27 applications.
28
29 $ hypnotoad ./myapp.pl
30
31 You can run the same command again for automatic hot deployment.
32
33 $ hypnotoad ./myapp.pl
34 Starting hot deployment for Hypnotoad server 31841.
35
36 This second invocation will load the application again, detect the
37 process id file with it, and send a "USR2" signal to the already
38 running server.
39
40 For better scalability (epoll, kqueue) and to provide non-blocking name
41 resolution, SOCKS5 as well as TLS support, the optional modules EV
42 (4.0+), Net::DNS::Native (0.15+), IO::Socket::Socks (0.64+) and
43 IO::Socket::SSL (2.009+) will be used automatically if possible.
44 Individual features can also be disabled with the "MOJO_NO_NNR",
45 "MOJO_NO_SOCKS" and "MOJO_NO_TLS" environment variables.
46
47 See "DEPLOYMENT" in Mojolicious::Guides::Cookbook for more.
48
50 The Mojo::Server::Hypnotoad manager process can be controlled at
51 runtime with the following signals.
52
53 INT, TERM
54 Shut down server immediately.
55
56 QUIT
57 Shut down server gracefully.
58
59 TTIN
60 Increase worker pool by one.
61
62 TTOU
63 Decrease worker pool by one.
64
65 USR2
66 Attempt zero downtime software upgrade (hot deployment) without losing
67 any incoming connections.
68
69 Manager (old)
70 |- Worker [1]
71 |- Worker [2]
72 |- Worker [3]
73 |- Worker [4]
74 +- Manager (new)
75 |- Worker [1]
76 |- Worker [2]
77 |- Worker [3]
78 +- Worker [4]
79
80 The new manager will automatically send a "QUIT" signal to the old
81 manager and take over serving requests after starting up successfully.
82
84 Mojo::Server::Hypnotoad worker processes can be controlled at runtime
85 with the following signals.
86
87 QUIT
88 Stop worker gracefully.
89
91 Mojo::Server::Hypnotoad can be configured with the following settings,
92 see "Hypnotoad" in Mojolicious::Guides::Cookbook for examples.
93
94 accepts
95 accepts => 100
96
97 Maximum number of connections a worker is allowed to accept, before
98 stopping gracefully and then getting replaced with a newly started
99 worker, defaults to the value of "accepts" in Mojo::Server::Prefork.
100 Setting the value to 0 will allow workers to accept new connections
101 indefinitely. Note that up to half of this value can be subtracted
102 randomly to improve load balancing, and to make sure that not all
103 workers restart at the same time.
104
105 backlog
106 backlog => 128
107
108 Listen backlog size, defaults to the value of "backlog" in
109 Mojo::Server::Daemon.
110
111 clients
112 clients => 100
113
114 Maximum number of accepted connections each worker process is allowed
115 to handle concurrently, before stopping to accept new incoming
116 connections, defaults to the value of "max_connections" in
117 Mojo::IOLoop. Note that high concurrency works best with applications
118 that perform mostly non-blocking operations, to optimize for blocking
119 operations you can decrease this value and increase "workers" instead
120 for better performance.
121
122 graceful_timeout
123 graceful_timeout => 15
124
125 Maximum amount of time in seconds stopping a worker gracefully may take
126 before being forced, defaults to the value of "graceful_timeout" in
127 Mojo::Server::Prefork. Note that this value should usually be a little
128 larger than the maximum amount of time you expect any one request to
129 take.
130
131 heartbeat_interval
132 heartbeat_interval => 3
133
134 Heartbeat interval in seconds, defaults to the value of
135 "heartbeat_interval" in Mojo::Server::Prefork.
136
137 heartbeat_timeout
138 heartbeat_timeout => 2
139
140 Maximum amount of time in seconds before a worker without a heartbeat
141 will be stopped gracefully, defaults to the value of
142 "heartbeat_timeout" in Mojo::Server::Prefork. Note that this value
143 should usually be a little larger than the maximum amount of time you
144 expect any one operation to block the event loop.
145
146 inactivity_timeout
147 inactivity_timeout => 10
148
149 Maximum amount of time in seconds a connection can be inactive before
150 getting closed, defaults to the value of "inactivity_timeout" in
151 Mojo::Server::Daemon. Setting the value to 0 will allow connections to
152 be inactive indefinitely.
153
154 listen
155 listen => ['http://*:80']
156
157 Array reference with one or more locations to listen on, defaults to
158 "http://*:8080". See also "listen" in Mojo::Server::Daemon for more
159 examples.
160
161 pid_file
162 pid_file => '/var/run/hypnotoad.pid'
163
164 Full path to process id file, defaults to "hypnotoad.pid" in the same
165 directory as the application. Note that this value can only be changed
166 after the server has been stopped.
167
168 proxy
169 proxy => 1
170
171 Activate reverse proxy support, which allows for the "X-Forwarded-For"
172 and "X-Forwarded-Proto" headers to be picked up automatically, defaults
173 to the value of "reverse_proxy" in Mojo::Server.
174
175 requests
176 requests => 50
177
178 Number of keep-alive requests per connection, defaults to the value of
179 "max_requests" in Mojo::Server::Daemon.
180
181 spare
182 spare => 4
183
184 Temporarily spawn up to this number of additional workers if there is a
185 need, defaults to the value of "spare" in Mojo::Server::Prefork. This
186 allows for new workers to be started while old ones are still shutting
187 down gracefully, drastically reducing the performance cost of worker
188 restarts.
189
190 upgrade_timeout
191 upgrade_timeout => 45
192
193 Maximum amount of time in seconds a zero downtime software upgrade may
194 take before getting canceled, defaults to 180.
195
196 workers
197 workers => 10
198
199 Number of worker processes, defaults to the value of "workers" in
200 Mojo::Server::Prefork. A good rule of thumb is two worker processes per
201 CPU core for applications that perform mostly non-blocking operations,
202 blocking operations often require more and benefit from decreasing
203 concurrency with "clients" (often as low as 1). Note that during zero
204 downtime software upgrades there will be twice as many workers active
205 for a short amount of time.
206
208 Mojo::Server::Hypnotoad implements the following attributes.
209
210 prefork
211 my $prefork = $hypnotoad->prefork;
212 $hypnotoad = $hypnotoad->prefork(Mojo::Server::Prefork->new);
213
214 Mojo::Server::Prefork object this server manages.
215
216 upgrade_timeout
217 my $timeout = $hypnotoad->upgrade_timeout;
218 $hypnotoad = $hypnotoad->upgrade_timeout(15);
219
220 Maximum amount of time in seconds a zero downtime software upgrade may
221 take before getting canceled, defaults to 180.
222
224 Mojo::Server::Hypnotoad inherits all methods from Mojo::Base and
225 implements the following new ones.
226
227 configure
228 $hypnotoad->configure('hypnotoad');
229
230 Configure server from application settings.
231
232 run
233 $hypnotoad->run('script/my_app');
234
235 Run server for application and wait for "MANAGER SIGNALS".
236
238 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
239
240
241
242perl v5.30.1 2020-01-30 Mojo::Server::Hypnotoad(3)