2. What's next
When / why did it start
Extremely boring theory
What to do aka common use cases
Differences from client side javascript
App example: a RESTful ninja managament tools
with real time notifications
4. Enter node js
In 200* Ryan Dahl saw a polling progress bar
He wanted a super easy way to implement sites with push
capabilities
In 2009 node.js was born
Joyent takes control
8. Blocking I/O analogy (2)
The cashier waits for your food
to be cooked before doing
anything else (he’s blocked)
The cashier is not able to help the
next person until you got your
food and went your way
10. Non-blocking I/O analogy
As soon as you place your order, it’s sent off for someone to fulfill
while the cashier is still taking your payment.
When you are done paying, you have to step aside because the
cashier is already looking to service the next customer.
When your food is set, the cashier – or someone – will signal you by
calling out your name, (callback)
11. Non-blocking I/O (2)
You use your web browser to make a request for “/about.html” on
a Node.js web server.
The Node server accepts your request and calls a function to
retrieve that file from disk.
While the Node server is waiting for the file to be retrieved, it
services the next web request.
When the file is retrieved, there is a callback function that is
inserted in the Node servers queue.
The Node server executes that function which in this case would
render the “/about.html” page and send it back to your web browser.
12. So:
Every I/O operation is non blocking
Your code is single threaded
Everything runs in parallel except your code
14. Event loop
A JavaScript runtime contains an event queue, which is a list of
tasks to be processed
Each message event is bound to a callback function
The said runtime loops on the queue, executing all the event callbacks
19. What not to do
everything that is CPU intensive
image/video processing
heavyweight number crunching
compressing files
everything involving complex algorithms
Event loops are highly specialized and not general purpose
23. What to do - Real time web
apps
It was born for this
Lots of stable mature frameworks (again) - primus, socket I/O ecc
It ca ben integrated into an existing web stack
http://webandphp.com/IntegratingNode.jswithPHP