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 - 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
И не забравяйте!