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 26.04.2012 at MixIT conference in Lyon, France.

Felix Geisendörfer

May 02, 2012
Tweet

More Decks by Felix Geisendörfer

Other Decks in Technology

Transcript

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

    View Slide

  2. (@)felixge(.de)

    View Slide

  3. core contributor

    View Slide

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

    View Slide

  5. History

    View Slide

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

    View Slide

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

    View Slide

  8. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  13. Topic of this Talk

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  18. View Slide

  19. Audience?

    View Slide

  20. Node.js?

    View Slide

  21. Are you measuring app performance in production?

    View Slide

  22. 1000
    req / s

    View Slide

  23. 100
    req / s

    View Slide

  24. 10
    req / s

    View Slide

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

    View Slide

  26. The End?

    View Slide

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

    View Slide

  28. Scalability

    View Slide

  29. (c) @substack

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  33. Node’s Concurrency
    Model

    View Slide

  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

    View Slide

  35. Node’s Concurrency Model
    $ node server.js

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  39. Vertical Scalability

    View Slide

  40. Adding more resources to a single node

    View Slide

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

    View Slide

  42. CPU

    View Slide

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

    View Slide

  44. Computers of the
    future will have
    hundreds of cores!

    View Slide

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

    View Slide

  46. But ...

    View Slide

  47. Does your problem
    require shared
    memory?

    View Slide

  48. If yes: Don’t use node

    View Slide

  49. And: Good Luck

    View Slide

  50. If no:
    child_process.fork()

    View Slide

  51. Redis / ZeroMQ are your
    friends

    View Slide

  52. GPUs

    View Slide

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

    View Slide

  54. Memory

    View Slide

  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

    View Slide

  56. Network

    View Slide

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

    View Slide

  58. Disk

    View Slide

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

    View Slide

  60. Does node scale vertically?

    View Slide

  61. Yeah, good enough

    View Slide

  62. Horizontal Scalability

    View Slide

  63. Adding more nodes to a system

    View Slide

  64. Bad News

    View Slide

  65. Node.js has no horizontal scaling features

    View Slide

  66. Even worse

    View Slide

  67. This s#@t is really hard

    View Slide

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

    View Slide

  69. ...

    View Slide

  70. Good Luck

    View Slide

  71. One tip

    View Slide

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

    View Slide

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

    View Slide


  74. View Slide

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

    View Slide

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

    View Slide

  77. Thanks

    View Slide

  78. Feedback

    View Slide