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

Multi-tiered Node Architectures - JSConf 2011

on

  • 11,913 views

 

Statistics

Views

Total Views
11,913
Views on SlideShare
11,787
Embed Views
126

Actions

Likes
24
Downloads
198
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 Multi-tiered Node Architectures - JSConf 2011 Presentation Transcript

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