Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't my Rails server render times add up?

I'm having some trouble with my Rails app being very slow on my staging server. What is most confusing is that the final line of the log output for each request.

It seems the View and Database times aren't even close to the entire render time. On one page it is as bad as ~1000ms for Completion, ~450ms for the View and ~20ms Database.

Where does the rest of the time required to render the page come from?

like image 573
Ben Crouse Avatar asked Jan 14 '09 14:01

Ben Crouse


2 Answers

When things are mysterious.... profilers are your friend!

a profiler will draw up statistics of which methods are being called the most and how long is being spent in each method call.

ruby-prof does the trick for me when I'm in RubyLand, and it will produce a nice call-graph (in html format if you want), that makes it nice and easy to see which methods are slowing up your request.

like image 74
Chris Farmiloe Avatar answered Oct 28 '22 16:10

Chris Farmiloe


I've found a large proportion of the render time can be spent on Rails creating and preparing Active Record objects. After the query and before the view. Depending on how many records are returned from a 'find', for example.

like image 20
Mark Swardstrom Avatar answered Oct 28 '22 18:10

Mark Swardstrom