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

scaling that rails app
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Scaling that Rails App

Christian Amor Kvalheim Linqia.com

slide-2
SLIDE 2
  • Search Service for social communities

and groups

  • Target 10+ million groups index
  • ROR/Nginx/Solr/Memcached/

Postgres

slide-3
SLIDE 3

The Goal

  • Help you spend less time f***ing

around

  • Get the gears grinding
slide-4
SLIDE 4

Understand your pattern

  • Mostly read only (aka content)
  • Fully dynamic (aka twitter)
  • Mixed dynamic (aka social networks)
slide-5
SLIDE 5

Saving Your App

  • The traffic is killing me
  • Pure Ruby execution not so hot :(
  • I need to save my database
slide-6
SLIDE 6

WOR

  • Uh Webrick
  • Hmm Mongrel
  • Config Hell Apache + Mongrel
  • Better than expected Nginx + Mongrel
slide-7
SLIDE 7

Slim it down dude

  • Size of Page
  • Size of Scripts
  • Scripts
  • CSS

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

slide-8
SLIDE 8

How did I get that object

  • What’s in that Query
  • Repetitive Queries == Caching

candidate

  • DRY content fetching
slide-9
SLIDE 9
  • Memcached
  • Distributed hash map
  • Just grow it when needed

Memcached

Cache_fu

slide-10
SLIDE 10
  • Rails plugin
  • Active Record caching
  • Fragment and Action caching

Memcached

Cache_fu Cache_fu + Memcached =

slide-11
SLIDE 11

ActiveRecord caching

  • Save the database
  • Write custom finders
  • Cache for effect

Cache_fu

# Caching options acts_as_cached :include => [:languages, :countries, :comments, :thumbnail, :community_members]

slide-12
SLIDE 12

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 Cache_fu

slide-13
SLIDE 13

Invalidation plugin

  • Uses the DB for storing list of

invalidated pages

  • Deletes pages on all servers
  • Used at http://www.linqia.com

Cache_fu

slide-14
SLIDE 14

Invalidation plugin

Cache_fu

Rails Db Expire Page Process

Invalidate page Save to cache

slide-15
SLIDE 15

Action Caching

  • Runs filters etc before serving cache
  • But it’s not all good...what about

parameters? Cache_fu

/community/index/5?param1=a saves as /community/index/5.html

slide-16
SLIDE 16

Params plugin

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

Cache_fu

slide-17
SLIDE 17

More for your money

  • Mongrel still doing heavy lifting
  • Use Evented Mongrel for Gods sake
  • Nginx

Cache_fu

slide-18
SLIDE 18

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

Cache_fu

slide-19
SLIDE 19

How it works !

Cache_fu

Nginx Mongrel Memcached

Cache miss Save to cache Fetch from cache

slide-20
SLIDE 20

Serving Action Cache

  • But what about dynamic pages?
  • Use cookie to let Nginx serve correct

content

  • Serve cached page and do dynamic

AJAX updates Cache_fu

slide-21
SLIDE 21

Obvious DB Smell

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

Cache_fu

slide-22
SLIDE 22

Learn from Pain

  • Need to scale the db
  • Read the Mysql story
  • http://www.baselinemag.com/c/a/

Projects-Networks-and-Storage/ Inside-MySpacecom/ Cache_fu

slide-23
SLIDE 23

Linqia

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

Cache_fu

slide-24
SLIDE 24

Linqia

  • Core System hosted servers
  • On demand servers from EC2
  • S3 for assets
  • SQS for asynchronous tasks

Cache_fu

slide-25
SLIDE 25

Tools

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