SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
Скалиране на 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
И не забравяйте!
Въпроси?

Mais conteúdo relacionado

Semelhante a Scaling Rails apps - Valentin Mihov

Processing big data with AWS MapReduce
Processing big data with AWS MapReduceProcessing big data with AWS MapReduce
Processing big data with AWS MapReduceValentin Mihov
 
Life In the cloud
Life In the cloudLife In the cloud
Life In the cloudzeridon
 
WordPress - Не е страшно да кешираш !
WordPress - Не е страшно да кешираш !WordPress - Не е страшно да кешираш !
WordPress - Не е страшно да кешираш !Veroslav Cenov
 
Ускоряване на World Wide Wait
Ускоряване на World Wide WaitУскоряване на World Wide Wait
Ускоряване на World Wide WaitSEOM
 
SEO курс, лекция 11 - От заявка до рендиране
SEO курс, лекция 11 - От заявка до рендиранеSEO курс, лекция 11 - От заявка до рендиране
SEO курс, лекция 11 - От заявка до рендиранеLily Grozeva
 
[Dev.bg] CI from scratch with Jenkins
[Dev.bg] CI from scratch with Jenkins[Dev.bg] CI from scratch with Jenkins
[Dev.bg] CI from scratch with JenkinsBorislav Traykov
 
On page seo презентация от Digital4Plovdiv
On page seo презентация от Digital4PlovdivOn page seo презентация от Digital4Plovdiv
On page seo презентация от Digital4PlovdivNikola Minkov
 
JavaScript - езикът с много приложения
JavaScript - езикът с много приложенияJavaScript - езикът с много приложения
JavaScript - езикът с много приложенияStefan Krastev
 

Semelhante a Scaling Rails apps - Valentin Mihov (10)

Processing big data with AWS MapReduce
Processing big data with AWS MapReduceProcessing big data with AWS MapReduce
Processing big data with AWS MapReduce
 
Life In the cloud
Life In the cloudLife In the cloud
Life In the cloud
 
WordPress - Не е страшно да кешираш !
WordPress - Не е страшно да кешираш !WordPress - Не е страшно да кешираш !
WordPress - Не е страшно да кешираш !
 
Ускоряване на World Wide Wait
Ускоряване на World Wide WaitУскоряване на World Wide Wait
Ускоряване на World Wide Wait
 
SEO курс, лекция 11 - От заявка до рендиране
SEO курс, лекция 11 - От заявка до рендиранеSEO курс, лекция 11 - От заявка до рендиране
SEO курс, лекция 11 - От заявка до рендиране
 
Webloz2011
Webloz2011Webloz2011
Webloz2011
 
[Dev.bg] CI from scratch with Jenkins
[Dev.bg] CI from scratch with Jenkins[Dev.bg] CI from scratch with Jenkins
[Dev.bg] CI from scratch with Jenkins
 
On page seo презентация от Digital4Plovdiv
On page seo презентация от Digital4PlovdivOn page seo презентация от Digital4Plovdiv
On page seo презентация от Digital4Plovdiv
 
JavaScript - езикът с много приложения
JavaScript - езикът с много приложенияJavaScript - езикът с много приложения
JavaScript - езикът с много приложения
 
Kendo + Drupal (Bulgarian)
Kendo + Drupal (Bulgarian)Kendo + Drupal (Bulgarian)
Kendo + Drupal (Bulgarian)
 

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