Nodejs - A quick tour (v4)
Upcoming SlideShare
Loading in...5
×
 

Nodejs - A quick tour (v4)

on

  • 13,263 views

Talk given at the Atlanta JS Meetup (@ATLJavaScript) on Feb 15, 2011.

Talk given at the Atlanta JS Meetup (@ATLJavaScript) on Feb 15, 2011.

Statistics

Views

Total Views
13,263
Views on SlideShare
5,508
Embed Views
7,755

Actions

Likes
6
Downloads
64
Comments
0

26 Embeds 7,755

http://debuggable.com 6169
http://feeds.feedburner.com 856
http://www.debuggable.com 535
http://www.scoop.it 82
http://nodeio.wordpress.com 21
http://theoldreader.com 20
http://us-w1.rockmelt.com 17
http://localhost 14
http://www.expressdifferent.com 7
http://paper.li 5
http://www.cloudtask.com 4
http://fr.deeb.hu 4
http://xss.yandex.net 3
http://xianguo.com 3
http://translate.googleusercontent.com 3
http://feedreader.com 2
http://feeds2.feedburner.com 1
http://ajlopez.wordpress.com 1
http://www.emailmeapp.de 1
http://static.slidesharecdn.com 1
http://rfgrandsconcerts 1
http://dark-code.com 1
http://git.debuggable.com 1
http://workshops.debuggable.com 1
http://blog.debuggable.com 1
http://feedproxy.google.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Nodejs - A quick tour (v4) Nodejs - A quick tour (v4) Presentation Transcript

  • node.js A quick tour 15.02.2011 (v4)
  • About • Felix Geisendörfer • 23 years • Berlin, Germany@felixge
  • Core Contributor & Module Authornode-mysql node-formidable
  • File uploading & processing as an infrastructure service for web & mobile applications.
  • Audience?
  • Nodes goal is to provide an easy way to build scalable network programs.
  • Node.js• Created by Ryan Dahl• Google’s V8 JavaScript engine (no DOM)• Module system, I/O bindings, Common Protocols
  • Installing$ git clone git://github.com/ry/node.git$ cd node$ ./configure$ make install
  • Hello World$ cat test.jsconsole.log(Hello World);$ node test.jsHello World
  • Ingredients libeio libevc-ares V8 http_parser
  • Philosophy• Just enough core-library to do I/O• Non-blocking• Close to the underlaying system calls
  • Non-blocking I/O
  • Blocking I/Ovar a = db.query(SELECT A);console.log(result a:, a);var b = db.query(SELECT B);console.log(result b:, b); Time = SUM(A, B)
  • Non-Blocking I/Odb.query(SELECT A, function(result) { console.log(result a:, result);});db.query(SELECT B, function(result) { console.log(result b:, result);}); Time = MAX(A, B)
  • Non-Blocking I/O• Offload most things to the kernel and poll for changes (select, epoll, kqueue, etc.)• Thread pool for anything else
  • Single Threadedvar a = [];function f() { a.push(1); a.push(2);}setTimeout(f, 10);setTimeout(f, 10);
  • Single Threadedvar a = [];function f() { • [1, 1, 2, 2] ? a.push(1); a.push(2);} • [1, 2, 1, 2] ?setTimeout(f, 10); • BAD ACCESS ?setTimeout(f, 10);
  • Single Threadedvar a = [];function f() { • [1, 1, 2, 2] a.push(1); a.push(2);} • [1, 2, 1, 2]setTimeout(f, 10); • BAD ACCESSsetTimeout(f, 10);
  • API Overview
  • CommonJS Modules$ cat hello.jsexports.world = function() { return Hello World;};$ cat main.jsvar hello = require(./hello);console.log(hello.world());$ node main.jsHello World
  • Child processes$ cat child.jsvar spawn = require(child_process).spawn;var cmd = echo hello; sleep 1; echo world;;var child = spawn(sh, [-c, cmd]);child.stdout.on(data, function(chunk) { console.log(chunk.toString());});$ node child.js"hellon"# 1 sec delay"worldnn"
  • Http Server$ cat http.jsvar http = require(http);http.createServer(function(req, res) { setTimeout(function() { res.writeHead(200); res.end(Thanks for waiting!); }, 1000);}).listen(4000);$ curl localhost:4000# 1 sec delayThanks for waiting!
  • Tcp Server$ cat tcp.jsvar tcp = require(tcp);tcp.createServer(function(socket) { socket .on(connect, function() { socket.write("Hi, How Are You?n> "); }) .on(data, function(data) { socket.write(data); });}).listen(4000);$ nc localhost 4000Hi, How Are You?> Great!Great!
  • DNS$ cat dns.jsvar dns = require(dns);dns.resolve(nodejs.org, function(err, addresses) { console.log(addresses);});$ node dns.js[ 8.12.44.238 ]
  • Watch File$ cat watch.jsvar fs = require(fs);fs.watchFile(__filename, function() { console.log(You changed me!); process.exit(0);});$ node watch.js# edit watch.jsYou changed me!
  • And much more• UDP • Buffer• Crypto • Script• Assert • EcmaScript5 ...
  • Suitable Applications
  • Suitable Applications• Singe-page apps• Real time• Crawlers
  • More Applications• Async chaining of unix tools• Streaming• File uploading
  • Interesting projects
  • Package management
  • Web Frameworks• Express.js (Sinatra clone)• Fab.js (Mind-bending & awesome)
  • DOM• node-htmlparser• jquery• node.io
  • WebSockets Socket.IO
  • 1171 modules in npm
  • Ready for production?
  • Ready for production?• 0.4 was released last week• API has settled down for most parts• Very few bugs, but YMMV
  • Things that suck
  • Things that suck• Stack traces are lost at the event loop boundary• Utilizing multiple cores requires multiple processes• V8: 1.9 GB heap limit / GC can be problematic
  • Community
  • Benevolent Dictator For Life Ryan Dahl
  • Community• Mailing list (nodejs, nodejs-dev)• IRC (#node.js)
  • Hosting
  • Questions?✎ @felixge / felix@debuggable.com
  • Bonus Slides
  • Speed
  • 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
  • Speed100 concurrent clients1 megabyte responsenode 822 req/secnginx 708thin 85mongrel 4(bigger is better) by Ryan Dahl
  • Speed• NGINX peaked at 4mb of memory• Node peaked at 60mb• Very special circumstances by Ryan Dahl
  • Questions?✎ @felixge / felix@debuggable.com