improving performance of iphone.news.com.au
DESCRIPTION
TRANSCRIPT
![Page 1: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/1.jpg)
PERFORMANCEIMPROVINGof iphone.news.com.au with Rails 2.1
![Page 2: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/2.jpg)
LUCASTIM
![Page 3: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/3.jpg)
![Page 4: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/4.jpg)
THE H.O.P.
![Page 5: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/5.jpg)
THE H.O.P.
![Page 6: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/6.jpg)
NEWS.COM.AU
![Page 7: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/7.jpg)
NEWS.COM.AU
![Page 8: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/8.jpg)
IPHONE.NEWS.COM.AU
![Page 9: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/9.jpg)
KEEP IT SIMPLE
![Page 10: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/10.jpg)
INITIAL PLANNINGIMPROVING PERFORMANCEMAINTENANCE
![Page 11: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/11.jpg)
INITIAL PLANNINGFETCHING& PARSING
![Page 12: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/12.jpg)
FETCHING & PARSING
![Page 13: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/13.jpg)
FETCHING & PARSING
Fetching feeds
![Page 14: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/14.jpg)
FETCHING & PARSING
Fetching feeds
Parsing feeds
![Page 15: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/15.jpg)
FETCHING & PARSING
Fetching feeds
Parsing feeds
Fetching images
![Page 16: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/16.jpg)
FETCHING & PARSING
Fetching feeds
Parsing feeds
Fetching images
Resizing images
![Page 17: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/17.jpg)
RAKE TASKS
![Page 18: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/18.jpg)
RAKE TASKS
Doesn’t irritate your mongrels
![Page 19: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/19.jpg)
RAKE TASKS
Doesn’t irritate your mongrels
Eases provisioning
![Page 20: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/20.jpg)
RAKE TASKS
Doesn’t irritate your mongrels
Eases provisioning
Short-lived processes
![Page 21: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/21.jpg)
INITIAL PLANNINGSERVING WEB REQUESTS
![Page 22: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/22.jpg)
CLIENT STATE
![Page 23: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/23.jpg)
CLIENT STATE
No Rails session
![Page 24: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/24.jpg)
CLIENT STATE
No Rails session
Hand-baked cookies
![Page 25: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/25.jpg)
THE HOME PAGE
![Page 26: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/26.jpg)
THE HOME PAGE
64 customisable news sections
![Page 27: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/27.jpg)
THE HOME PAGE
64 customisable news sections
5 recent stories per section
![Page 28: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/28.jpg)
THE HOME PAGE
64 customisable news sections
5 recent stories per section
Customisable position of sections
![Page 29: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/29.jpg)
THE HOME PAGE
64 customisable news sections
5 recent stories per section
Customisable position of sections
Sections constantly expiring
![Page 30: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/30.jpg)
THE HOME PAGE
64 customisable news sections
5 recent stories per section
Customisable position of sections
Sections constantly expiring
Each section expires at different times
![Page 31: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/31.jpg)
STEP 1. LIMIT THEIR OPTIONS
![Page 32: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/32.jpg)
STEP 1. LIMIT THEIR OPTIONS
Maximum 8 feeds
![Page 33: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/33.jpg)
FIND GRANULAR COMMONALITIES
![Page 34: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/34.jpg)
FIND GRANULAR COMMONALITIES
Some people have the same feeds
![Page 35: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/35.jpg)
FIND GRANULAR COMMONALITIES
Some people have the same feeds
Each feeds last 5 articles are the same
![Page 36: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/36.jpg)
DE-NORMALISATION
@feed.5_most_recent_stories_ids
![Page 37: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/37.jpg)
RENDERING.
![Page 38: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/38.jpg)
RENDERING.
ERB is a dog.
![Page 39: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/39.jpg)
IMPROVING PERFORMANCEBENCHMARKING
![Page 40: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/40.jpg)
BONG
![Page 42: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/42.jpg)
BONG
http://bong.rubyforge.org/
Geoffrey Grosenbach
![Page 43: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/43.jpg)
BONG
http://bong.rubyforge.org/
Geoffrey Grosenbach
httperf
![Page 44: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/44.jpg)
USAGE: ./script/performance/request [options] [session script path] -n, --times [100] How many requests to process. Defaults to 100. -b, --benchmark Benchmark instead of profiling -m, --measure [mode] Which ruby-prof measure mode to use: process_time, wall_time, cpu_time, allocations, or memory. Defaults to process_time. --open [CMD] Command to open profile results. Defaults to "open %s &" -h, --help Show this help
./SCRIPT/PERFORMANCE
![Page 45: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/45.jpg)
RAILS_ROOT/PROFILING/SCRIPTS/CUSTOMISE.RB
get '/customise'
![Page 46: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/46.jpg)
$ RAILS_ENV=profiling./script/performance/request-n 10-bprofiling/integration_scripts/customise.rb
Warming up once0.34 sec, 1 requests, 2 req/sec
Benchmarking 10x ..........0.81 sec, 10 requests, 12 req/sec
![Page 47: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/47.jpg)
$ rake benchmark:customise RAILS_ENV=profiling
Warming up once0.34 sec, 1 requests, 2 req/sec
Benchmarking 10x ..........0.81 sec, 10 requests, 12 req/sec
![Page 48: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/48.jpg)
LIB/TASKS/BENCHMARK.RAKE
namespace :benchmark do def run_benchmark_script(integration_script_name) `./script/performance/request -n 10 -b profiling/integration_scripts/#{integration_script_name}.rb` end desc "Benchmark the customise page" task :customise => :environment do puts run_benchmark_script('customise') endend
![Page 49: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/49.jpg)
desc "Benchmark a feed page" task :feed => :environment do ENV['FEED_ID'] = Feed.find(:first, :order => "id DESC").id.to_s puts run_benchmark_script('feed') end
PASSING ARGS
get "/feeds/#{ENV['FEED_ID']}"
![Page 50: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/50.jpg)
IMPROVING PERFORMANCECACHING
![Page 51: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/51.jpg)
RAILS 2.1
![Page 52: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/52.jpg)
RAILS 2.1
Ryan Bates’ excellent screencast:
![Page 53: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/53.jpg)
RAILS 2.1
Ryan Bates’ excellent screencast:
Caching in Rails 2.1
![Page 54: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/54.jpg)
RAILS.CACHE
Rails.cache.write('date', Date.today)Rails.cache.read('date')
Rails.cache.fetch('time') { Time.now }Rails.cache.read('time')
Category.first.cache_key # => "categories/1-20080622195243"
![Page 55: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/55.jpg)
CONFIG/ENVIRONMENTS/PRODUCTION.RB
config.cache_store = :mem_cache_store, "server1:11211", "server2:11211", { :namespace => 'myapp_production' }
![Page 56: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/56.jpg)
HOMEPAGE
<% for feed in @feeds %> <%- stories = feed.stories.recent(5) -%> ...<% end %>
![Page 57: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/57.jpg)
class Feed < ActiveRecord::Base # Cache key used for content that relies on the recent stories def recent_stories_cache_key "feeds/#{self.id}/#{self.stories_updated_at.to_i}" endend
![Page 58: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/58.jpg)
<% for feed in @feeds %> <% cache "#{feed.recent_stories_cache_key}/home" do -%> <%- stories = feed.stories.recent(5) -%> ... <% end -%><% end -%>
![Page 59: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/59.jpg)
DEPLOYMENT
after "deploy", "clear_cache"desc "Clear the Rails cache"task :clear_cache, :roles => :app, :except => {:no_release => true, :no_symlink => true} do run("cd #{current_release}; rake RAILS_ENV=#{rails_env} cache:clear")end
namespace :cache do desc "Clear the Rails cache" task :clear => :environment do Rails.cache.clear endend
![Page 60: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/60.jpg)
MAINTENANCE
![Page 61: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/61.jpg)
README
== Caching
=== Feed page
Fragment cache the lookup and render of recent stories
=== Customise
No caching
![Page 62: Improving performance of iphone.news.com.au](https://reader033.vdocument.in/reader033/viewer/2022051110/54c891534a7959cf7d8b4661/html5/thumbnails/62.jpg)
NEW RELIC