Server Starter - a superdaemon to hot-deploy server programs

  • 4,362 views
Uploaded on

Explains techniques used to write hot-deployable TCP servers, introduces a superdaemon to handle the problems.

Explains techniques used to write hot-deployable TCP servers, introduces a superdaemon to handle the problems.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,362
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
15
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Server::Starter a superdaemon to hot-deploy server programs Cybozu Labs, Inc. Kazuho Oku
  • 2. Hot deployment  what is it?  upgrading web application without restarting the application server  the goals  no downtime  no resource leaks  fail-safe Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 2
  • 3. Current techniques  restart the interpreter (mod_perl)  pros: graceful  cons: XS may cause resource leaks, service-down on deployment failure, cannot implement in pure- perl  bind to unix socket (FastCGI)  pros: graceful, fail-safe  cons: only useful for local-machine communication Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 3
  • 4. Current techniques (cont'd)  exec(myself) (Net::Server)  pros: graceful, pure-perl  cons: file descriptor leaks, service-down on deployment failure Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 4
  • 5. Server::Starter  a superdaemon for hot-deploying TCP servers  superdaemon binds to TCP ports, then spawns the application server listen accept fork & exec SIGTERM app. logic accept spawn app. servers fork & exec app. logic SIGHUP Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 5
  • 6. Reaching the Goals Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 6
  • 7. No downtime  listening socket shared by old and new generation app. servers  old app. servers receive SIGTERM after new servers start listen accept fork & exec SIGTERM accept logic app. spawn app. servers fork & exec app. logic SIGHUP Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 7
  • 8. No resource leaks  no chance of resource leaks  every generation of app. servers spawned from superdaemon listen accept fork & exec SIGTERM accept logic app. spawn app. servers fork & exec app. logic SIGHUP Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 8
  • 9. Fail-safe  old app. server retired if and only if the new app. server starts up successfully  service continues even if the updated app. server fails to start, in cases like missing modules, etc.  a good practice is to do self-testing in the app. server before starting to serve client connections  is also an efficient way to preload modules listen accept fork & exec SIGTERM accept logic app. spawn app. servers fork & exec app. logic SIGHUP Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 9
  • 10. Demo Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 10
  • 11. Using Server::Starter Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 11
  • 12. The Low-level Code # from command line % start_server --port=80 my_httpd # in my_httpd use Server::Starter qw(server_ports); my $listen_sock = IO::Socket::INET->new( Proto => 'tcp', ); $listen_sock->fdopen((values %{server_ports()})[0], 'w') or die "failed to bind to listening socket:$!"; while (1) { if (my $conn = $listen_sock->accept) { .... } } Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 12
  • 13. Net::Server::SS::PreFork  subclass of Net::Server::PreFork # from command line % start_server --port=80 my_server.pl # in my_server.pl use base qw(Net::Server::SS::PreFork); sub process_request { #...code... } __PACKAGE__->run(); Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 13
  • 14. Using together with HTTP::Server::Simple  HTTP::Server::Simple can use Net::Server::SS::PreFork as a backend  and many WAFs support HTTP::Server::Simple package MyServer; use base qw(HTTP::Server::Simple::CGI); sub net_server { 'Net::Server::SS::PreFork' }; sub handle_request { print "HTTP/1.0 200 HOKrnContent-Type: text/plainrnrnHello World"; } 1; Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 14
  • 15. Using together with PSGI / Plack  started writing Plack::Impl::SSPreFork  on my github fork of Plack  uid, etc. aren't configurable yet :-( # from command line % start_server --port=80 -- plackup -i SSPreFork MyApp.pm Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 15
  • 16. Launching from daemontools  daemontools  a (better) alternative to init.d scripts, by DJB  start_server script is designed to be run under daemontools  restart using –h (SIGHUP)  all logs to STDERR Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 16
  • 17. ToDo  Support for FastCGI  although ... (ry  init.d-style startup mode Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 17
  • 18. Conclusion  with Server::Starter, it is easy to write hot-deployable TCP servers Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 18