What's so special about node.js

2,760 views
2,644 views

Published on

Published in: Technology, Spiritual
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,760
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
46
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

What's so special about node.js

  1. 1. What's so special about Node.js?<br />giancarlo.valente@gmail.com<br />twitter @gncvalente<br />
  2. 2. years of front-end programming evolution<br />now on server-side<br />
  3. 3. javascript<br />
  4. 4. Fundamental videography<br />Ryan Dahl at JS.Conf 2009 <br />show his creature<br />http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html<br />and also this ... http://vimeo.com/9968301<br />
  5. 5. Fundamental videography<br />Douglas Crockford: <br />“Crockford on JavaScript <br />Scene 6: Loopage” August 2010<br />http://www.yuiblog.com/blog/2010/08/30/<br />yui-theater-douglas-crockford-crockford-on-javascript<br />-scene-6-loopage-52-min<br />
  6. 6. node.js is special<br />
  7. 7. What does<br />node.js, nginx, memcached<br /> have in common ?<br />
  8. 8. a C library<br />called<br />libevent<br />
  9. 9. Apache vs Nginx<br />http://blog.webfaction.com/a-little-holiday-present<br />
  10. 10. Apache vs Nginx<br />http://blog.webfaction.com/a-little-holiday-present<br />
  11. 11. apache uses threads<br />nginx uses an event loop<br />
  12. 12. ... it's a different approach<br />on building servers ... <br />with differnt strenghts / weaknesses<br />event loop approach <br />scales better when has to serve <br />many clients <br />with requests that doesn't need <br />so much "data crunching" elaboartion, <br />but a lot of I/O<br />
  13. 13. Ryan's idea! <br />node.js is a thin layer <br />that glue 3 libraries togheter:<br />V8 js engine <br />+<br /> libev (event loop) <br />+ <br />libeio (async I/O)<br />
  14. 14. blocking I/O<br />historically all programming languages<br />have blocking I/O<br />
  15. 15. but, a problem arise:<br />the very expensive "data processing machine" is not used in a very efficient way<br />
  16. 16. multi user systems<br />use of timesharing, <br />in order to make the same computer<br />multiuser<br />
  17. 17. in our modern<br />"server side" code,<br />the same thing appens<br />how do we solve this?<br />simple, we do the same thing. <br />We invented the Threads!<br />
  18. 18. but now the situation is like this<br />Help !!! web real-time, long running sockets ... I've sent the newsletter with 90% discount !!! traffic jam !<br />
  19. 19. has a different approach<br />
  20. 20. event loop approach<br />event loop is used from many years in:<br />games<br />graphical UIs<br />...<br />servers<br />
  21. 21. single thread server<br />c1, c2, c3, c4 ---> S ---> I/O<br />
  22. 22. multi-thread server<br />c1 ---> T1 ---> I/O<br />c2 ---> T2 ---> I/O<br />c3 ---> T3 ---> I/O<br />c4 ---> T4 ---> I/O<br />
  23. 23. thread pool server<br />c9, c5, c1 ---> T1 ---> I/O<br />c10, c6, c2 ---> T2 ---> I/O<br />c11, c7, c3 ---> T3 ---> I/O<br />c12, c8, c4 ---> T4 ---> I/O<br />
  24. 24. event loop<br />c1 ---> ST --> async I/O<br />c2 ---> <br />c3 ---> <br />c4 ---> <br />c5 ---> <br />c6 ---> <br />c7 ---> <br />c8 ---> <br />c9 ---> <br />c10 ---> <br />c11 ---> <br />c12 ---> <br />
  25. 25. so what's the point ...<br />also the browser<br />is <br />mono-thread<br />and works <br />with an<br />event loop<br />
  26. 26. when we write<br />setTimeout('timeout_trigger()', 2000)<br />we're not creating a new thread! (as sometimes I've heard ...)<br />but we're subscribing <br />a new event, <br />which will run our callback, <br />2 seconds from now<br />
  27. 27. so ... why all this hype ?<br />who are the most expert professionals<br />in event driven programming<br />with non blocking I/O ?<br />
  28. 28. the one that do this from years!<br />front-end developers!<br />
  29. 29. accidental evolution<br />of a language<br />(video)<br />http://www.yuiblog.com/blog/2010/08/30/<br />yui-theater-douglas-crockford-crockford-on-javascript<br />-scene-6-loopage-52-min<br />
  30. 30. part 2<br />
  31. 31. Do we all jump on the node.js train?<br />maybe sometimes<br />but it's important to understand what are the strenght of node<br />so we can know how and when to use it.<br />
  32. 32. alternatives ?<br />yes,<br />but we can talk about them<br />next time ... :)<br />
  33. 33. weaknesses<br />monothread (?)<br />(also principal strength point)<br />.. you've to follow the rules<br />non blocking operations,<br />develop in evented style<br />

×