为什么 Kernel#require 占用了我的应用程序资源的这么大块? [英] Why is Kernel#require taking such a big chunk of my application's resources?

查看:44
本文介绍了为什么 Kernel#require 占用了我的应用程序资源的这么大块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 ruby​​-prof 并针对一个有点自包含的模块运行它.该模块的核心是 3 个类,可能还使用了 3 个其他辅助类.所以不应该有大量的开销和大量的需求.这在安装了大量 gem 的大型(gish)应用程序中是否正常?

I am trying out ruby-prof and ran it against a somewhat self-contained module. The core of the module is 3 classes, with maybe 3 other helper classes being used. So there shouldn't be a huge amount of overhead with tons of requires and incluces. Is this normal in a big(gish) app with a fair number of gems installed?

 18.06      7.67     1.99     0.00     7.66     1366  Kernel#require
  5.80      1.21     0.64     0.00     0.83    18704  Array#map
  5.73     10.21     0.63     0.00    10.09    38133  Array#each
  5.17      1.13     0.57     0.00     0.56    21796  Array#include?
  4.40      0.49     0.49     0.00     0.00   345434  Symbol#to_s
  3.78      0.42     0.42     0.00     0.00   446478  String#==

推荐答案

来自 ruby-prof文档:

要分析 Rails 应用程序,它是使用生产运行它至关重要设置(缓存类,缓存视图查找等).否则,Rail依赖加载代码将不堪重负在应用程序中花费的任何时间本身(我们的测试表明 Rails依赖加载导致大约 6x减速).

To profile a Rails application it is vital to run it using production like settings (cache classes, cache view lookups, etc.). Otherwise, Rail’s dependency loading code will overwhelm any time spent in the application itself (our tests show that Rails dependency loading causes a roughly 6x slowdown).

您是否使用生产设置运行此程序?如果您不使用缓存数据而是每次都必须从磁盘读取文件/类,我可以理解为什么您看到您的系统在 Kernel#require 中花费了这么多时间.

Are you running this using production settings? If you aren't using cached data and instead have to read the files/classes from disk every time, I can understand why you are seeing your system spend so much time in Kernel#require.

这篇关于为什么 Kernel#require 占用了我的应用程序资源的这么大块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆