Streams are awesome.@sh1mmer
Tom Hughes-Croucher       @sh1mmer
Scalable Server-Side Code with JavaScript               Node                        Up and Running                        ...
Client → ServerServer → DB                  Computation Computation@sh1mmer
Non event-driven              frontend@sh1mmer
@sh1mmer
Server@sh1mmer
Request@sh1mmer
@sh1mmer
Event-driven frontend@sh1mmer
Place-           holder@sh1mmer
@sh1mmer
Shared  WorkResources@sh1mmer
Memory operations@sh1mmer
var x = "I am a string"           ~1ns Running 1 instruction           2ns Data from l1 cpu cache           5ns Data from ...
@sh1mmer
Mobile data latency@sh1mmer
@sh1mmer
100 Blue Whales                      Cat@sh1mmer
Node.js Streams@sh1mmer
Streams•   Readable    •   Pause    •   Resume    •   data event•   Writable    •   Write•   Pipe
Event Loop Fail          node.cc     add-ons          v8              libuv      libev           iocp
nextTick                       Event Loop FailnextTick                      Run stuff                      TCP            ...
stream.pause()@sh1mmer
nextTick                       Event Loop FailnextTick                       stream.pause()                      TCP      ...
New Streams•   Writable    •   Same (hooray!)•   Readable    •   Configure buffer waterline    •   readable event    •   re...
Node.js Domains@sh1mmer
var d = domain.create();  function readSomeFile(filename, cb) {    fs.readFile(filename, utf8, d.bind(function(er, data) {  ...
Questions!@sh1mmer
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Upcoming SlideShare
Loading in...5
×

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

5,065

Published on

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

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

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Streams are Awesome - (Node.js) TimesOpen Sep 2012

    1. 1. Streams are awesome.@sh1mmer
    2. 2. Tom Hughes-Croucher @sh1mmer
    3. 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. 4. Client → ServerServer → DB Computation Computation@sh1mmer
    5. 5. Non event-driven frontend@sh1mmer
    6. 6. @sh1mmer
    7. 7. Server@sh1mmer
    8. 8. Request@sh1mmer
    9. 9. @sh1mmer
    10. 10. Event-driven frontend@sh1mmer
    11. 11. Place- holder@sh1mmer
    12. 12. @sh1mmer
    13. 13. Shared WorkResources@sh1mmer
    14. 14. Memory operations@sh1mmer
    15. 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. 16. @sh1mmer
    17. 17. Mobile data latency@sh1mmer
    18. 18. @sh1mmer
    19. 19. 100 Blue Whales Cat@sh1mmer
    20. 20. Node.js Streams@sh1mmer
    21. 21. Streams• Readable • Pause • Resume • data event• Writable • Write• Pipe
    22. 22. Event Loop Fail node.cc add-ons v8 libuv libev iocp
    23. 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. 24. stream.pause()@sh1mmer
    25. 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. 26. New Streams• Writable • Same (hooray!)• Readable • Configure buffer waterline • readable event • read(len) -> returns data• Pipe • Doesnt mix with direct access
    27. 27. Node.js Domains@sh1mmer
    28. 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. 29. Questions!@sh1mmer

    ×