Caching, Memcached And Rails
Upcoming SlideShare
Loading in...5
×
 

Caching, Memcached And Rails

on

  • 35,405 views

An overview of the various caching mechanisms available in Rails 2.3.

An overview of the various caching mechanisms available in Rails 2.3.

Statistics

Views

Total Views
35,405
Views on SlideShare
34,200
Embed Views
1,205

Actions

Likes
28
Downloads
266
Comments
2

12 Embeds 1,205

http://www.mikeperham.com 923
http://www.slideshare.net 261
http://miimr.com 7
http://webcache.googleusercontent.com 3
http://fillup.tumblr.com 3
https://www.mikeperham.com 2
http://static.slidesharecdn.com 1
http://74.125.47.132 1
http://safe.tumblr.com 1
http://ztaylor.tumblr.com 1
http://duckduckgo.com 1
http://seekr-artemis.heroku.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hi ,

    Thanks for your blog.
    Can we validate request input data using memcache ? Actually I am facing scenario in which user uploading CSV file which can have hundreds of rows and to validate each row using ActiveRecord taking long time.

    Please can you reply me below question:-

    1. So can we cache our validation rule in memcache ?
    2. If it is possible to store validation rules in memcache but can I able to perform
    validation check ?
    Are you sure you want to
    Your message goes here
    Processing…
  • well done
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Caching, Memcached And Rails Caching, Memcached And Rails Presentation Transcript

  • Caching, Memcached, and Rails Mike Perham http://mikeperham.com Wednesday, March 25, 2009
  • Me Maintainer of memcache-client, shipped with Rails Hardcore performance nerd Wednesday, March 25, 2009
  • Performance Let me Tell you a Story... Wednesday, March 25, 2009
  • Performance Tuning Remove unnecessary Functionality Tune necessary Functionality ONLY THEN, add caching last ALWAYS track before/after timings Wednesday, March 25, 2009
  • Caching Cache the results of expensive operations Why is this memoization dumb? Wednesday, March 25, 2009
  • Why Dumb? SCALABILITY! FRESHNESS! Wednesday, March 25, 2009
  • Rails Built in support for memcached since Rails 2.1 config/environments/production.rb: Wednesday, March 25, 2009
  • Request Varnish Apache Rails DB Memcached Standard Toolset for Rails 2.3 Further == Slower Wednesday, March 25, 2009
  • Caching Mechanisms HTTP Proxy FASTER Page Action Fragment SLOWER Object Wednesday, March 25, 2009
  • HTTP Proxy HTTP/URL caching with Varnish Expires, Etag, Cache-Control headers 5-10k req/sec! Wednesday, March 25, 2009
  • Page Caching ERB --> Static HTML Uh oh, uses the filesystem! Apache = 1-5k req/sec Wednesday, March 25, 2009
  • Action Caching Runs filters (e.g. authorization) Can use any cache strategy File, memory, memcached Wednesday, March 25, 2009
  • Fragment Caching Parts of the page are unique per user Fragment cache the various UI boxes Dynamically assemble HTML from the cache Wednesday, March 25, 2009
  • Object Caching Built-in AR support for “smart” keys Rails.cache.fetch(post.cache_key) { expensive_calc(post) } “#{table_name}/#{self.id}-#{self.updated_at.to_i}” Support for complex dependencies Wednesday, March 25, 2009
  • Expiration “There are only two hard things in Computer Science: naming and cache invalidation” Explicit expire_page :controller => ‘users’, :action => ‘index’ expire_action :controller => ‘users’, :action => ‘index’ Rails.cache.delete(‘key’) Observers Wednesday, March 25, 2009
  • Expiration (Cont’d) Time-based Rails.cache.fetch(‘key’, :expires_in => 1.hour) { ... } expires_in(2.hours) # sets page’s HTTP max-age attribute Versioning Rails.cache.fetch(user.cache_key) { ... } Wednesday, March 25, 2009
  • Memcached Giant Hash of Fixed Size Time-based expiration LRU eviction Operations: GET, SET, APPEND, INCR, CAS Limited to 1MB per value, 250 chars per key Wednesday, March 25, 2009
  • Facebook 100s of servers w/ 28TB of RAM 5 billion page views/day 400k req/sec from memcached Wednesday, March 25, 2009
  • Performance Wednesday, March 25, 2009
  • Mongrel + Nginx Varnish Nginx WEB1 M1 M2 M1 M2 Memcached Memcached APP1 APP2 Wednesday, March 25, 2009
  • Apache + Passenger Varnish HAProxy WEB1 Memcached Memcached Apache Apache Rails Rails Rails Rails APP1 APP2 Wednesday, March 25, 2009
  • Advanced Spread your cache across a farm of memcached Use the memcaches_page plugin Use AJAX for user-specific widgets Wednesday, March 25, 2009
  • Advice Cache late in the development cycle, after tuning! Memcached gives you time-based expiration, versioning and multi-machine support. Cache as early in the request as possible! Varnish Apache Rails DB Wednesday, March 25, 2009
  • THANK YOU! HTTP://MIKEPERHAM.COM MPERHAM@GMAIL.COM QUESTIONS? Wednesday, March 25, 2009