【问题标题】:Rails complete quickly but it takes longer to finish loading the pageRails 快速完成,但加载页面需要更长的时间
【发布时间】:2017-07-03 22:31:00
【问题描述】:

我最近一直在处理这个问题。我可以在服务器控制台中发现以下内容:

Completed 200 OK in 2748ms (Views: 0.2ms | ActiveRecord: 42.8ms)

正如您所见,活动记录和视图需要不到一秒的时间,但仍需要大约 4 秒才能从服务器获得响应。我已经运行了多个活动记录优化,但我找不到为什么要花这么长时间才能看到它。

【问题讨论】:

  • 您可以安装 'ruby-prof' (gem 'ruby-prof') 然后将其包含在您的视图中: - 需要 'ruby-prof' - RubyProf.start /将您的视图代码放在这里 - 结果= RubyProf.stop - 打印机 = RubyProf::CallStackPrinter.new(result) - file = File.open('profile.html', 'w') - printer.print(file) - file.close 你可以这样做控制器,如果这没有向您显示任何相关信息。然后打开“profile.html”,它将位于您的存储库的根文件夹中。

标签: ruby-on-rails performance activerecord rendering


【解决方案1】:

试试rack-mini-profiler

为每个 html 页面显示速度标志的中间件。设计用于生产和开发。

特点:

数据库分析 - 目前支持 Mysql2、Postgres、Oracle (oracle_enhanced ~> 1.5.0) 和 Mongoid3(回退支持 ActiveRecord)
调用堆栈分析 - 显示 gem 所用时间的火焰图
内存分析 - 每个请求的内存使用情况、GC 统计信息和全局分配指标

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多