scaling that rails app
play

Scaling that Rails App Christian Amor Kvalheim Linqia.com Search - PowerPoint PPT Presentation

Scaling that Rails App Christian Amor Kvalheim Linqia.com Search Service for social communities and groups Target 10+ million groups index ROR/Nginx/Solr/Memcached/ Postgres The Goal Help you spend less time f***ing around


  1. Scaling that Rails App Christian Amor Kvalheim Linqia.com

  2. • Search Service for social communities and groups • Target 10+ million groups index • ROR/Nginx/Solr/Memcached/ Postgres

  3. The Goal • Help you spend less time f***ing around • Get the gears grinding

  4. Understand your pattern • Mostly read only (aka content) • Fully dynamic (aka twitter) • Mixed dynamic (aka social networks)

  5. Saving Your App • The traffic is killing me • Pure Ruby execution not so hot :( • I need to save my database

  6. WOR • Uh Webrick • Hmm Mongrel • Config Hell Apache + Mongrel • Better than expected Nginx + Mongrel

  7. Slim it down dude • Size of Page http://images.google.com/imgres?imgurl=http://images.allposters.com/images/pic/GBEU/FP1334~The-Simpsons-Posters.jpg&imgrefurl=http://www homer_simpson_poster h&prev=/images%3Fq%3Dhomer%2Bsimpson%26start%3D20%26ndsp%3D20%26um%3D1%26hl%3Den%26client%3Dfirefox-a%26rls%3Dorg.mozilla:en-US:official%26sa%3DN • Size of Scripts • Scripts • CSS

  8. How did I get that object • What’s in that Query • Repetitive Queries == Caching candidate • DRY content fetching

  9. Cache_fu Memcached • Memcached • Distributed hash map • Just grow it when needed

  10. Cache_fu Memcached Cache_fu + Memcached = • Rails plugin • Active Record caching • Fragment and Action caching

  11. Cache_fu ActiveRecord caching • Save the database • Write custom finders • Cache for effect # Caching options acts_as_cached :include => [:languages, :countries, :comments, :thumbnail, :community_members]

  12. Cache_fu Page Caching • Render content to disk • Bypass Mongrel, let Nginx/Apache do the lifting • Not good for dynamic content • Standard page cache invalidation based on shared file system

  13. Cache_fu Invalidation plugin • Uses the DB for storing list of invalidated pages • Deletes pages on all servers • Used at http://www.linqia.com

  14. Cache_fu Invalidation plugin Invalidate page Rails Db Save to cache Expire Page Process

  15. Cache_fu Action Caching • Runs filters etc before serving cache • But it’s not all good...what about parameters? /community/index/5?param1=a saves as /community/index/5.html

  16. Cache_fu Params plugin • Takes params into consideration • Used at http://www.linqia.com • Coming soon to a browser near you

  17. Cache_fu More for your money • Mongrel still doing heavy lifting • Use Evented Mongrel for Gods sake • Nginx

  18. Cache_fu Strong man seeks server • Nginx Serving from memcached • http://openhack.ru/nginx-patched • Based on params • Patch for Cache_fu needed • No Raw support as far as I can see

  19. Cache_fu How it works ! Cache miss Nginx Mongrel Fetch from cache Save to cache Memcached

  20. Cache_fu Serving Action Cache • But what about dynamic pages? • Use cookie to let Nginx serve correct content • Serve cached page and do dynamic AJAX updates

  21. Cache_fu Obvious DB Smell • Any sql “like ‘%faster%’” ? • Get a search engine (solr, sphinx) • Using find(:all) ? • Use it with select, limit and offset

  22. Cache_fu Learn from Pain • Need to scale the db • Read the Mysql story • http://www.baselinemag.com/c/a/ Projects-Networks-and-Storage/ Inside-MySpacecom/

  23. Cache_fu Linqia • All search is GET • Nginx serving from memcached • Page Caching for community info • Dynamic change of cached pages • Using SOLR for all searching

  24. Cache_fu Linqia • Core System hosted servers • On demand servers from EC2 • S3 for assets • SQS for asynchronous tasks

  25. Tools • Railsbench • railsbench.rubyforge.org • Tsung load testing tool • Firefox + firebug • YSlow from Yahoo • Website Optimization • www.websiteoptimization.com

Recommend


More recommend