On 05/15/2012 04:27 AM, Alon Burg wrote:
> Hi Caleb & Roger,
> Thank you very much for your responses.
> I tried adding PerfTools but still seem to be missing some understanding
> of where is most of the time spent and which functions are eating all of
> the cpu/performance.
>
> A few clarifications on the stack I am profile: Rails 3.1 + Mongoid +
> JBuilder for JSON rendering.
> The main issue I am trying to debug is why the JBuilder JSON rendering
> is taking 80% of the request time in production (530msec spent on views
> / 640sec total request time)
>
> Attached is my PerfTools + RubyProf results
Ok, took a look at the profiler outputs you sent. perftools wasn't very
enlightening... all the boxes were about the same size, so nothing is
jumping out there. Plus, it's rails so of course there's some big long
call stack....
the graph.html is more revealing, I think. Usually interpreting these is
a matter of pouring over the output for hours combined with spelunking
the source code, (which is deeper than I intend to go) but here are some
things that are obvious:
1) 17 calls to Mongoid::Collections::Retry#retry_on_connection_failure
accounted for 44.33% of time. It's something to think further on... I'd
say that there probably shouldn't have been any calls to this. Lots of
time spent in Mongoid generally, but it all seems to flow towards this.
Maybe your mongo server needs more resources?
2) JBuilder (which I don't know what that is, I thought that was a
borland ide) shows up at maybe 32%? not sure what's going on there.
3) actual time rendering json looks to be around 16%. considering your
workload, this is interesting. it could be worth optimizing the json
render, maybe with some custom renderers which would be faster than the
generic ones from JSON, but that's not where you need to look first.
4) Mongoid (and other things) are doing lots of Kernel#tap, which is
silly. profiler claims this is only 0.1%, but this could be deceptive.
Might be worth trying to inline this.
It looks like this test run only went for maybe 4 seconds? How many
queries were done for this run? Once again, I recommend longer test runs
when doing profiling, to help filter out the noise better. A couple
minutes is a good lower limit.
I recommend you try to learn how to read graph_html; I know there are
some guides out there that could help you. Google for something like
'interpreting ruby-prof output' or 'interpreting gprof output' (since
ruby-prof and gprof give very similar outputs).