Server::Starter
a superdaemon to hot-deploy server programs



          Cybozu Labs, Inc.
            Kazuho Oku
Hot deployment

    what is it?
         upgrading web application without restarting the
          application server
 ...
Current techniques

    restart the interpreter (mod_perl)
         pros: graceful
         cons: XS may cause resource...
Current techniques (cont'd)

    exec(myself) (Net::Server)
         pros: graceful, pure-perl
         cons: file desc...
Server::Starter

    a superdaemon for hot-deploying TCP servers
         superdaemon binds to TCP ports, then spawns
  ...
Reaching the Goals




Sep 10 2009   Server::Starter - a superdaemon to hot-deploy server programs   6
No downtime

    listening socket shared by old and new
     generation app. servers
    old app. servers receive SIGTER...
No resource leaks

    no chance of resource leaks
         every generation of app. servers spawned from
          supe...
Fail-safe

    old app. server retired if and only if the
     new app. server starts up successfully
         service c...
Demo




Sep 10 2009   Server::Starter - a superdaemon to hot-deploy server programs   10
Using Server::Starter




Sep 10 2009   Server::Starter - a superdaemon to hot-deploy server programs   11
The Low-level Code
   # from command line
   % start_server --port=80 my_httpd

   # in my_httpd
   use Server::Starter qw...
Net::Server::SS::PreFork

    subclass of Net::Server::PreFork
   # from command line
   % start_server --port=80 my_serv...
Using together with HTTP::Server::Simple

    HTTP::Server::Simple can use
     Net::Server::SS::PreFork as a backend
   ...
Using together with PSGI / Plack

    started writing Plack::Impl::SSPreFork
         on my github fork of Plack
       ...
Launching from daemontools

    daemontools
         a (better) alternative to init.d scripts, by DJB
    start_server ...
ToDo

    Support for FastCGI
         although ... (ry
    init.d-style startup mode




Sep 10 2009       Server::Sta...
Conclusion

    with Server::Starter, it is easy to write
     hot-deployable TCP servers




Sep 10 2009   Server::Start...
Upcoming SlideShare
Loading in...5
×

Server Starter - a superdaemon to hot-deploy server programs

5,177

Published on

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

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,177
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Server Starter - a superdaemon to hot-deploy server programs

  1. 1. Server::Starter a superdaemon to hot-deploy server programs Cybozu Labs, Inc. Kazuho Oku
  2. 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. 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. 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. 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. 6. Reaching the Goals Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 6
  7. 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. 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. 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. 10. Demo Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 10
  11. 11. Using Server::Starter Sep 10 2009 Server::Starter - a superdaemon to hot-deploy server programs 11
  12. 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. 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. 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. 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. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×