The Node.js Scalability Myth

The Node.js Scalability Myth

Presentation given on 26.04.2012 at MixIT conference in Lyon, France.

23968f0ca75b13463d2db5343e5c2096?s=128

Felix Geisendörfer

May 02, 2012
Tweet

Transcript

  1. The Node.js Scalability Myth Felix Geisendörfer 26.04.2012 at MixIT Conference

    (Lyon, France)
  2. (@)felixge(.de)

  3. core contributor

  4. transloadit.com (using node since v0.0.6)

  5. History

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

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

  8. None
  9. Core Contributor & Module Author node-mysql node-formidable + 30 other

    modules
  10. Isaac Schlueter starts the npm package manager (first commit) Sep

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

    7, 2009
  12. (c) @substack Jan 30, 2012 Ryan appoints Isaac to lead

    node.js
  13. Topic of this Talk

  14. I need to build an über-scalable web service. It will

    be the next big thing!
  15. Easy! I will use node.js and MongoDB!

  16. Easy! I will use node.js and MongoDB!

  17. Because node.js is “scalable”, right?

  18. None
  19. Audience?

  20. Node.js?

  21. Are you measuring app performance in production?

  22. 1000 req / s

  23. 100 req / s

  24. 10 req / s

  25. 10 requests / per second = 864000 requests / day

    10 req / s
  26. The End?

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

  28. Scalability

  29. (c) @substack

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

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

    loops do (Probably) not true in 2012 (Very likely) not relevant
  32. More relevant • Understanding your tools • Using the right

    tool for the job
  33. Node’s Concurrency Model

  34. 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
  35. Node’s Concurrency Model $ node server.js

  36. Node’s Concurrency Model • Node loads server.js from disk ->

    v8 compiles & executes • listen() allocates and binds a file descriptor • Event Loops starts running
  37. 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
  38. Node’s Concurrency Model • Cooperative multitasking • Low memory usage

    • Fast / efficient • Simple (compared to threads)
  39. Vertical Scalability

  40. Adding more resources to a single node

  41. Vertical Scalability • CPU • GPUs • Memory • Disk

    • Network
  42. CPU

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

    compilation (JIT) • Does pretty well in those language benchmarks
  44. Computers of the future will have hundreds of cores!

  45. CPU • Node is single threaded (runs on a single

    CPU) • No shared memory
  46. But ...

  47. Does your problem require shared memory?

  48. If yes: Don’t use node

  49. And: Good Luck

  50. If no: child_process.fork()

  51. Redis / ZeroMQ are your friends

  52. GPUs

  53. GPUs • No support in node itself • node-cuda addon

    by Kashif Rasul
  54. Memory

  55. 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
  56. Network

  57. Network • Node’s concurrency model is optimized for networking •

    Good at fully saturating available network resources
  58. Disk

  59. Disk • Done in thread pool • Unfortunately along with

    DNS at this point • Throughput ok, but not ideal yet • sendfile() not working yet
  60. Does node scale vertically?

  61. Yeah, good enough

  62. Horizontal Scalability

  63. Adding more nodes to a system

  64. Bad News

  65. Node.js has no horizontal scaling features

  66. Even worse

  67. This s#@t is really hard

  68. Problems • De-coupling / encapsulation • CAP Theorem • System

    Automation
  69. ...

  70. Good Luck

  71. One tip

  72. Monitor & Measure! • Collect: node-measured, statsd, ... • Analyze:

    Graphite, Librato Metrics, ... • Debug
  73. So if node doesn’t have magic scaling, what is it

    good for?
  74. <Live Coding>

  75. tl;dr • Know your requirements • There are no silver

    bullets
  76. Questions? Slides will be available at felixge.de

  77. Thanks

  78. Feedback