Async I/O & Node.js

llamas

Felix & pfleidi

We like:

Be prepared!

internet

Webserver

wellwell

Single Threaded Process

  
  sock := listen(8080)
  while True:
    request := sock.accept()
    file := parse(request)
    data := open(file).read()
    request.send(data)
  
  

Does it scale?

scale

No Dave, I'm afraid I can't do that!

sadkeanu

Worker Processes

apache

Apache mpm-prefork

Benchmark

benchmark

Meh ...

facepalm

Worker Threads

threads

Apache mpm-worker

Benchmark

benchmark

Better, but still ...

wellfuck

Async I/O

nginx

NginX

Benchmark

benchmark

Squeee ...

dinosaur
nodejslogo

JavaScript SRSLY?

srsly

Skeptical?

skeptical

JavaScript Goodies

Still not convinced?

disapprove

John Resig is a Ninja!

ejohn

Douglas Crockford is Chuck Norris!

crockford

Yo dawg! I herd you like events ...

dawg

... so we put an event loop in ur JS

dawg

Combined Awesomeness!

r2d2

Usage of Node.js

Maybe even serious applications

seriouscat

What does it look like?

stoner dog

Sync

  
  var data = fs.readFileSync(
    filePath, "binary"
  ); //blocking
  doSomethingGreat(data);
  
  

Async + Callback

  
  fs.readFile(filePath, "binary", 
    function(err,data){ //non-blocking
      if (err) throw err;
      doSomethingGreat(data);
    }
  );
  doMoreAwesomeness();
  
  

HTTP "Hello World"

  
  var http = require('http');

  http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
     res.end('Hello World\n');
  }).listen(8124, "127.0.0.1");

  console.log('Server running at http://127.0.0.1:8124/');
  
  

Does it work?

      
       curl http://localhost:8124/
       Hello World

      curl -I http://localhost:8124/
      HTTP/1.1 200 OK
      Content-Type: text/plain
      Connection: keep-alive
      
  

Node Modules

More Modules

Our Projects:

germany

Magnets

xkcd

What does it do?

magnets

Mediengewitter

batman

What does it do?

what

Questions?

owlcat

Twitter

Github