SlideShare una empresa de Scribd logo
1 de 66
Descargar para leer sin conexión
Node



                        James A. Duncan
                        Chief Architect

                        james@joyent.com




Friday, March 4, 2011
James A. Duncan

                          Chief Architect @ Joyent

                          Spend a lot of my time thinking about
                          how things should join together and
                          why they shouldnʼt.

                          Grew up in Hawkesbury, Ontario

                          Live in the mountains to the north of
                          Montreal in Quebec, Canada.

                          Formerly lived in London & was a CIO
                          of a subsidiary of Canon Europe.

                          Open Source guy for 15 years.

                          Gardener, skier, and technologist.




   2

Friday, March 4, 2011
C10K




Friday, March 4, 2011
Friday, March 4, 2011
Friday, March 4, 2011
Between 70-100
                        microprocessors
                            in a car!




Friday, March 4, 2011
1 flight, 1 plane, 480 TBs




Friday, March 4, 2011
Intel shipped 3.3 billion CPUs
                                           in Q1 2010


         1.5ZBs of storage sold in 2010



Friday, March 4, 2011
Scale Up



                           From 1990 to 2010, “RAM” in
                        computers increased 1,000,000x in the
                               same power footprint



Friday, March 4, 2011
Computer Scientists
                              and
                        Computer Engineers


Friday, March 4, 2011
Friday, March 4, 2011
the node.js project




                    To provide a purely evented, non-
                  blocking infrastructure to script highly
                          concurrent programs.




 12

Friday, March 4, 2011
Twisted
                        POE
                        EventMachine



Friday, March 4, 2011
Twisted
                        POE            = Pain.
                        EventMachine



Friday, March 4, 2011
a snippet of code




          ...
          rows = db.select("col,umns FROM aTable WHERE aRow=‘foo’");
          do_something( rows );
          ...




 15

Friday, March 4, 2011
Computers can do
                        nothing.
                        Very fast.



Friday, March 4, 2011
L1: 3 cycles




Friday, March 4, 2011
L2: 14 Cycles




Friday, March 4, 2011
RAM: 250 cycles




Friday, March 4, 2011
Disk: 41,000,000 cycles




Friday, March 4, 2011
Network: 240,000,000 cycles




Friday, March 4, 2011
Anything that waits for a
                        response from the disk,
                        or the network can be
                        considered “blocking”
                        IO

Friday, March 4, 2011
a better snippet of code




                        ...
                        sql = "col,umns FROM aTable WHERE aRow=‘foo’";
                        db.select(sql, do_something);
                        ...




 23

Friday, March 4, 2011
Computer can keep
                        doing things very fast.




Friday, March 4, 2011
Asynchronous IO.




Friday, March 4, 2011
Alternatives




Friday, March 4, 2011
Multiple Processes
               Threads
               Green Threads, Coroutines



Friday, March 4, 2011
Asynchronous IO.
                        Not New.




Friday, March 4, 2011
Cultural Bias
                         puts("Enter your name: ");
                         var name = gets();
                         puts("Name: " + name)



Friday, March 4, 2011
Infrastructural Bias




Friday, March 4, 2011
Callbacks




Friday, March 4, 2011
C will never go away.




Friday, March 4, 2011
Man Pages




Friday, March 4, 2011
Library support




Friday, March 4, 2011
Async File IO

                    • BSD:
                        • poll/select
                    • Linux:
                        • epoll
                    • FreeBSD
                        • kqueue
                    • Solaris
                        • /dev/poll
                    • libevent, libev

 35

Friday, March 4, 2011
C will never go away.




Friday, March 4, 2011
C will never go away.
                        Nor will JavaScript.




Friday, March 4, 2011
JavaScript is a cultural fit




 38

Friday, March 4, 2011
the node.js project

                    • Evented server-side javascript
                    • All IO is non-blocking
                    • Good at handling lots of different IO at the same time
                    • Achieves this by making all IO non-blocking


                    • Primary author, and benevolent dictator for life is Ryan Dahl
                    • Owned by us (Joyent), but MIT/BSD licensed
                    • seems to be pretty popular, which is making us happy
                    • running our http://no.de service - lets you get started using node quickly
                    • running on HPʼs webOS as the underlying service mechanism (replaced Java)


 39

Friday, March 4, 2011
a pleasing example

                        var http = require("http");
                        var net = require("net");
                        var c = 0;

                        http.createServer( function( req, res ) {
                          c++;
                          res.writeHead(200);
                          res.end("Hello World");
                        }).listen(8000);

                        net.createServer( function( socket ) {
                          socket.write("connections: " + c);
                          socket.end();
                        }).listen(8001);


 40

Friday, March 4, 2011
speed is obviously important

                    • Benchmark:
                    • nginx v0.7.65
                    • node v0.1.91
                    • tornado v0.2 (python 2.6.4)
                    • thin v1.2.7 (ruby 1.9.1-p376)


                    • Linux 2.53, using Intel Core 2 Duo & 4GB RAM
                    • Standard hello world, with a 100 byte response




 41

Friday, March 4, 2011
establish the competition




 42

Friday, March 4, 2011
Why is nginx so fast?




Friday, March 4, 2011
plot node.js results




 44

Friday, March 4, 2011
what if we change the response size?




 45

Friday, March 4, 2011
Implementation



                        buffer = new Buffer(16*1024);
                        for (i = 0; i < buffer.length; i++) {
                          buffer[i] = 100;
                        }

                        http.createServer(function(req, res){
                          res.writeHead(200);
                          res.end(buffer);
                        });


 46

Friday, March 4, 2011
JavaScript is only a little
                        bit slower than lovingly
                        hand-crafted optimized
                        C.


Friday, March 4, 2011
JavaScript is only a little
                        bit slower than lovingly
                        hand-crafted optimized
                        C. Wow.


Friday, March 4, 2011
How is this true?




Friday, March 4, 2011
Friday, March 4, 2011
ECMAScript




Friday, March 4, 2011
Friday, March 4, 2011
Friday, March 4, 2011
Speedy




 54

Friday, March 4, 2011
Friday, March 4, 2011
Friday, March 4, 2011
Dogfood.




Friday, March 4, 2011
Friday, March 4, 2011
Libraries




Friday, March 4, 2011
Web Framework - Express


                var express = require('express');
                var app = express.createServer();

                app.get("/", function(req, res, next) {
                  res.send("Hello from the URL " + req.url);
                });

                app.get(“/:name”, function(req, res, next) {
                  res.send(“Hello “ + req.params.name);
                });
                app.listen(3000);

 60

Friday, March 4, 2011
Connect Middleware




Friday, March 4, 2011
Databases




Friday, March 4, 2011
Multi-process




Friday, March 4, 2011
npm




Friday, March 4, 2011
Demo App




Friday, March 4, 2011
Conclusions
                        &
                        Thanks for Listening!



Friday, March 4, 2011

Más contenido relacionado

Similar a Chief Architect James Duncan Discusses Node.js Architecture and Performance

Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisJonathan Wage
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Bachkoutou Toutou
 
HTML XHTML HTML5
HTML XHTML HTML5HTML XHTML HTML5
HTML XHTML HTML5timstone
 
Atlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide DeckAtlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide DeckAtlassian
 
HTML5 and jQuery for Flex Developers
HTML5 and jQuery for Flex DevelopersHTML5 and jQuery for Flex Developers
HTML5 and jQuery for Flex DevelopersRyan Stewart
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the LazyMaurício Linhares
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability PatternsRobert Treat
 
Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010Ted Dunning
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywoodehuard
 

Similar a Chief Architect James Duncan Discusses Node.js Architecture and Performance (20)

What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0
 
Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 Paris
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011
 
Beyond Page Objects
Beyond Page ObjectsBeyond Page Objects
Beyond Page Objects
 
HTML XHTML HTML5
HTML XHTML HTML5HTML XHTML HTML5
HTML XHTML HTML5
 
Tim stone.html5.rjug.20110316
Tim stone.html5.rjug.20110316Tim stone.html5.rjug.20110316
Tim stone.html5.rjug.20110316
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
Atlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide DeckAtlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide Deck
 
RunDeck
RunDeckRunDeck
RunDeck
 
HTML5 and jQuery for Flex Developers
HTML5 and jQuery for Flex DevelopersHTML5 and jQuery for Flex Developers
HTML5 and jQuery for Flex Developers
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the Lazy
 
Geolinkeddata 07042011 1
Geolinkeddata 07042011 1Geolinkeddata 07042011 1
Geolinkeddata 07042011 1
 
GeoLinkedData
GeoLinkedDataGeoLinkedData
GeoLinkedData
 
Web heresies
Web heresiesWeb heresies
Web heresies
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability Patterns
 
Mahout classifier tour
Mahout classifier tourMahout classifier tour
Mahout classifier tour
 
SD Forum 11 04-2010
SD Forum 11 04-2010SD Forum 11 04-2010
SD Forum 11 04-2010
 
Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010
 
Notebook
NotebookNotebook
Notebook
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 

Chief Architect James Duncan Discusses Node.js Architecture and Performance