際際滷

際際滷Share a Scribd company logo
弌从舒仍亳舒仆亠 仆舒 Rails
亳仍仂亢亠仆亳
舒仍亠仆亳仆 亳仂于
2013
舒 仄亠仆
 5 亞仂亟亳仆亳 仂仗亳  Ruby on Rails
 从舒仍亳舒仆亠 亟仂 仄亳仍亳仂仆亳 亰舒磦从亳 仆舒 亟亠仆
 big data processing
仂亢亠 仍亳 Rails 亟舒 从舒仍亳舒?
舒从 舒弍仂亳 Ruby on Rails?
Browser
WEBrick
Makes request
Rails App
Parses the request Writes response
Sends response
亰弍仂 仆舒 仗舒于亳仍亠仆 app server
One machine concurrent setup
Browser
App Server
Makes request
Rails App
Parses the request Writes response
Sends response
App Server
App Server
App Server
App Server
Pool of workers
Many machines concurrent setup
Browser
Makes request Sends response
App Server
App Server
App Server
App Server
App Server
Load Balancer
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
Balances between machines
Instance/VM/Box Instance/VM/Box Instance/VM/Box
Slow clients
亰从舒舒 亠 弍舒于仆舒 亶 从舒仂 从舒仆舒仍舒 亠 Internet
仂亢亠 亟舒 亳仄舒 network latency
Browser
App Server
App Server
App Server
App Server
App Server
Load Balancer
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
亰仗仂仍亰于舒亶亠 "弍亠亳" 亰舒 舒亳从舒
Browser
App Server
App Server
App Server
App Server
App Server
ELB/haproxy/nginx
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
App Server
nginxnginx nginx
亰弍亠亠亠 于仆亳仄舒亠仍仆仂 Ruby VM
 GC 仄仂亢亠 亟舒 亰舒亠仄舒 ** 于亠仄亠
 green threads vs true concurrency vs GIL
 仄仆仂亞仂 亰舒于亳亳 仂 仗亳仍仂亢亠仆亳亠仂
 ruby 1.8 仆亠 亠 仗仂亟亟亢舒 仂亳亳舒仍仆仂
 GC tweaks
 RUBY_GC_MALLOC_LIMIT
 RUBY_HEAP_SLOTS_INCREMENT
 RUBY_HEAP_MIN_SLOTS
Ruby Enterprise Edition
 仂亢亠 弍亠 仆舒亶-亟仂弍舒舒 1.8 亳仄仗仍亠仄亠仆舒亳
 Tweakable GC params
 copy-on-write friendly GC
 亰仗仂仍亰于舒 TCMalloc - 仗仂-弍亰 malloc
JRuby
 亰亞舒亟亠仆 于 JVM
 亰仗仂仍亰于舒 JVM GC - 仄仆仂亞仂 弍亰
 亠 仗仂亟亟亢舒 native extensions
 Unicorn 仆亠 亠 仗仂亟亟亢舒
 丐磡于舒 亟舒 亠 仗仂仍亰于舒 TomCat, JBoss,
GlassFish, etc.
 礆舒 GIL + 亳亰仗仂仍亰于舒 native threads
 GC-仂 仄仂亢亠 亟舒 亠 仆亳仆亞仂于舒
 亠 于亳从亳 gem-仂于亠 亠 仗仂亟亟亢舒
 弌舒仆仆舒 仗仂亟亟亢从舒 仆舒 unicode
 仂亢亠 弍亳 仆舒亶-亟仂弍亳 亳亰弍仂 亰舒 仆仂于 仗仂亠从
MRI 2.0
Unicorn::OobGC
Time
Request 1 Request 2
Request 3
GC GC
Time
Request 1 Request 2
Request 3
GC GC
Monitoring
NewRelic - 丶!
仂仍亠亰仆亳 仗仂亠从亳/仍亞亳
 Unicorn - app server
 nginx - web server
 haproxy - load balancer
 AWS - real-time scaling infrastructure
 NewRelic - kick ass monitoring
 REE - optimized ruby VM
 memcached - 亠亳亳, 从亠亳舒仆亠
 于仂 亳亰仄亠于舒亶亠, 仗仂仍亠 仂仗亳仄亳亰亳舒亶亠
 舒弍仂亠 仗仂亟从 - 仆舒亶-于舒亢仆舒舒
仂仗亳仄亳亰舒亳
  仗仂于亠亠仂 仍舒亶 bottleneck-舒 亠 data IO
 Rails 从舒仍亳舒 仆亠 仗仂-仍仂仂 仂 于亠从亳 亠亟亳仆
亟亞 framework
 亳从仂 e computer science
 仆亠 亰舒弍舒于磺亠!
仗仂亳?

More Related Content

Scaling Rails apps - Valentin Mihov

  • 2. 舒 仄亠仆 5 亞仂亟亳仆亳 仂仗亳 Ruby on Rails 从舒仍亳舒仆亠 亟仂 仄亳仍亳仂仆亳 亰舒磦从亳 仆舒 亟亠仆 big data processing
  • 3. 仂亢亠 仍亳 Rails 亟舒 从舒仍亳舒?
  • 4. 舒从 舒弍仂亳 Ruby on Rails? Browser WEBrick Makes request Rails App Parses the request Writes response Sends response
  • 6. One machine concurrent setup Browser App Server Makes request Rails App Parses the request Writes response Sends response App Server App Server App Server App Server Pool of workers
  • 7. Many machines concurrent setup Browser Makes request Sends response App Server App Server App Server App Server App Server Load Balancer App Server App Server App Server App Server App Server App Server App Server App Server App Server App Server Balances between machines Instance/VM/Box Instance/VM/Box Instance/VM/Box
  • 8. Slow clients 亰从舒舒 亠 弍舒于仆舒 亶 从舒仂 从舒仆舒仍舒 亠 Internet 仂亢亠 亟舒 亳仄舒 network latency Browser App Server App Server App Server App Server App Server Load Balancer App Server App Server App Server App Server App Server App Server App Server App Server App Server App Server
  • 9. 亰仗仂仍亰于舒亶亠 "弍亠亳" 亰舒 舒亳从舒 Browser App Server App Server App Server App Server App Server ELB/haproxy/nginx App Server App Server App Server App Server App Server App Server App Server App Server App Server App Server nginxnginx nginx
  • 10. 亰弍亠亠亠 于仆亳仄舒亠仍仆仂 Ruby VM GC 仄仂亢亠 亟舒 亰舒亠仄舒 ** 于亠仄亠 green threads vs true concurrency vs GIL 仄仆仂亞仂 亰舒于亳亳 仂 仗亳仍仂亢亠仆亳亠仂 ruby 1.8 仆亠 亠 仗仂亟亟亢舒 仂亳亳舒仍仆仂 GC tweaks RUBY_GC_MALLOC_LIMIT RUBY_HEAP_SLOTS_INCREMENT RUBY_HEAP_MIN_SLOTS
  • 11. Ruby Enterprise Edition 仂亢亠 弍亠 仆舒亶-亟仂弍舒舒 1.8 亳仄仗仍亠仄亠仆舒亳 Tweakable GC params copy-on-write friendly GC 亰仗仂仍亰于舒 TCMalloc - 仗仂-弍亰 malloc
  • 12. JRuby 亰亞舒亟亠仆 于 JVM 亰仗仂仍亰于舒 JVM GC - 仄仆仂亞仂 弍亰 亠 仗仂亟亟亢舒 native extensions Unicorn 仆亠 亠 仗仂亟亟亢舒 丐磡于舒 亟舒 亠 仗仂仍亰于舒 TomCat, JBoss, GlassFish, etc. 礆舒 GIL + 亳亰仗仂仍亰于舒 native threads
  • 13. GC-仂 仄仂亢亠 亟舒 亠 仆亳仆亞仂于舒 亠 于亳从亳 gem-仂于亠 亠 仗仂亟亟亢舒 弌舒仆仆舒 仗仂亟亟亢从舒 仆舒 unicode 仂亢亠 弍亳 仆舒亶-亟仂弍亳 亳亰弍仂 亰舒 仆仂于 仗仂亠从 MRI 2.0
  • 14. Unicorn::OobGC Time Request 1 Request 2 Request 3 GC GC Time Request 1 Request 2 Request 3 GC GC
  • 16. 仂仍亠亰仆亳 仗仂亠从亳/仍亞亳 Unicorn - app server nginx - web server haproxy - load balancer AWS - real-time scaling infrastructure NewRelic - kick ass monitoring REE - optimized ruby VM memcached - 亠亳亳, 从亠亳舒仆亠
  • 17. 于仂 亳亰仄亠于舒亶亠, 仗仂仍亠 仂仗亳仄亳亰亳舒亶亠 舒弍仂亠 仗仂亟从 - 仆舒亶-于舒亢仆舒舒 仂仗亳仄亳亰舒亳 仗仂于亠亠仂 仍舒亶 bottleneck-舒 亠 data IO Rails 从舒仍亳舒 仆亠 仗仂-仍仂仂 仂 于亠从亳 亠亟亳仆 亟亞 framework 亳从仂 e computer science 仆亠 亰舒弍舒于磺亠!