$30 off During Our Annual Pro Sale. View Details »

Node.js - In Production

Node.js - In Production

Talk given on 25.05.2012 at Web Rebels in Oslo. Included a lot of live coding, video available here: https://vimeo.com/43380478

Felix Geisendörfer

June 16, 2012
Tweet

More Decks by Felix Geisendörfer

Other Decks in Programming

Transcript

  1. in production 25.05.2012 at Web Rebels (Oslo, Norway)

  2. Felix Geisendörfer

  3. transloadit.com

  4. core contributor

  5. OS Projects • node-mysql • node-formidable • ~50 npm modules

    total
  6. (@)felixge(.de)

  7. Audience?

  8. Backend?

  9. Node.js?

  10. In Production?

  11. Node.js in production

  12. - Our Imagination -

  13. - Our First Attempt -

  14. node- v0.1.28 (November 17, 2009)

  15. (evcom) recv() Success

  16. None
  17. 6 week rewrite

  18. Launch Delayed

  19. How to not be like us

  20. Today

  21. Transloadit Today • 75 TB files processed • 5 -

    100 Servers • Bootstrapped & Profitable
  22. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself
  23. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself ✔
  24. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself ✔ ‏
  25. <Live Coding>

  26. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself ✔ ✔
  27. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself ✔ ✔ ‏
  28. Hosting Yourself

  29. Cloud or not?

  30. Port 80

  31. One port to rule them all

  32. The enemy is looking at you

  33. process.setuid() • Start process as root • Drop privileges once

    port is open
  34. iptables • Forward traffic from port 80 to another port

    • sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000 • Safe, simple, flexible
  35. Reverse Proxy • Haproxy, Nginx, etc. • Useful for other

    routing, file serving • Watch out for buffering, web sockets, etc.
  36. Staying Alive

  37. Staying Alive • Upstart, Monit, etc. • Detects process crashes,

    restarts them • Make sure to log this
  38. Deployment

  39. The Build • I recommend to vendor node with your

    app • Build server makes sure node is compiled • *.tar.gz can be deployed to same Kernel / Architecture
  40. The Deploy • Another CI job • Get’s list of

    machines to deploy to • Uploads .tar.gz, stops old app, starts new one via SSH
  41. Fork • cluster.fork() • ~1 process per CPU • Load

    Balancing done by Kernel
  42. Metrics

  43. Gather metrics • node-measured, etc. • Graphite, Librato, etc. •

    Measure early, measure often
  44. Gather metrics • Requests / Events per Second (Meters) •

    Response times (Histograms) • Number of items in queue (Gauges)
  45. Configuration • Use environment variables! • Bash files to store

    configs locally
  46. http://www.12factor.net/

  47. The Smart Way to node(tm) • Wait for node to

    be stable enough • Learn how to host on PaaS • Learn how to host it yourself ✔ ✔ ✔
  48. I need to build an über-scalable web service. It will

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

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

  51. None
  52. None
  53. None
  54. Node.js is good for: • I/O bound workloads (streaming data)

    • Long running connections (web sockets) • Code sharing between server / client
  55. Today ~14:00

  56. Questions?