Node                        James A. Duncan                        Chief Architect                        james@joyent.com...
James A. Duncan                          Chief Architect @ Joyent                          Spend a lot of my time thinking...
C10KFriday, 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 TBsFriday, March 4, 2011
Intel shipped 3.3 billion CPUs                                           in Q1 2010         1.5ZBs of storage sold in 2010...
Scale Up                           From 1990 to 2010, “RAM” in                        computers increased 1,000,000x in th...
Computer Scientists                              and                        Computer EngineersFriday, March 4, 2011
Friday, March 4, 2011
the node.js project                    To provide a purely evented, non-                  blocking infrastructure to scrip...
Twisted                        POE                        EventMachineFriday, March 4, 2011
Twisted                        POE            = Pain.                        EventMachineFriday, March 4, 2011
a snippet of code          ...          rows = db.select("col,umns FROM aTable WHERE aRow=‘foo’");          do_something( ...
Computers can do                        nothing.                        Very fast.Friday, March 4, 2011
L1: 3 cyclesFriday, March 4, 2011
L2: 14 CyclesFriday, March 4, 2011
RAM: 250 cyclesFriday, March 4, 2011
Disk: 41,000,000 cyclesFriday, March 4, 2011
Network: 240,000,000 cyclesFriday, March 4, 2011
Anything that waits for a                        response from the disk,                        or the network can be     ...
a better snippet of code                        ...                        sql = "col,umns FROM aTable WHERE aRow=‘foo’"; ...
Computer can keep                        doing things very fast.Friday, March 4, 2011
Asynchronous IO.Friday, March 4, 2011
AlternativesFriday, March 4, 2011
Multiple Processes               Threads               Green Threads, CoroutinesFriday, March 4, 2011
Asynchronous IO.                        Not New.Friday, March 4, 2011
Cultural Bias                         puts("Enter your name: ");                         var name = gets();               ...
Infrastructural BiasFriday, March 4, 2011
CallbacksFriday, March 4, 2011
C will never go away.Friday, March 4, 2011
Man PagesFriday, March 4, 2011
Library supportFriday, March 4, 2011
Async File IO                    • BSD:                        • poll/select                    • Linux:                  ...
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 38Friday, March 4, 2011
the node.js project                    • Evented server-side javascript                    • All IO is non-blocking       ...
a pleasing example                        var http = require("http");                        var net = require("net");    ...
speed is obviously important                    • Benchmark:                    • nginx v0.7.65                    • node ...
establish the competition 42Friday, March 4, 2011
Why is nginx so fast?Friday, March 4, 2011
plot node.js results 44Friday, March 4, 2011
what if we change the response size? 45Friday, March 4, 2011
Implementation                        buffer = new Buffer(16*1024);                        for (i = 0; i < buffer.length; ...
JavaScript is only a little                        bit slower than lovingly                        hand-crafted optimized ...
JavaScript is only a little                        bit slower than lovingly                        hand-crafted optimized ...
How is this true?Friday, March 4, 2011
Friday, March 4, 2011
ECMAScriptFriday, March 4, 2011
Friday, March 4, 2011
Friday, March 4, 2011
Speedy 54Friday, March 4, 2011
Friday, March 4, 2011
Friday, March 4, 2011
Dogfood.Friday, March 4, 2011
Friday, March 4, 2011
LibrariesFriday, March 4, 2011
Web Framework - Express                var express = require(express);                var app = express.createServer();   ...
Connect MiddlewareFriday, March 4, 2011
DatabasesFriday, March 4, 2011
Multi-processFriday, March 4, 2011
npmFriday, March 4, 2011
Demo AppFriday, March 4, 2011
Conclusions                        &                        Thanks for Listening!Friday, March 4, 2011
Upcoming SlideShare
Loading in …5
×

Node js techtalksto

1,974
-1

Published on

James Duncan's March 2nd TechTalksTO presentation on NodeJS

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

  • Be the first to like this

No Downloads
Views
Total Views
1,974
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Node js techtalksto

  1. 1. Node James A. Duncan Chief Architect james@joyent.comFriday, March 4, 2011
  2. 2. 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. 2Friday, March 4, 2011
  3. 3. C10KFriday, March 4, 2011
  4. 4. Friday, March 4, 2011
  5. 5. Friday, March 4, 2011
  6. 6. Between 70-100 microprocessors in a car!Friday, March 4, 2011
  7. 7. 1 flight, 1 plane, 480 TBsFriday, March 4, 2011
  8. 8. Intel shipped 3.3 billion CPUs in Q1 2010 1.5ZBs of storage sold in 2010Friday, March 4, 2011
  9. 9. Scale Up From 1990 to 2010, “RAM” in computers increased 1,000,000x in the same power footprintFriday, March 4, 2011
  10. 10. Computer Scientists and Computer EngineersFriday, March 4, 2011
  11. 11. Friday, March 4, 2011
  12. 12. the node.js project To provide a purely evented, non- blocking infrastructure to script highly concurrent programs. 12Friday, March 4, 2011
  13. 13. Twisted POE EventMachineFriday, March 4, 2011
  14. 14. Twisted POE = Pain. EventMachineFriday, March 4, 2011
  15. 15. a snippet of code ... rows = db.select("col,umns FROM aTable WHERE aRow=‘foo’"); do_something( rows ); ... 15Friday, March 4, 2011
  16. 16. Computers can do nothing. Very fast.Friday, March 4, 2011
  17. 17. L1: 3 cyclesFriday, March 4, 2011
  18. 18. L2: 14 CyclesFriday, March 4, 2011
  19. 19. RAM: 250 cyclesFriday, March 4, 2011
  20. 20. Disk: 41,000,000 cyclesFriday, March 4, 2011
  21. 21. Network: 240,000,000 cyclesFriday, March 4, 2011
  22. 22. Anything that waits for a response from the disk, or the network can be considered “blocking” IOFriday, March 4, 2011
  23. 23. a better snippet of code ... sql = "col,umns FROM aTable WHERE aRow=‘foo’"; db.select(sql, do_something); ... 23Friday, March 4, 2011
  24. 24. Computer can keep doing things very fast.Friday, March 4, 2011
  25. 25. Asynchronous IO.Friday, March 4, 2011
  26. 26. AlternativesFriday, March 4, 2011
  27. 27. Multiple Processes Threads Green Threads, CoroutinesFriday, March 4, 2011
  28. 28. Asynchronous IO. Not New.Friday, March 4, 2011
  29. 29. Cultural Bias puts("Enter your name: "); var name = gets(); puts("Name: " + name)Friday, March 4, 2011
  30. 30. Infrastructural BiasFriday, March 4, 2011
  31. 31. CallbacksFriday, March 4, 2011
  32. 32. C will never go away.Friday, March 4, 2011
  33. 33. Man PagesFriday, March 4, 2011
  34. 34. Library supportFriday, March 4, 2011
  35. 35. Async File IO • BSD: • poll/select • Linux: • epoll • FreeBSD • kqueue • Solaris • /dev/poll • libevent, libev 35Friday, March 4, 2011
  36. 36. C will never go away.Friday, March 4, 2011
  37. 37. C will never go away. Nor will JavaScript.Friday, March 4, 2011
  38. 38. JavaScript is a cultural fit 38Friday, March 4, 2011
  39. 39. 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) 39Friday, March 4, 2011
  40. 40. 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); 40Friday, March 4, 2011
  41. 41. 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 41Friday, March 4, 2011
  42. 42. establish the competition 42Friday, March 4, 2011
  43. 43. Why is nginx so fast?Friday, March 4, 2011
  44. 44. plot node.js results 44Friday, March 4, 2011
  45. 45. what if we change the response size? 45Friday, March 4, 2011
  46. 46. 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); }); 46Friday, March 4, 2011
  47. 47. JavaScript is only a little bit slower than lovingly hand-crafted optimized C.Friday, March 4, 2011
  48. 48. JavaScript is only a little bit slower than lovingly hand-crafted optimized C. Wow.Friday, March 4, 2011
  49. 49. How is this true?Friday, March 4, 2011
  50. 50. Friday, March 4, 2011
  51. 51. ECMAScriptFriday, March 4, 2011
  52. 52. Friday, March 4, 2011
  53. 53. Friday, March 4, 2011
  54. 54. Speedy 54Friday, March 4, 2011
  55. 55. Friday, March 4, 2011
  56. 56. Friday, March 4, 2011
  57. 57. Dogfood.Friday, March 4, 2011
  58. 58. Friday, March 4, 2011
  59. 59. LibrariesFriday, March 4, 2011
  60. 60. 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); 60Friday, March 4, 2011
  61. 61. Connect MiddlewareFriday, March 4, 2011
  62. 62. DatabasesFriday, March 4, 2011
  63. 63. Multi-processFriday, March 4, 2011
  64. 64. npmFriday, March 4, 2011
  65. 65. Demo AppFriday, March 4, 2011
  66. 66. Conclusions & Thanks for Listening!Friday, March 4, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×