Multi-tiered Node Architectures - JSConf 2011
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Multi-tiered Node Architectures - JSConf 2011

on

  • 12,539 views

 

Statistics

Views

Total Views
12,539
Views on SlideShare
12,413
Embed Views
126

Actions

Likes
24
Downloads
200
Comments
1

13 Embeds 126

http://lanyrd.com 43
http://www.redditmedia.com 34
http://www.techgig.com 22
http://irr.posterous.com 8
http://www.twylah.com 5
http://us-w1.rockmelt.com 4
http://thinkery.me 3
http://a0.twimg.com 2
http://trunkly.com 1
http://twitter.com 1
https://twitter.com 1
http://10.0.1.2 1
http://paper.li 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Multi-tiered Node Architectures - JSConf 2011 Presentation Transcript

  • 1. Multi-tiered Node.jsArchitecturesTom Hughes-Croucher@sh1mmertom@joyent.com
  • 2. Scalable Server-Side Code with JavaScriptNode Up and Running Tom Hughes-Croucher
  • 3. Goal 1.Minimise clientresponse time
  • 4. Goal 2.Maximise resourceefficiency on server
  • 5. Client → Server Server → DB Computation Computation
  • 6. Pre-allocate resources to the client for the entire duration
  • 7. Get efficiency within each connection
  • 8. Pre-allocation = sacrificing resource efficiency forconnection response times
  • 9. Server
  • 10. Request
  • 11. In order to serve thefastest request memory is heavily wasted
  • 12. When you run out ofmemory the server gets overwhelmed
  • 13. And that sucks.
  • 14. Don’t pre-allocate memory
  • 15. Create a place-holder for ‘slow’ tasks
  • 16. Place-holder
  • 17. Shared WorkResources
  • 18. Deal with tasks when they are ready in a FIFO way
  • 19. App (event loop) AppEvents Event OS StackEvents
  • 20. If we block the event loop then we can’t serve requests
  • 21. If we do “big” work in the event loop then we can only serve requests after the work is finished
  • 22. Blocking the main event loop is bad. Mmmkay.
  • 23. Event-loop harassment Pan-da
  • 24. Multi-tieredArchitectures
  • 25. The obviousarchitecture
  • 26. Client Front-end DatabaseUser Node DB
  • 27. What about this?
  • 28. Front-end JSDomClient Database Farm Render FarmUser Node Node Node Node DB Node Node Node Node
  • 29. Why an architecture like this?
  • 30. Parallelisation?
  • 31. Client → Server Server → DB Computation Computation
  • 32. Non-blocking I/O removes resourceallocation during latency
  • 33. Pushing client-facing processing off the main process does not improve response time
  • 34. Better multi-tier architectures
  • 35. Front-endClient Database Farm DBUser Node Node Node Node Big Slow Logging farm Disk Node Node Disk
  • 36. Move work which isn’tuser-facing out of main event loop
  • 37. Use pre-forking todistribute work acrossprocessors into ‘farms’
  • 38. Distributing work
  • 39. Cluster
  • 40. children.js:var server = require(http).createServer( function(req, res) { res.writeHead(200, {}); res.end("Sever stuff"); });
  • 41. Run
  • 42. var cluster = require(cluster);cluster(children).listen(80);
  • 43. Use load balancers to distribute across servers
  • 44. node-proxy squid varnish haproxy
  • 45. Sharding
  • 46. Disclaimer:Sharding is hard
  • 47. Node processes can hold many clients soyou can do big shards
  • 48. Inter-processcommunication on machine
  • 49. Use file descriptor sharing to do onmachine multicast
  • 50. Load Front-endClient Database balancers Shards Node Node Node NodeUser Node Node DB Node Node Node Node Node Node
  • 51. Unix FDs have much lower unboundedlatency than network
  • 52. Summary
  • 53. 1. Don’t sweat client facing CPU time2. Move non client-facing away3. Cluster to use all processors
  • 54. Fin.(You should follow me, @sh1mmer on Twitter. Like now!)
  • 55. Bonus