node.js
DESCRIPTION
TRANSCRIPT
![Page 2: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/2.jpg)
Introduction
"Node's goal is to provide an easy way to build scalable network programs."
Ryan Dahl
● Server-side Javascript
● Built on Google’s V8
● CommonJS module system
● Evented, non-blocking I/O. Similar to EventMachine or Twisted.
![Page 3: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/3.jpg)
I/O needs to be done differently.
![Page 4: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/4.jpg)
I/O Costs
●L1: 3 cycles
●L2: 14 cycles
●RAM: 250 cycles
●DISK: 41,000,000 cycles
●NETWORK: 240,000,000 cycles
http://nodejs.org/jsconf.pdf
![Page 5: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/5.jpg)
Traditional way
var db = require('db');
row = db.query(' SELECT id, name FROM aaa');
row2 = db.query('SELECT id, name WHERE id = '+row.id );
// do your stuff hereconsole.log( row2.name );
![Page 6: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/6.jpg)
I/O Costs
●L1: 3 cycles
●L2: 14 cycles
●RAM: 250 cycles
●DISK: 41,000,000 cycles
●NETWORK: 240,000,000 cycles
http://nodejs.org/jsconf.pdf
![Page 7: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/7.jpg)
Node's first attempt
var db = require('db');
db.query(' SELECT id, name FROM table', function(row){ db.query('SELECT .... WHERE id = '+row.id, function(row2){
// do your stuff here console.log( row2.name ); });});
![Page 8: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/8.jpg)
Better wayvar db = require('db');
frunction get(cb){ db.query('SELECT id, name FROM table', row1);}
function row1(row, cb){ db.query('SELECT .... WHERE id = '+ row.id, function(row){ cb( row ); });}
get(function(row){ console.log( row.name );});
![Page 9: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/9.jpg)
speed
![Page 10: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/10.jpg)
speed
var http = require(’http’);var b = new Buffer(1024*1024);
http.createServer(function(req, res){ res.writeHead(200); res.end(b);}).listen(8000);
by Ryan Dahl
![Page 11: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/11.jpg)
speed
100 concurrent clients1 megabyte response
req/sec
node ~800nginx ~700
thin 85mongrel 4
(bigger is better)by Ryan Dahl
![Page 12: Node.js](https://reader035.vdocuments.net/reader035/viewer/2022081807/54b794de4a79596b578b456c/html5/thumbnails/12.jpg)
Questions?