I have this list of remote links. When one is clicked, two divs are updated each with its own partial.
_printing.html.erb
开发者_JAVA技巧<%= link_to printing.name, printing, :remote => true %>
printings/show.js.erb
jQuery('#render').html( "<%= escape_javascript(render "render",:printing=>@printing) %>" );
jQuery('#info').html( "<%= escape_javascript(render "info",:printing=>@printing) %>" );
When clicking a link, it takes a while for the divs to be replaced. This example took 15 seconds before being replaced. I timed it with a watch. But the log tells a different story.
Rendered printings/_render.html.erb (22.7ms)
Rendered printings/_info.html.erb (39.7ms)
Rendered printings/show.js.erb (73.6ms)
Completed 200 OK in 978ms (Views: 457.7ms | ActiveRecord: 40.6ms)
So there's a serious delay on two occasions. The first: why is the sum of the above values so incredibly big? And second, why do I wait 15 seconds, but the log tells me it took less than a second?
So there are several possibilities here. It could be an issue of latency (Firebug or Safari/Chrome inspector tools will show this), some issue in the javascript that is slowing down the event loop (this is unlikely, but possible, you can step through the code in a JS debugger), or it could be due to the performance of the web server. 1 second response time is not fast and the log view only tells you part of the story. In addition to the time spent in the request (which is displayed), the request could be significantly delayed by other requests in the queue. Development mode runs a single process server, so each request has to line up to be served. If you're running Webrick then all bets are off in terms of performance, but it is easy to solve by installing mongrel or thin.
For better visibility into your app's performance, install the newrelic gem which provides a very comprehensive development mode view for seeing where your app is spending time.
The difference in response times may have to do with the browser being slow to uncompress gzipped AJAX requests.
Consider testing turning compression off for these ajax requests. See http://public.ok2life.com/welcome/index/86 for detailed information.
精彩评论