Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Streams are Awesome - (Node.js) TimesOpen Sep 2012

7,224 views

Published on

  • Be the first to comment

Streams are Awesome - (Node.js) TimesOpen Sep 2012

  1. Streams are awesome.@sh1mmer
  2. Tom Hughes-Croucher @sh1mmer
  3. Scalable Server-Side Code with JavaScript Node Up and Running Tom Hughes-Croucher http://ofps.oreilly.com/titles/9781449398583/http://shop.oreilly.com/product/0636920015956.do
  4. Client → ServerServer → DB Computation Computation@sh1mmer
  5. Non event-driven frontend@sh1mmer
  6. @sh1mmer
  7. Server@sh1mmer
  8. Request@sh1mmer
  9. @sh1mmer
  10. Event-driven frontend@sh1mmer
  11. Place- holder@sh1mmer
  12. @sh1mmer
  13. Shared WorkResources@sh1mmer
  14. Memory operations@sh1mmer
  15. var x = "I am a string" ~1ns Running 1 instruction 2ns Data from l1 cpu cache 5ns Data from l2 cpu cache 80ns Data from ram@sh1mmer
  16. @sh1mmer
  17. Mobile data latency@sh1mmer
  18. @sh1mmer
  19. 100 Blue Whales Cat@sh1mmer
  20. Node.js Streams@sh1mmer
  21. Streams• Readable • Pause • Resume • data event• Writable • Write• Pipe
  22. Event Loop Fail node.cc add-ons v8 libuv libev iocp
  23. nextTick Event Loop FailnextTick Run stuff TCP Conn node.cc FS Read add-ons v8 TCP Conn v8 func libuv v8 TCP func Conn libev iocp v8 FS func Read FS Read
  24. stream.pause()@sh1mmer
  25. nextTick Event Loop FailnextTick stream.pause() TCP Conn node.cc FS Read add-ons v8 TCP Conn v8 func libuv v8 TCP func Conn libev iocp v8 FS func Read FS Read
  26. New Streams• Writable • Same (hooray!)• Readable • Configure buffer waterline • readable event • read(len) -> returns data• Pipe • Doesnt mix with direct access
  27. Node.js Domains@sh1mmer
  28. var d = domain.create(); function readSomeFile(filename, cb) { fs.readFile(filename, utf8, d.bind(function(er, data) { // if this throws, it will also be passed to the domain return cb(er, data ? JSON.parse(data) : null); })); } d.on(error, function(er) { // an error occurred somewhere. // if we throw it now, it will crash the program // with the normal line number and stack message. });@sh1mmer
  29. Questions!@sh1mmer

×