Slide 1

Slide 1 text

The Node.js Scalability Myth Felix Geisendörfer 26.04.2012 at MixIT Conference (Lyon, France)

Slide 2

Slide 2 text

(@)felixge(.de)

Slide 3

Slide 3 text

core contributor

Slide 4

Slide 4 text

transloadit.com (using node since v0.0.6)

Slide 5

Slide 5 text

History

Slide 6

Slide 6 text

Ryan Dahl starts the node project (first commit) Feb 16, 2009

Slide 7

Slide 7 text

Discovered node.js (v0.0.6) ~June, 2009

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Core Contributor & Module Author node-mysql node-formidable + 30 other modules

Slide 10

Slide 10 text

Isaac Schlueter starts the npm package manager (first commit) Sep 29, 2009

Slide 11

Slide 11 text

Ryan’s talk at JSConf.EU gets people excited about node Nov 7, 2009

Slide 12

Slide 12 text

(c) @substack Jan 30, 2012 Ryan appoints Isaac to lead node.js

Slide 13

Slide 13 text

Topic of this Talk

Slide 14

Slide 14 text

I need to build an über-scalable web service. It will be the next big thing!

Slide 15

Slide 15 text

Easy! I will use node.js and MongoDB!

Slide 16

Slide 16 text

Easy! I will use node.js and MongoDB!

Slide 17

Slide 17 text

Because node.js is “scalable”, right?

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Audience?

Slide 20

Slide 20 text

Node.js?

Slide 21

Slide 21 text

Are you measuring app performance in production?

Slide 22

Slide 22 text

1000 req / s

Slide 23

Slide 23 text

100 req / s

Slide 24

Slide 24 text

10 req / s

Slide 25

Slide 25 text

10 requests / per second = 864000 requests / day 10 req / s

Slide 26

Slide 26 text

The End?

Slide 27

Slide 27 text

I REALLY need to build an über-scalable web service!!11!1

Slide 28

Slide 28 text

Scalability

Slide 29

Slide 29 text

(c) @substack

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

The Node.js Scalability Myth • Threads don’t scale • Event loops do (Probably) not true in 2012 (Very likely) not relevant

Slide 32

Slide 32 text

More relevant • Understanding your tools • Using the right tool for the job

Slide 33

Slide 33 text

Node’s Concurrency Model

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Node’s Concurrency Model $ node server.js

Slide 36

Slide 36 text

Node’s Concurrency Model • Node loads server.js from disk -> v8 compiles & executes • listen() allocates and binds a file descriptor • Event Loops starts running

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Node’s Concurrency Model • Cooperative multitasking • Low memory usage • Fast / efficient • Simple (compared to threads)

Slide 39

Slide 39 text

Vertical Scalability

Slide 40

Slide 40 text

Adding more resources to a single node

Slide 41

Slide 41 text

Vertical Scalability • CPU • GPUs • Memory • Disk • Network

Slide 42

Slide 42 text

CPU

Slide 43

Slide 43 text

CPU (v8) • V8 compiles JS to Assembly • Just-in-time compilation (JIT) • Does pretty well in those language benchmarks

Slide 44

Slide 44 text

Computers of the future will have hundreds of cores!

Slide 45

Slide 45 text

CPU • Node is single threaded (runs on a single CPU) • No shared memory

Slide 46

Slide 46 text

But ...

Slide 47

Slide 47 text

Does your problem require shared memory?

Slide 48

Slide 48 text

If yes: Don’t use node

Slide 49

Slide 49 text

And: Good Luck

Slide 50

Slide 50 text

If no: child_process.fork()

Slide 51

Slide 51 text

Redis / ZeroMQ are your friends

Slide 52

Slide 52 text

GPUs

Slide 53

Slide 53 text

GPUs • No support in node itself • node-cuda addon by Kashif Rasul

Slide 54

Slide 54 text

Memory

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Network

Slide 57

Slide 57 text

Network • Node’s concurrency model is optimized for networking • Good at fully saturating available network resources

Slide 58

Slide 58 text

Disk

Slide 59

Slide 59 text

Disk • Done in thread pool • Unfortunately along with DNS at this point • Throughput ok, but not ideal yet • sendfile() not working yet

Slide 60

Slide 60 text

Does node scale vertically?

Slide 61

Slide 61 text

Yeah, good enough

Slide 62

Slide 62 text

Horizontal Scalability

Slide 63

Slide 63 text

Adding more nodes to a system

Slide 64

Slide 64 text

Bad News

Slide 65

Slide 65 text

Node.js has no horizontal scaling features

Slide 66

Slide 66 text

Even worse

Slide 67

Slide 67 text

This s#@t is really hard

Slide 68

Slide 68 text

Problems • De-coupling / encapsulation • CAP Theorem • System Automation

Slide 69

Slide 69 text

...

Slide 70

Slide 70 text

Good Luck

Slide 71

Slide 71 text

One tip

Slide 72

Slide 72 text

Monitor & Measure! • Collect: node-measured, statsd, ... • Analyze: Graphite, Librato Metrics, ... • Debug

Slide 73

Slide 73 text

So if node doesn’t have magic scaling, what is it good for?

Slide 74

Slide 74 text

Slide 75

Slide 75 text

tl;dr • Know your requirements • There are no silver bullets

Slide 76

Slide 76 text

Questions? Slides will be available at felixge.de

Slide 77

Slide 77 text

Thanks

Slide 78

Slide 78 text

Feedback