What does Rails do after logging 200 OK? (Debugging slow response time)

I am trying to debug a very slow query request in my Ruby on Rails application. I managed to optimize the controller method to my liking, and the Rails log tells me that it completed the action in XX ms ( Completed 200 OK in 5049ms (Views: 34.9ms | ActiveRecord: 76.3ms) ). However, when the page loads, this message is printed long before anything is actually displayed in the browser; up to about 15 seconds of waiting time. The rack mini-profiler confirms this by telling me that the GET action (not counting the time taken to complete the controller action) took 14 seconds or so. (The profiler also confirms that the controller takes about 5 seconds to complete).

I am fine with a controller action taking 5 seconds or so, because I can check various parts of my code and see clearly what is happening slowly and why. I am completely puzzled, but why does this mysterious lag exist. What is he doing?

+6
source share
1 answer

Assets

The main reason is probably asset loading. Are you in a development environment? By default, assets are not precompiled (and I believe that resource caching is also disabled)

You may not see the related GET requests because you are using the β€œsilent assets” gem. I'm so tired of seeing all the GET requests for assets (javascript / css) that I put in this Gem file and forgot about it for a while. But then it still continued.

Service assets can be very long. For example, I use jquery ui, and at the beginning I called //require jquery.ui.all in application.js . Turns out it actually sends dozens of files just for jquery.ui. And even if the files are small and are served very quickly, there is some delay between successive GET requests / responses, which caused the application response time to localhost / development to be excessively slow

You do not want to precompile assets in development, but you can get rid of useless ones (if you use jquery, most likely you need only a few files, not all)

The response time of my server is 10 to 100 times faster when testing / manufacturing with precompiled assets.

+2
source

Source: https://habr.com/ru/post/980782/


All Articles