开发者

For Ruby and Rails, how to print out the true page rendering time on the webpage?

If using in the controlle开发者_运维问答r:

def index
  @time_start_in_controller
    ...
end

and at the end of view, use

<%= "took #(Time.now - @time_start_in_controller} seconds" %>

but isn't the time at the view not the true ending of rendering, because it needs to mix with the layout and so forth. What is a more accurate way (just as accurate as possible) to print out the page generation time right on the webpage?

(update: also, the console showing the log as taking 61ms, but the page definitely took 2 to 3 seconds to load, and the network I am using is super fast, at home or at work, at 18mbps or higher with a ping of maybe 30ms)

update: it is a bit strange that if I use the http performance test ab

ab -n 10 http://www.my-web-site.com:8080

it takes 3 seconds total for 10 requests. But if I use Firefox or Chrome to load the page, each page load is about 3 seconds. This is tunneling to my work's computer back to my notebook running Rails 3, but shouldn't make a difference because I run Bash locally for the above statement and use Firefox locally too.


in a typical production environment, static content (images, css, js) are handled by the web server (eg. apache, nginx etc) not you rails server. so you should check their logs as well. if you are serving static content from your rails server that could be your problem right there.

If your browser time is slow but the time taken in rails (According to the logs) is fast, that can mean many things including but not quite limited to:

  1. network speed is slow
  2. your dns server is slow and browser can't resolve your dns quickly (this happens with for instance if you use godaddy for your dns server they throttle dns lookups)
  3. the requests concurrency exceeds how many threads you have in rails

one way to debug these types of performance issues is to put something in front of the rails server (for example Haproxy) and turn the logging to full. As they will show how many waiting requests there are and how long the actual request/response transferring took along with how long it took your rails thread to process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜