Slide 1

Slide 1 text

Got milk?

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

milk = dear_son.please_buy_a_milk();

Slide 4

Slide 4 text

milk = dear_son.please_buy_a_milk();

Slide 5

Slide 5 text

milk = dear_son.please_buy_a_milk(); dear_son.thank_you(); milk.drink();

Slide 6

Slide 6 text

milk = dear_son.please_buy_a_milk(); dear_son.thank_you(); milk.drink(); Blocking operations

Slide 7

Slide 7 text

milk = dear_son.please_buy_a_milk();

Slide 8

Slide 8 text

milk = dear_son.please_buy_a_milk(); do_cleanup(); do_something_else();

Slide 9

Slide 9 text

milk = dear_son.please_buy_a_milk(); do_cleanup(); do_something_else(); /* ? dear_son.here_is_your_milk(); */ Non-Blocking operations

Slide 10

Slide 10 text

Event-Loop

Slide 11

Slide 11 text

milk = dear_son.please_buy_a_milk(); /* Event loop starts - while(…) */ if( dear_son.milk_ready() ) break; do_some_cleanup(); /* Event loop ends */ Event-Loop

Slide 12

Slide 12 text

In terms of: 1. OS ( process, threads scheduling) 2. Application ( event-loops, overlapped system calls, callbacks )

Slide 13

Slide 13 text

OS can handle it. So why should I know about event-loops and other sh!t?!

Slide 14

Slide 14 text

That’s why

Slide 15

Slide 15 text

Introducing Node.Js! Event-driven I/O server-side JavaScript framework based on V8

Slide 16

Slide 16 text

Why Javascript? 1. It’s awesome 2. It’s simple 3. It’s popular 4. V8 is really fast 5. Built-in support for callbacks, lambdas, closures and other magic

Slide 17

Slide 17 text

setTimeout(function() { console.log('Hello, '); }, 1000); console.log(' World!'); Dummy example #1

Slide 18

Slide 18 text

Dummy example #2 var http = require(‘http’); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': ‘text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at port 1337');

Slide 19

Slide 19 text

Web-Server | CGI | php, perl, python, etc.

Slide 20

Slide 20 text

Node.Js (all-in-one: web-server, caching, parsing, templating, data-storing, doing-a-sandwich)

Slide 21

Slide 21 text

Features 1. Clustering 2. Packages: web-frameworks, DB, graphics, BNF parsers, unit- testing, … + package manager 3. Cloud 9 IDE (runs in browser)

Slide 22

Slide 22 text

Problems Asynchronous logic hell!

Slide 23

Slide 23 text

Problems Asynchronous logic hell! 1. Using helper modules (deferred, async, node-fibers) 2. Program is Finite State Machine

Slide 24

Slide 24 text

The main problem Node.Js is very young, so be careful! Use it just-for-fun!

Slide 25

Slide 25 text

Resources 1. “UNIX internals” by U.Vahalia 2. “Thinking Asynchronous in C++” by author of boost::asio http://blog.think-async.com/ 3. Online npm repository http://search.npm.js 4. Cloud 9 IDE http://c9.io

Slide 26

Slide 26 text

Have a nice milk! Speaker: Taktarov A. Drawings: Taktarov E. molefrog[at]gmail.com