【问题标题】:Slow basic operations JRuby rake task慢速基本操作 JRuby rake task
【发布时间】:2017-07-13 08:57:27
【问题描述】:

我正在尝试诊断 JRuby 和 Rails 的性能问题,但运气不佳。

基本上,我有一个 JRuby on Rails 5 应用程序,它将启动 rake 任务中的进程。在测试一些 rake 任务时,我们注意到与使用 MRI ruby​​ 编写并使用 bundle exec ruby <script> 调用运行的旧脚本相比,速度明显下降。

在 rake 任务的上下文中对字符串、数组、数字等的基本操作要慢 5-6 倍。例如,进行这个简单的测试:

bin/rake performance_test:start

performance_test.rake 在哪里:

namespace :performance_test do
  desc 'Test Performance'
  task :start do
    Benchmark.bmbm do |x|
      x.report ('double') do
        100_000_000.times do
          "Hello world!"
        end
      end
    end
  end
end

产生这些结果:

Rehearsal ------------------------------------------
double  27.570000   0.630000  28.200000 ( 27.714908)
-------------------------------- total: 28.200000sec

             user     system      total        real
double  28.050000   0.750000  28.800000 ( 29.864897)

运行时:

jruby -G performance_test.rb

performance_test.rb 在哪里:

require 'require_all'
require 'bundler'
Bundler.require(:default)
require_all Dir.glob('lib/extensions/*.rb')

Benchmark.bmbm do |x|
  x.report ('double') do
    100_000_000.times do
      "Hello world!"
    end
  end
end

给我这些结果:

Rehearsal ------------------------------------------
double   4.930000   0.240000   5.170000 (  5.639570)
--------------------------------- total: 5.170000sec

             user     system      total        real
double   4.420000   0.180000   4.600000 (  5.538717)

我已经尝试了几乎所有可用的 JVM 和 JRuby 选项,并在没有任何运气的情况下搜索了这方面的信息。如果我能找到这个问题的根本原因以及我将如何解决这个问题,那就太好了。

【问题讨论】:

    标签: ruby-on-rails performance rake jruby


    【解决方案1】:

    如果您将它作为 JRuby 错误提交,您可能会更好地引起我们的注意,即使它不是真正的错误 :-)

    我相信您的数字可能在 JRuby 1.7 或早期版本的 JRuby 9k 下,它没有独立 JIT 编译块。这是我在 JRuby 9k master (9.1.8.0) 下的结果:

    ~/projects/jruby/tmp $ jruby performance_test.rb 
    Rehearsal ------------------------------------------
    double   3.180000   0.130000   3.310000 (  2.801371)
    --------------------------------- total: 3.310000sec
    
                 user     system      total        real
    double   2.740000   0.030000   2.770000 (  2.700693)
    
    ~/projects/jruby/tmp $ rake performance_test:start
    Rehearsal ------------------------------------------
    double   3.890000   0.110000   4.000000 (  3.499264)
    --------------------------------- total: 4.000000sec
    
                 user     system      total        real
    double   3.430000   0.040000   3.470000 (  3.382129)
    

    Rake 数稍慢,但不像您的示例那样慢 5 倍。

    如果您使用 JRuby 1.7.x 运行,您可以尝试将 -X+C 传递给 JRuby (JRUBY_OPTS=-X+C) 以强制编译所有文件,但有些文件可能无法编译成功。

    【讨论】:

    • 嘿查尔斯!非常感谢您花时间看这个。我使用 JRuby 9.1.7.0 运行,结果绝对符合我的预期。 PS 我会作为一个错误提交,但它似乎不是正确的地方:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多