SlideShare a Scribd company logo
1 of 18
Download to read offline
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
    the goals
         no downtime
         no resource leaks
         fail-safe



Sep 10 2009       Server::Starter - a superdaemon to hot-deploy server programs   2
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
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
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
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 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
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
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
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(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
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
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
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
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
ToDo

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




Sep 10 2009       Server::Starter - a superdaemon to hot-deploy server programs   17
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

More Related Content

Viewers also liked

Writing Prefork Workers / Servers
Writing Prefork Workers / ServersWriting Prefork Workers / Servers
Writing Prefork Workers / Servers
Kazuho Oku
 
Judes Drafting Table The Bowling Question
Judes Drafting Table   The Bowling QuestionJudes Drafting Table   The Bowling Question
Judes Drafting Table The Bowling Question
sixteen.wiishes
 
Lewis Woodpecker by Taylor
Lewis Woodpecker by TaylorLewis Woodpecker by Taylor
Lewis Woodpecker by Taylor
vebrya
 
Poplava sisljavic ppt
Poplava sisljavic pptPoplava sisljavic ppt
Poplava sisljavic ppt
Gavranica
 
Task 4 Louise Nicholson
Task 4 Louise NicholsonTask 4 Louise Nicholson
Task 4 Louise Nicholson
Louise1
 
Presentazione Cerisdi (7Nov2008)
Presentazione Cerisdi (7Nov2008)Presentazione Cerisdi (7Nov2008)
Presentazione Cerisdi (7Nov2008)
euresgroup
 
Using CKAN as a data store
Using CKAN as a data storeUsing CKAN as a data store
Using CKAN as a data store
Joss Winn
 
Stepz - An Introduction
Stepz - An IntroductionStepz - An Introduction
Stepz - An Introduction
Pratik Gupta
 

Viewers also liked (20)

Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
Writing Prefork Workers / Servers
Writing Prefork Workers / ServersWriting Prefork Workers / Servers
Writing Prefork Workers / Servers
 
Developing the fastest HTTP/2 server
Developing the fastest HTTP/2 serverDeveloping the fastest HTTP/2 server
Developing the fastest HTTP/2 server
 
The best power diy marketing tips for entrepreneurs
The best power diy marketing tips for entrepreneursThe best power diy marketing tips for entrepreneurs
The best power diy marketing tips for entrepreneurs
 
My presentation at Busan's Asia Exhibition Forum 2013
My presentation at Busan's Asia Exhibition Forum 2013My presentation at Busan's Asia Exhibition Forum 2013
My presentation at Busan's Asia Exhibition Forum 2013
 
Judes Drafting Table The Bowling Question
Judes Drafting Table   The Bowling QuestionJudes Drafting Table   The Bowling Question
Judes Drafting Table The Bowling Question
 
Lewis Woodpecker by Taylor
Lewis Woodpecker by TaylorLewis Woodpecker by Taylor
Lewis Woodpecker by Taylor
 
Civil War Causes
Civil War CausesCivil War Causes
Civil War Causes
 
Projet Enfance
Projet EnfanceProjet Enfance
Projet Enfance
 
My garden
My gardenMy garden
My garden
 
Pomoc
PomocPomoc
Pomoc
 
Global warming
Global warmingGlobal warming
Global warming
 
Santiago Calatrava
Santiago CalatravaSantiago Calatrava
Santiago Calatrava
 
Poplava sisljavic ppt
Poplava sisljavic pptPoplava sisljavic ppt
Poplava sisljavic ppt
 
香港六合彩 » SlideShare
香港六合彩 » SlideShare香港六合彩 » SlideShare
香港六合彩 » SlideShare
 
Task 4 Louise Nicholson
Task 4 Louise NicholsonTask 4 Louise Nicholson
Task 4 Louise Nicholson
 
Presentazione Cerisdi (7Nov2008)
Presentazione Cerisdi (7Nov2008)Presentazione Cerisdi (7Nov2008)
Presentazione Cerisdi (7Nov2008)
 
Cytoscape プロジェクト現状報告 2011年2月
Cytoscape プロジェクト現状報告 2011年2月Cytoscape プロジェクト現状報告 2011年2月
Cytoscape プロジェクト現状報告 2011年2月
 
Using CKAN as a data store
Using CKAN as a data storeUsing CKAN as a data store
Using CKAN as a data store
 
Stepz - An Introduction
Stepz - An IntroductionStepz - An Introduction
Stepz - An Introduction
 

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

Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
FuseSource.com
 
appserver.io tutorial
appserver.io tutorialappserver.io tutorial
appserver.io tutorial
appserver.io
 
continuous delivery at SAP IT for devopscon Israel
continuous delivery at SAP IT for devopscon Israelcontinuous delivery at SAP IT for devopscon Israel
continuous delivery at SAP IT for devopscon Israel
Alon Aizenberg
 

Similar to Server Starter - a superdaemon to hot-deploy server programs (20)

Real time data processing with kafla spark integration
Real time data processing with kafla spark integrationReal time data processing with kafla spark integration
Real time data processing with kafla spark integration
 
AWS SnapStart at Community Day Istanbul 2023
AWS SnapStart at Community Day Istanbul 2023AWS SnapStart at Community Day Istanbul 2023
AWS SnapStart at Community Day Istanbul 2023
 
Building Web APIs that Scale
Building Web APIs that ScaleBuilding Web APIs that Scale
Building Web APIs that Scale
 
Java App On Digital Ocean: Deploying With Gitlab CI/CD
Java App On Digital Ocean: Deploying With Gitlab CI/CDJava App On Digital Ocean: Deploying With Gitlab CI/CD
Java App On Digital Ocean: Deploying With Gitlab CI/CD
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Tuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on MobicentsTuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on Mobicents
 
V fabric overview
V fabric overviewV fabric overview
V fabric overview
 
Tungsten University: Configure and provision Tungsten clusters
Tungsten University: Configure and provision Tungsten clustersTungsten University: Configure and provision Tungsten clusters
Tungsten University: Configure and provision Tungsten clusters
 
Zero downtime deployment of micro-services with Kubernetes
Zero downtime deployment of micro-services with KubernetesZero downtime deployment of micro-services with Kubernetes
Zero downtime deployment of micro-services with Kubernetes
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
 
appserver.io tutorial
appserver.io tutorialappserver.io tutorial
appserver.io tutorial
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
JavaFX Uni Parthenope
JavaFX Uni ParthenopeJavaFX Uni Parthenope
JavaFX Uni Parthenope
 
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
 
Windows Azure Interoperability
Windows Azure InteroperabilityWindows Azure Interoperability
Windows Azure Interoperability
 
continuous delivery at SAP IT for devopscon Israel
continuous delivery at SAP IT for devopscon Israelcontinuous delivery at SAP IT for devopscon Israel
continuous delivery at SAP IT for devopscon Israel
 
Continuous Delivery at SAP IT, Alon Aizenberg
Continuous Delivery at SAP IT, Alon AizenbergContinuous Delivery at SAP IT, Alon Aizenberg
Continuous Delivery at SAP IT, Alon Aizenberg
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and Tomorrow
 

More from Kazuho Oku

Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsiveness
Kazuho Oku
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
Kazuho Oku
 

More from Kazuho Oku (20)

HTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときHTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないとき
 
QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7
 
HTTP/2の課題と将来
HTTP/2の課題と将来HTTP/2の課題と将来
HTTP/2の課題と将来
 
TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondReorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and Beyond
 
Recent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using rubyRecent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using ruby
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsiveness
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsiveness
 
TLS & LURK @ IETF 95
TLS & LURK @ IETF 95TLS & LURK @ IETF 95
TLS & LURK @ IETF 95
 
HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
 
Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5
 
HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計
 
H2O - making the Web faster
H2O - making the Web fasterH2O - making the Web faster
H2O - making the Web faster
 
H2O - making HTTP better
H2O - making HTTP betterH2O - making HTTP better
H2O - making HTTP better
 
H2O - the optimized HTTP server
H2O - the optimized HTTP serverH2O - the optimized HTTP server
H2O - the optimized HTTP server
 
JSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedJSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons Learned
 
JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法
 
JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Server Starter - a superdaemon to hot-deploy server programs

  • 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