Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Node.js Scalability Myth

The Node.js Scalability Myth

Presentation given on 27.04.2012 at Roots conference in Bergen, Norway.

Felix Geisendörfer

May 02, 2012
Tweet

More Decks by Felix Geisendörfer

Other Decks in Technology

Transcript

  1. The Node.js Scalability Myth • Threads don’t scale • Event

    loops do (Probably) not true in 2012 (Very likely) not relevant
  2. Node’s Concurrency Model 1 var http = require('http'); 2 3

    http.createServer(function(req, res) { 4 res.end('Hello World'); 5 }).listen(8080); server.js
  3. Node’s Concurrency Model • Node loads server.js from disk ->

    v8 compiles & executes • listen() allocates and binds a file descriptor • Event Loops starts running
  4. Node’s Concurrency Model 1 while (true) { 2 int r

    = select(nfds, readfds, writefds, errorfds, 0); 3 if (r === 0) { 4 continue; 5 } 6 7 // Figure out which fds had activity, accept() on server fds, read() on // connection fds, write() queued writes 8 } Abstracted by libuv Different on Windows
  5. Node’s Concurrency Model • Cooperative multitasking • Low memory usage

    • Fast / efficient • Simple (compared to threads)
  6. CPU

  7. CPU (v8) • V8 compiles JS to Assembly • Just-in-time

    compilation (JIT) • Does pretty well in those language benchmarks
  8. Memory • No hard memory limit on 64 bit (since

    node-0.6 / v8-3.7) • JS is a garbage collected language (avoid huge heaps) • Buffers do not count towards heap
  9. Network • Node’s concurrency model is optimized for networking •

    Good at fully saturating available network resources
  10. Disk • Done in thread pool • Unfortunately along with

    DNS at this point • Throughput ok, but not ideal yet • sendfile() not working yet
  11. ...