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