Your SlideShare is downloading. ×
0
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Node.js
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Node.js

279

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
279
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Danilo Sousadsgoncalves@sp.r7.comNode.js
  • 2. Introduction"Nodes goal is to provide an easy way to buildscalable network programs."Ryan Dahl●Server-side Javascript●Built on Google’s V8●CommonJS module system●Evented, non-blocking I/O. Similar to EventMachine orTwisted.
  • 3. I/O needs to be donedifferently.
  • 4. I/O Costs●L1: 3 cycles●L2: 14 cycles●RAM: 250 cycles●DISK: 41,000,000 cycles●NETWORK: 240,000,000 cycleshttp://nodejs.org/jsconf.pdf
  • 5. Traditional wayvar 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 );
  • 6. I/O Costs●L1: 3 cycles●L2: 14 cycles●RAM: 250 cycles●DISK: 41,000,000 cycles●NETWORK: 240,000,000 cycleshttp://nodejs.org/jsconf.pdf
  • 7. Nodes first attemptvar db = require(db);db.query( SELECT id, name FROM table, function(row){db.query(SELECT .... WHERE id = +row.id, function(row2){// do your stuff hereconsole.log( row2.name );});});
  • 8. 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 );});
  • 9. speed
  • 10. speedvar 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
  • 11. speed100 concurrent clients1 megabyte responsereq/secnode ~800nginx ~700thin 85mongrel 4(bigger is better)by Ryan Dahl
  • 12. Questions?

×