kunovsky/put_it_out — pull request #76 by ElaineYu (2013-11-26 17:01:38+00:00)
Title: Elaine memcache

@mikelikesbikes @ryanbriones

Load time before memcache

Processing by PostsController#index as HTML
Post Load (0.5ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (11.6ms)
Rendered shared/_navbar.html.erb (1.3ms)
Completed 200 OK in 169.1ms (Views: 113.1ms | ActiveRecord: 6.7ms)

.............................................................................................................

Load times after running rake assets:precompile

Added memcache gem and adjusted/added configurations
http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memcachestore

# STEP 1: Less bytes to the wire. Ran rake assets:precompile

Processing by PostsController#index as HTML
Post Load (0.4ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (13.0ms)
Rendered shared/_navbar.html.erb (1.4ms)
Completed 200 OK in 174.0ms (Views: 140.5ms | ActiveRecord: 7.1ms)

See compression: ls -al public/assets
-rw-r--r-- 1 apprentice staff 195K Nov 26 09:44 application-70a75588b372d9322c8d77e5d8a57d98.css
-rw-r--r-- 1 apprentice staff 26K Nov 26 09:44 application-70a75588b372d9322c8d77e5d8a57d98.css.gz

# STEP 2: Add index (limit the amount of data you need to get to your query)

Part 1: Add index to comments on Post Id
rails generate migration add_index_to_comments_on_post_id
add_index :comments, :post_id
rake db:migrate

Ryan Briones, philosopher, impregnating thoughts:
Ryan "Every time you edit a migration, God kills a kitten"
Source of transcription: Salamanders Phase 3: Web Performance

Added this...
Processing by PostsController#index as HTML
Post Load (0.4ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (11.8ms)
Rendered shared/_navbar.html.erb (1.3ms)
Completed 200 OK in 169.0ms (Views: 113.4ms | ActiveRecord: 6.8ms)

Part 2: Add index to posts on user id

rails generate migration add_index_to_posts_on_user_id
rake db:migrate

Processing by PostsController#index as HTML
Post Load (0.5ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (11.7ms)
Rendered shared/_navbar.html.erb (1.4ms)
Completed 200 OK in 173.1ms (Views: 116.4ms | ActiveRecord: 8.4ms)

Then added some caching to controller and model for Post.

See link: Building a Rails 3 Application with Memcache
https://devcenter.heroku.com/articles/building-a-rails-3-application-with-memcache

Processing by PostsController#index as HTML
Rendered posts/index.html.erb within layouts/application (91.6ms)
Rendered shared/_navbar.html.erb (1.3ms)
Completed 200 OK in 169.6ms (Views: 161.6ms | ActiveRecord: 6.2ms)

???? merde