33
What's so special about Node.js? [email protected] twitter @gncvalente

What's so special about node.js

Embed Size (px)

Citation preview

Page 1: What's so special about node.js

What's so special about Node.js?

[email protected] @gncvalente

Page 2: What's so special about node.js

years of front-end programming evolution

now on server-side

Page 3: What's so special about node.js

javascript

Page 4: What's so special about node.js

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

Page 5: What's so special about node.js

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

Page 6: What's so special about node.js

node.js is special

Page 7: What's so special about node.js

What does

node.js, nginx, memcached

have in common ?

Page 8: What's so special about node.js

a C librarycalledlibevent

Page 9: What's so special about node.js

Apache vs Nginx

http://blog.webfaction.com/a-little-holiday-present

Page 10: What's so special about node.js

Apache vs Nginx

http://blog.webfaction.com/a-little-holiday-present

Page 11: What's so special about node.js

apache uses threads

nginx uses an event loop

Page 12: What's so special about node.js

... 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

Page 13: What's so special about node.js

Ryan's idea! node.js is a thin layer

that glue 3 libraries togheter:

V8 js engine +

libev (event loop) +

libeio (async I/O)

Page 14: What's so special about node.js

blocking I/O

historically all programming languageshave blocking I/O

Page 15: What's so special about node.js

but, a problem arise:the very expensive "data processing machine" is not used in a very efficient

way

Page 16: What's so special about node.js

multi user systems

use of timesharing, in order to make the same computer

multiuser

Page 17: What's so special about node.js

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!

Page 18: What's so special about node.js

but now the situation is like this

Help !!! web real-time, long running sockets ... I've sent the newsletter with 90% discount !!! traffic jam !

Page 19: What's so special about node.js

has a different approach

Page 20: What's so special about node.js

event loop approach

event loop is used from many years in:

gamesgraphical UIs

...servers

Page 21: What's so special about node.js

single thread server

c1, c2, c3, c4 ---> S ---> I/O

Page 22: What's so special about node.js

multi-thread server

c1 ---> T1 ---> I/Oc2 ---> T2 ---> I/Oc3 ---> T3 ---> I/Oc4 ---> T4 ---> I/O

Page 23: What's so special about node.js

thread pool server

c9, c5, c1 ---> T1 ---> I/Oc10, c6, c2 ---> T2 ---> I/Oc11, c7, c3 ---> T3 ---> I/Oc12, c8, c4 ---> T4 ---> I/O

Page 24: What's so special about node.js

event loop

c1 ---> ST --> async I/Oc2 ---> c3 ---> c4 ---> c5 ---> c6 ---> c7 ---> c8 ---> c9 ---> c10 ---> c11 ---> c12 --->

Page 25: What's so special about node.js

so what's the point ...

also the browseris

mono-threadand works with an

event loop

Page 26: What's so special about node.js

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

Page 27: What's so special about node.js

so ... why all this hype ?

who are the most expert professionals

in event driven programming

with non blocking I/O ?

Page 28: What's so special about node.js

the one that do this from years!

front-end developers!

Page 29: What's so special about node.js

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

Page 30: What's so special about node.js

part 2

Page 31: What's so special about node.js

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.

Page 32: What's so special about node.js

alternatives ?

yes,

but we can talk about themnext time ... :)

Page 33: What's so special about node.js

weaknesses

monothread (?)(also principal strength point)

.. you've to follow the rules

non blocking operations,develop in evented style