Reputation: 38012
I am getting bad performance after upgrading an application to Rails 3.
Before upgrading, I got 60ms - 100ms response times.
After upgrading, I get 300ms - 1500ms response times.
The log shows a sample response time from each time:
Rails 3.0.0: Completed 200 OK in 1454ms (Views: 1314.6ms | ActiveRecord: 25.1ms)
Rails 2.3.8: Completed in 31ms (View: 27, DB: 1) | 200 OK [FILTERED]
I've tried running using passenger and 'rails server' (both results are close). I've created two identical applications (running in 2.3.8 and 3.0.0) to demonstrate the performance differences. The code that appears to be causing the performance issues is:
<%- @posts.each do |post| -%>
<h1><%= post.title %></h1>
<p><%=truncate post.body %></p>
<%- post.comments.each do |comment| -%>
<h2><%= comment.title%></h2>
<p><%=truncate comment.body %></p>
<ul>
<%- comment.ratings.each do |rating| -%>
<li><%=truncate rating.notes %></li>
<%- end -%>
</ul>
<%- end -%>
<%- end -%>
For full source, the projects are available here: http://github.com/ksylvest/performance
Thanks!
Upvotes: 1
Views: 497
Reputation: 65435
Without much to go on, there's not much anyone can do.
generated source files
In Ruby?
Really?
nested loops
select n+1
? Do you need to specify in certain queries that specific associations need to be eager-loaded?
--EDIT--
The ActiveRecord query API and performance characteristics have changed significantly from v2 to v3.
Perhaps you need to eager-load some associations?
To eager-load the comments with the posts, use
@posts = Post.includes(:comments)
and to eager-load the comments and the comments' ratings with the posts, use
@posts = Post.includes(:comments => :ratings)
Upvotes: 1
Reputation: 1082
Please include the version of Ruby you are using for your tests.
Try running Rails 3 on Ruby 1.9.2-head and see if you notice a difference. You can use something like RVM to try multiple versions of Ruby very easily.
As noted in this SO question, 1.9.1 seems to have some performance issues. If you are using Ruby Enterprise Edition with Rails 3, that may be causing some performance issues as well. If you use plugins that are not Ruby 1.9 compatible, make sure you are using REE >= 1.8.7-2010.02 as noted on the Edge Rails Guides.
I believe Rails 3 development is being targeted at 1.9.2 and backported to run on earlier versions.
Upvotes: 1