Jan 15, 2015
Performance tips in rails development
select *
•temporary table• :select•belongs_to, has_many
text, blob
•blogs: id, title, content• temporary table•blogs: id, title, content_id
contents: id, content•memcached
db:migrate
•t.column "title", :string•varchar(255)• :limit
update• @article.update_attributes(params[:article])• @article.update_attributes(:title =>
"#{params[:article][:title]}", :author => "#{params[:article][:author]}")
join• :include, :joins• mysql> SELECT * FROM tag
-> JOIN tag_post ON tag_post.tag_id=tag.id-> JOIN post ON tag_post.post_id=post.id-> WHERE tag.tag='mysql';mysql> SELECT * FROM tag WHERE tag='mysql';mysql> SELECT * FROM tag_post WHERE tag_id=1234;mysql> SELECT * FROM post WHERE post.id in (123,456,567,9098,8904);
• High.Performance.MySQL.Second.Edition, p159
IN vs OR• SELECT *
FROM wp_postsWHERE post_author IN ( 1, 2, 3, 4, 5, 6, 7, 8, 9 )
• SELECT *FROM wp_postsWHERE post_author = 1 OR post_author = 2 OR post_author = 3 OR post_author = 4 OR post_author = 5 OR post_author = 6 OR post_author = 7 OR post_author = 8 OR post_author = 9
• http://www.webmastersbydesign.com/2008/07/13/sql-speed-test-in-vs-or/
helpers
• link_to, url_for
session store
•file•db•memcached•CookieStore, Rails 2.0
http://izumi.plan99.net/blog/index.php/2007/11/25/rails-20-cookie-session-store-and-security/
memcached
•memcache-client•cache_fu•cache-money, Write-Through
http://github.com/nkallen/cache-money/tree/master
•key
Tools• newrelic_rpm• request-log-analyzer
http://github.com/wvanbergen/request-log-analyzer/tree/master
• rawkhttp://rubyforge.org/projects/rawk-the-logs/
• railsbenchhttp://rubyforge.org/projects/railsbench
THANK YOU :)