Rails: Page loading very long time

故事扮演 提交于 2019-12-12 14:14:43

问题


I have a rails project. I got very strange thing in one controller: browser needs about 3 minutes for load page but Rails writes in logs:

Completed 200 OK in 20563ms (Views: 17144.2ms | ActiveRecord: 324.4ms)

I know 21 sec it's very long time, but It's not 3 minutes.

I know this data not enough but I don't expect complete answer only a pointer where is trouble. Size of this page about 5 Mb.


回答1:


The delay might be caused by config.assets.debug = true inside of config/environments/development.rb. Setting this to false may resolve your problem.

By doing this,source files are combined together and source maps won't work (e.g. if using Sass/Coffee you won't see it in devtools)




回答2:


As you can see the most of the time is spent in "idle" phase. This includes the time to load all resources on your page (images, stylesheets, javascript, etc.). So, your HTML page is being loaded and rendered in 10 seconds, but the rest is spent to download all the resources in your page.

This can be a single resources that is hosted on some server that is just very slow on responding to your request. So, even if you have a loaded all content, but you have a Google hosted jquery file there and really bad internet connection, then you would see that "idle" to take up a lot of time.

But, in your case, it looks like some images on your 5MB page.




回答3:


I found a problem after long search. It was unnecessary query to database which loaded many related objects for main objects. But I didn't understand why it required such many time (maybe GC clean it mess).



来源:https://stackoverflow.com/questions/37056561/rails-page-loading-very-long-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!