Your SlideShare is downloading. ×
Node js techtalksto
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 techtalksto

1,857

Published on

James Duncan's March 2nd TechTalksTO presentation on NodeJS

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

×