SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Node.js
In Production




                20.01.2011
About

             Contributor                                         Co-founder




                                          Felix Geisendörfer
             node.js driver                                    node-formidable




-   Joined the mailing list in June 26, 2009
-   Co-Transloadit
-   When I joined there where #24 people
-   First patch in September 2009
-   Now mailing list has > 3400 members
File uploading & processing as a
                   service for other web applications.


- The app we run in production
- Not a “typical” app, no html rendering, only JSON APIs
Are you running
node in production?
Our imagination
Our first attempt
~1
                                                              Ye

                         Transloadit v1
                                                                 a   r
                                                                         ag
                                                                           o




          • Complete failure

          • Node randomly crashed with:
              (evcom) recv() Success


          • A mess of code, hard to maintain
* http://transloadit.com/blog/2010/04/to-launch-or-not
Today
Well, almost : )
N

        Transloadit v2
                                           ow




• Processed > 2 TB of data

• Not seen a node bug in production yet

• Clean code base, 100% test coverage
How to get there?
Hosting
Managed / Heroku-style

• Joyent (no.de)
• Nodejitsu (nodejitsu.com)
• Duostack (duostack.com)
• Nodefu (nodefu.com)
• Heroku (heroku.com)
Self-managed

• Amazon Ec2
• Linode
• Rackspace Cloud Servers
• etc.
Deployment
Deployment

• Heroku service

• Custom deploy script
Custom “deploy script”


$ git clone <my-project> /var/www/<my-project>
$ nohup bin/server.js &




             Enough to get started
Staying alive
The problem
SyntaxError: Unexpected token ILLEGAL
    at Object.parse (native)
    at Server.<anonymous> (/path/to/my-script.js:4:8)
    at Server.emit (events.js:45:17)
    at HTTPParser.onIncoming (http.js:862:12)
    at HTTPParser.onHeadersComplete (http.js:85:31)
    at Socket.ondata (http.js:787:22)
    at Socket._onReadable (net.js:623:27)
    at IOWatcher.onReadable [as callback] (net.js:156:10)



    Your node process is killed by any runtime error
The wrong solution

process.on('uncaughtException', function(err) {
  console.log('Something bad happened: '+err);
  // continue on ...
});



     Continuing after an exception will leave your
            system in unpredictable state
The right solution

process.on('uncaughtException', function(err) {
  console.log('Something bad happened: '+err);
  // Every process has to die one day, it’s life
  process.exit(0);
});




    Exiting the program will prevent corrupted state
Even better
var Hoptoad = require('hoptoad-notifier').Hoptoad;
Hoptoad.key = 'YOUR_API_KEY';

process.on('uncaughtException', function(err) {
  console.log('Something bad happened: '+err);
  Hoptoad.notify(err, function() {
    process.exit(0);
  });
});

       Send your exception to a logging service.
Your process is dead.

     Now what?
Use a process monitor
          •    Monit *


          •    Upstart


          •    God (ruby)


          •    forever (node.js)

* http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/
Debugging
Debugging tools

• console.log

• node-inspector (use webkit inspector.)

• node debug <script.js> (new in 0.3.x)
Unit tests
 (Real ones, not integration tests)
Load balancing
Load Balancing

• Haproxy

• Amazon Load Balancer

• Nginx (supports only http 1.0)
Our stack
Our stack
                              Ec2 Load Balancer




                             :80            :443
  :80            :443                                  :80            :443

haproxy         stunnel    haproxy         stunnel   haproxy         stunnel

 node           nginx       node            nginx     node           nginx

          php                                                  php
                                     php
Workers

• Use workers a la Unicorn

• All workers listen on a shared socket

• Master process starts & kills workers
Workers

• spark

• fugue

• custom
master.js
var netBinding = process.binding('net');
var spawn = require('child_process').spawn;
var net = require('net');

var serverSocket = netBinding.socket('tcp4');
netBinding.bind(serverSocket, 8080);
netBinding.listen(serverSocket, 128);

for (var i = 0; i < 10; i++) {
  var fds = netBinding.socketpair();
  var child = spawn(process.argv[0], [__dirname+'/worker.js'], {
    customFds: [fds[0], 1, 2]
  });
  var socket = new net.Stream(fds[1], 'unix');
  socket.write('hi', 'utf8', serverSocket);
}
worker.js
var net = require('net');
var http = require('http');
var socket = new net.Socket(0, 'unix');

socket
  .on('fd', function(fd) {
     startServer(fd);
  })
  .resume();

function startServer(fd) {
  http.createServer(function(req, res) {
    res.writeHead(200);
    res.end('Hello from: '+process.pid+'n');
  }).listenFD(fd);
  console.log('Worker ready: '+process.pid);
}
Questions?




✎   @felixge / felix@debuggable.com

Weitere ähnliche Inhalte

Was ist angesagt?

Dirty - How simple is your database?
Dirty - How simple is your database?Dirty - How simple is your database?
Dirty - How simple is your database?Felix Geisendörfer
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)Felix Geisendörfer
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming Tom Croucher
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 

Was ist angesagt? (20)

Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Dirty - How simple is your database?
Dirty - How simple is your database?Dirty - How simple is your database?
Dirty - How simple is your database?
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Node.js
Node.jsNode.js
Node.js
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 

Andere mochten auch

Be Your Own Technology Brand Ambassador
Be Your Own Technology Brand AmbassadorBe Your Own Technology Brand Ambassador
Be Your Own Technology Brand AmbassadorPragati Rai
 
DesignOps Skunk Works - SXSW 2015
DesignOps Skunk Works - SXSW 2015DesignOps Skunk Works - SXSW 2015
DesignOps Skunk Works - SXSW 2015Russ U
 
The changing nature of things: the present and future of connected products.
The changing nature of things: the present and future of connected products.The changing nature of things: the present and future of connected products.
The changing nature of things: the present and future of connected products.Alexandra Deschamps-Sonsino
 
Cosas conectadas, vidas conectadas, negocios que conectan
Cosas conectadas, vidas conectadas, negocios que conectanCosas conectadas, vidas conectadas, negocios que conectan
Cosas conectadas, vidas conectadas, negocios que conectanCarat UK
 
4 Key Challenges in the Shift to Digital Recurring Revenue
4 Key Challenges in the Shift to Digital Recurring Revenue4 Key Challenges in the Shift to Digital Recurring Revenue
4 Key Challenges in the Shift to Digital Recurring RevenueZuora, Inc.
 
Professional involvement
Professional involvementProfessional involvement
Professional involvementBethan Ruddock
 
The Seismic Shift to Recurring Revenue Models & What It Means For Your Company
The Seismic Shift to Recurring Revenue Models & What It Means For Your CompanyThe Seismic Shift to Recurring Revenue Models & What It Means For Your Company
The Seismic Shift to Recurring Revenue Models & What It Means For Your CompanyZuora, Inc.
 
Predictable Revenue. Predictable Risk? Sales Tax & Recurring Revenue
Predictable Revenue. Predictable Risk? Sales Tax & Recurring RevenuePredictable Revenue. Predictable Risk? Sales Tax & Recurring Revenue
Predictable Revenue. Predictable Risk? Sales Tax & Recurring RevenueZuora, Inc.
 
Презентация к проекту "Создание мультфильма"
Презентация к проекту "Создание мультфильма"Презентация к проекту "Создание мультфильма"
Презентация к проекту "Создание мультфильма"kargapoltseva
 
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...Millennium Intézet
 
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövője
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövőjeHorváth Ágnes: Válaszút előtt: A magyar energiamix jövője
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövőjeMillennium Intézet
 
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívája
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívájaDr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívája
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívájaMillennium Intézet
 
Design for the Network - IA Summit, March 2014 - No Notes Version
Design for the Network - IA Summit, March 2014 - No Notes VersionDesign for the Network - IA Summit, March 2014 - No Notes Version
Design for the Network - IA Summit, March 2014 - No Notes VersionMatthew Milan
 
Anti-Patterns that Stifle Lean UX Teams
Anti-Patterns that Stifle Lean UX TeamsAnti-Patterns that Stifle Lean UX Teams
Anti-Patterns that Stifle Lean UX TeamsBill Scott
 
Sociedad de la informacion y el conocimiento
Sociedad de la informacion y el conocimientoSociedad de la informacion y el conocimiento
Sociedad de la informacion y el conocimientocamilo2799
 

Andere mochten auch (20)

Be Your Own Technology Brand Ambassador
Be Your Own Technology Brand AmbassadorBe Your Own Technology Brand Ambassador
Be Your Own Technology Brand Ambassador
 
DesignOps Skunk Works - SXSW 2015
DesignOps Skunk Works - SXSW 2015DesignOps Skunk Works - SXSW 2015
DesignOps Skunk Works - SXSW 2015
 
The changing nature of things: the present and future of connected products.
The changing nature of things: the present and future of connected products.The changing nature of things: the present and future of connected products.
The changing nature of things: the present and future of connected products.
 
Cosas conectadas, vidas conectadas, negocios que conectan
Cosas conectadas, vidas conectadas, negocios que conectanCosas conectadas, vidas conectadas, negocios que conectan
Cosas conectadas, vidas conectadas, negocios que conectan
 
Transformaciones lineales
Transformaciones linealesTransformaciones lineales
Transformaciones lineales
 
Defeitos da visão humana
Defeitos da visão humanaDefeitos da visão humana
Defeitos da visão humana
 
4 Key Challenges in the Shift to Digital Recurring Revenue
4 Key Challenges in the Shift to Digital Recurring Revenue4 Key Challenges in the Shift to Digital Recurring Revenue
4 Key Challenges in the Shift to Digital Recurring Revenue
 
Professional involvement
Professional involvementProfessional involvement
Professional involvement
 
The Seismic Shift to Recurring Revenue Models & What It Means For Your Company
The Seismic Shift to Recurring Revenue Models & What It Means For Your CompanyThe Seismic Shift to Recurring Revenue Models & What It Means For Your Company
The Seismic Shift to Recurring Revenue Models & What It Means For Your Company
 
Owning Your Recruiting
Owning Your RecruitingOwning Your Recruiting
Owning Your Recruiting
 
Predictable Revenue. Predictable Risk? Sales Tax & Recurring Revenue
Predictable Revenue. Predictable Risk? Sales Tax & Recurring RevenuePredictable Revenue. Predictable Risk? Sales Tax & Recurring Revenue
Predictable Revenue. Predictable Risk? Sales Tax & Recurring Revenue
 
Reunió del segon trimestre
Reunió del segon trimestre Reunió del segon trimestre
Reunió del segon trimestre
 
Презентация к проекту "Создание мультфильма"
Презентация к проекту "Создание мультфильма"Презентация к проекту "Создание мультфильма"
Презентация к проекту "Создание мультфильма"
 
Reprodução humana
Reprodução humanaReprodução humana
Reprodução humana
 
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...
Tóth Bertalan: Időzített bombák és eltékozolt lehetőségek az Orbán-kormány en...
 
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövője
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövőjeHorváth Ágnes: Válaszút előtt: A magyar energiamix jövője
Horváth Ágnes: Válaszút előtt: A magyar energiamix jövője
 
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívája
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívájaDr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívája
Dr. Munkácsy Béla: Az energiaforradalomnak nincs alternatívája
 
Design for the Network - IA Summit, March 2014 - No Notes Version
Design for the Network - IA Summit, March 2014 - No Notes VersionDesign for the Network - IA Summit, March 2014 - No Notes Version
Design for the Network - IA Summit, March 2014 - No Notes Version
 
Anti-Patterns that Stifle Lean UX Teams
Anti-Patterns that Stifle Lean UX TeamsAnti-Patterns that Stifle Lean UX Teams
Anti-Patterns that Stifle Lean UX Teams
 
Sociedad de la informacion y el conocimiento
Sociedad de la informacion y el conocimientoSociedad de la informacion y el conocimiento
Sociedad de la informacion y el conocimiento
 

Ähnlich wie Node.js in production

OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialTom Croucher
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2http403
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2Wyatt Fang
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2tianyi5212222
 
Node.js - The New, New Hotness
Node.js - The New, New HotnessNode.js - The New, New Hotness
Node.js - The New, New HotnessDaniel Shaw
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentationasync_io
 
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawBeginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawRedspin, Inc.
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tourq3boy
 
An introduction to node3
An introduction to node3An introduction to node3
An introduction to node3Vivian S. Zhang
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Novaclayton_oneill
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebBhagaban Behera
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 

Ähnlich wie Node.js in production (20)

OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
Node.js - The New, New Hotness
Node.js - The New, New HotnessNode.js - The New, New Hotness
Node.js - The New, New Hotness
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawBeginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tour
 
An introduction to node3
An introduction to node3An introduction to node3
An introduction to node3
 
Ropython-windbg-python-extensions
Ropython-windbg-python-extensionsRopython-windbg-python-extensions
Ropython-windbg-python-extensions
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
Dockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and NovaDockerizing the Hard Services: Neutron and Nova
Dockerizing the Hard Services: Neutron and Nova
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 

Kürzlich hochgeladen

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Kürzlich hochgeladen (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Node.js in production

  • 2. About Contributor Co-founder Felix Geisendörfer node.js driver node-formidable - Joined the mailing list in June 26, 2009 - Co-Transloadit - When I joined there where #24 people - First patch in September 2009 - Now mailing list has > 3400 members
  • 3. File uploading & processing as a service for other web applications. - The app we run in production - Not a “typical” app, no html rendering, only JSON APIs
  • 4. Are you running node in production?
  • 7. ~1 Ye Transloadit v1 a r ag o • Complete failure • Node randomly crashed with: (evcom) recv() Success • A mess of code, hard to maintain * http://transloadit.com/blog/2010/04/to-launch-or-not
  • 10. N Transloadit v2 ow • Processed > 2 TB of data • Not seen a node bug in production yet • Clean code base, 100% test coverage
  • 11. How to get there?
  • 13. Managed / Heroku-style • Joyent (no.de) • Nodejitsu (nodejitsu.com) • Duostack (duostack.com) • Nodefu (nodefu.com) • Heroku (heroku.com)
  • 14. Self-managed • Amazon Ec2 • Linode • Rackspace Cloud Servers • etc.
  • 16. Deployment • Heroku service • Custom deploy script
  • 17. Custom “deploy script” $ git clone <my-project> /var/www/<my-project> $ nohup bin/server.js & Enough to get started
  • 19. The problem SyntaxError: Unexpected token ILLEGAL at Object.parse (native) at Server.<anonymous> (/path/to/my-script.js:4:8) at Server.emit (events.js:45:17) at HTTPParser.onIncoming (http.js:862:12) at HTTPParser.onHeadersComplete (http.js:85:31) at Socket.ondata (http.js:787:22) at Socket._onReadable (net.js:623:27) at IOWatcher.onReadable [as callback] (net.js:156:10) Your node process is killed by any runtime error
  • 20. The wrong solution process.on('uncaughtException', function(err) { console.log('Something bad happened: '+err); // continue on ... }); Continuing after an exception will leave your system in unpredictable state
  • 21. The right solution process.on('uncaughtException', function(err) { console.log('Something bad happened: '+err); // Every process has to die one day, it’s life process.exit(0); }); Exiting the program will prevent corrupted state
  • 22. Even better var Hoptoad = require('hoptoad-notifier').Hoptoad; Hoptoad.key = 'YOUR_API_KEY'; process.on('uncaughtException', function(err) { console.log('Something bad happened: '+err); Hoptoad.notify(err, function() { process.exit(0); }); }); Send your exception to a logging service.
  • 23. Your process is dead. Now what?
  • 24. Use a process monitor • Monit * • Upstart • God (ruby) • forever (node.js) * http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/
  • 26. Debugging tools • console.log • node-inspector (use webkit inspector.) • node debug <script.js> (new in 0.3.x)
  • 27. Unit tests (Real ones, not integration tests)
  • 29. Load Balancing • Haproxy • Amazon Load Balancer • Nginx (supports only http 1.0)
  • 31. Our stack Ec2 Load Balancer :80 :443 :80 :443 :80 :443 haproxy stunnel haproxy stunnel haproxy stunnel node nginx node nginx node nginx php php php
  • 32. Workers • Use workers a la Unicorn • All workers listen on a shared socket • Master process starts & kills workers
  • 34. master.js var netBinding = process.binding('net'); var spawn = require('child_process').spawn; var net = require('net'); var serverSocket = netBinding.socket('tcp4'); netBinding.bind(serverSocket, 8080); netBinding.listen(serverSocket, 128); for (var i = 0; i < 10; i++) { var fds = netBinding.socketpair(); var child = spawn(process.argv[0], [__dirname+'/worker.js'], { customFds: [fds[0], 1, 2] }); var socket = new net.Stream(fds[1], 'unix'); socket.write('hi', 'utf8', serverSocket); }
  • 35. worker.js var net = require('net'); var http = require('http'); var socket = new net.Socket(0, 'unix'); socket .on('fd', function(fd) { startServer(fd); }) .resume(); function startServer(fd) { http.createServer(function(req, res) { res.writeHead(200); res.end('Hello from: '+process.pid+'n'); }).listenFD(fd); console.log('Worker ready: '+process.pid); }
  • 36. Questions? ✎ @felixge / felix@debuggable.com