开发者

How to pinpoint what is slowing down my Rails App

My Rails app runs fine in development mode (without caching) but in production has a hard time loading the :show view for the primary model. The log only shows SQL queries which add up to about 45ms, but the actual render time is about 15 seconds. I'm using acts_as_ferret and paperclip, but paperclip is only calling the after_save loop to no action. There are only 1 or 2 users online at the time, so I'm not thinking I've got a backed up queue, but I really can't narrow down what's hogging up the site. What can I do to more precisely measu开发者_如何学Pythonre server-side functions and see what is backing up the load time?

Things called in the :show view

  • about 12 HABTM lists (types of tags, categories, etc.)
  • Related videos found with acts_as_ferret
  • HABTM comments for the videos

And that's really pretty much it. And how should I call HABTM as a Rails best practice? Right now I"m doing something like:

<%= @video.tags.map {|t| link_to t.name, path} %>
<%= @video.categories.map {|c| link_to c.name, path} %>
#etc....

I'm pretty sure there's a better way to do this, and I'm open to suggestion


Here are a few tools to really pinpoint bottlenecks:

  1. http://newrelic.com/ will analyze things like db query time and ruby execution time on the server side

  2. http://developer.yahoo.com/yslow/ will analyze things like response time, render time, and javascript on the client side

There's not a lot of given code to run with, but there's a few things that generally help in rails find or where:

  1. use :includes to reduce number of queries.
  2. use :select rather than selecting all columns

Great links on the subject:
http://snippets.dzone.com/posts/show/2089
http://www.fortytwo.gr/blog/18/9-Essential-Rails-Tips
http://www.engineyard.com/blog/2009/thats-not-a-memory-leak-its-bloat/


Check the machine

Maybe other things running on that machine are the problem. Have you tried profiling the machine - for example, running top to check the CPU usage?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜