Mojo::Server::Hypnotoad - ALL GLORY TO THE HYPNOTOAD!
use Mojo::Server::Hypnotoad; my $hypnotoad = Mojo::Server::Hypnotoad->new; $hypnotoad->run('/home/sri/myapp.pl');
Mojo::Server::Hypnotoad is a full featured, UNIX optimized, preforking non-blocking I/O HTTP and WebSocket server, built around the very well tested and reliable Mojo::Server::Prefork, with IPv6, TLS, Comet (long polling), keep-alive, multiple event loop and hot deployment support that just works. Note that the server uses signals for process management, so you should avoid modifying signal handlers in your applications.
To start applications with it you can use the hypnotoad script, for Mojolicious and Mojolicious::Lite applications it will default to production mode.
production
$ hypnotoad myapp.pl Server available at http://127.0.0.1:8080.
You can run the same command again for automatic hot deployment.
$ hypnotoad myapp.pl Starting hot deployment for Hypnotoad server 31841.
This second invocation will load the application again, detect the process id file with it, and send a "USR2" signal to the already running server.
For better scalability (epoll, kqueue) and to provide IPv6, SOCKS5 as well as TLS support, the optional modules EV (4.0+), IO::Socket::IP (0.20+), IO::Socket::Socks (0.64+) and IO::Socket::SSL (1.84+) will be used automatically if they are installed. Individual features can also be disabled with the MOJO_NO_IPV6, MOJO_NO_SOCKS and MOJO_NO_TLS environment variables.
MOJO_NO_IPV6
MOJO_NO_SOCKS
MOJO_NO_TLS
See "DEPLOYMENT" in Mojolicious::Guides::Cookbook for more.
The Mojo::Server::Hypnotoad manager process can be controlled at runtime with the following signals.
Shutdown server immediately.
Shutdown server gracefully.
Increase worker pool by one.
Decrease worker pool by one.
Attempt zero downtime software upgrade (hot deployment) without losing any incoming connections.
Manager (old) |- Worker [1] |- Worker [2] |- Worker [3] |- Worker [4] +- Manager (new) |- Worker [1] |- Worker [2] |- Worker [3] +- Worker [4]
The new manager will automatically send a "QUIT" signal to the old manager and take over serving requests after starting up successfully.
Mojo::Server::Hypnotoad worker processes can be controlled at runtime with the following signals.
Stop worker immediately.
Stop worker gracefully.
Mojo::Server::Hypnotoad can be configured with the following settings, see "Hypnotoad" in Mojolicious::Guides::Cookbook for examples.
accept_interval => 0.5
Interval in seconds for trying to reacquire the accept mutex, defaults to the value of "accept_interval" in Mojo::IOLoop. Note that changing this value can affect performance and idle CPU usage.
accepts => 100
Maximum number of connections a worker is allowed to accept before stopping gracefully, defaults to the value of "accepts" in Mojo::Server::Prefork. Setting the value to 0 will allow workers to accept new connections indefinitely. Note that up to half of this value can be subtracted randomly to improve load balancing.
0
backlog => 128
Listen backlog size, defaults to the value of "backlog" in Mojo::Server::Daemon.
clients => 100
Maximum number of concurrent client connections per worker process, defaults to the value of "max_connections" in Mojo::IOLoop. Note that high concurrency works best with applications that perform mostly non-blocking operations, to optimize for blocking operations you can decrease this value and increase "workers" instead for better performance.
graceful_timeout => 15
Maximum amount of time in seconds stopping a worker gracefully may take before being forced, defaults to the value of "graceful_timeout" in Mojo::Server::Prefork.
group => 'staff'
Group name for worker processes, defaults to the value of "group" in Mojo::Server.
heartbeat_interval => 3
Heartbeat interval in seconds, defaults to the value of "heartbeat_interval" in Mojo::Server::Prefork.
heartbeat_timeout => 2
Maximum amount of time in seconds before a worker without a heartbeat will be stopped gracefully, defaults to the value of "heartbeat_timeout" in Mojo::Server::Prefork.
inactivity_timeout => 10
Maximum amount of time in seconds a connection can be inactive before getting closed, defaults to the value of "inactivity_timeout" in Mojo::Server::Daemon. Setting the value to 0 will allow connections to be inactive indefinitely.
keep_alive_requests => 50
Number of keep-alive requests per connection, defaults to the value of "max_requests" in Mojo::Server::Daemon.
listen => ['http://*:80']
List of one or more locations to listen on, defaults to http://*:8080. See also "listen" in Mojo::Server::Daemon for more examples.
http://*:8080
lock_file => '/tmp/hypnotoad.lock'
Full path of accept mutex lock file prefix, to which the process id will be appended, defaults to the value of "lock_file" in Mojo::Server::Prefork.
lock_timeout => 0.5
Maximum amount of time in seconds a worker may block when waiting for the accept mutex, defaults to the value of "lock_timeout" in Mojo::Server::Prefork. Note that changing this value can affect performance and idle CPU usage.
multi_accept => 100
Number of connections to accept at once, defaults to the value of "multi_accept" in Mojo::IOLoop.
pid_file => '/var/run/hypnotoad.pid'
Full path to process id file, defaults to hypnotoad.pid in the same directory as the application. Note that this value can only be changed after the server has been stopped.
hypnotoad.pid
proxy => 1
Activate reverse proxy support, which allows for the X-Forwarded-For and X-Forwarded-Proto headers to be picked up automatically, defaults to the value of "reverse_proxy" in Mojo::Server.
X-Forwarded-For
X-Forwarded-Proto
upgrade_timeout => 45
Maximum amount of time in seconds a zero downtime software upgrade may take before getting canceled, defaults to the value of "upgrade_timeout".
user => 'sri'
Username for worker processes, defaults to the value of "user" in Mojo::Server.
workers => 10
Number of worker processes, defaults to the value of "workers" in Mojo::Server::Prefork. A good rule of thumb is two worker processes per CPU core for applications that perform mostly non-blocking operations, blocking operations often require more and benefit from decreasing the number of concurrent "clients" (often as low as 1).
1
Mojo::Server::Hypnotoad implements the following attributes.
my $prefork = $hypnotoad->prefork; $hypnotoad = $hypnotoad->prefork(Mojo::Server::Prefork->new);
Mojo::Server::Prefork object this server manages.
my $timeout = $hypnotoad->upgrade_timeout; $hypnotoad = $hypnotoad->upgrade_timeout(15);
Maximum amount of time in seconds a zero downtime software upgrade may take before getting canceled, defaults to 60.
60
Mojo::Server::Hypnotoad inherits all methods from Mojo::Base and implements the following new ones.
$hypnotoad->configure('hypnotoad');
Configure server from application settings.
$hypnotoad->run('script/myapp');
Run server for application.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.