2017-02-23 41 views
0

我试图用JRuby和Rails诊断性能问题,但没有多少运气。基本上,我有一个JRuby on Rails 5应用程序,它将启动rake任务中的进程。在测试一些rake任务时,我们注意到与我们使用的写在MRI ruby​​中的旧脚本相比显着下降,并使用bundle exec ruby <script>调用运行。慢速基本操作JRuby rake任务

在rake任务上下文中对字符串,数组,数字等的基本操作速度要慢5-6倍。在运行此

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 

例如采取这个简单的测试:

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 

产生这些结果其中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选项可用,并寻找没有任何的运气这个信息。如果我能找到这个问题的根本原因以及我将如何解决问题,那将是非常好的。

回答

0

你可能会吸引我们的注意力更好,如果你提起它作为一个JRuby的错误,即使它不是真正:-)

的错误,我相信你的号码很可能的JRuby 1.7下,或JRuby的早期版本9k没有JIT独立编译块。这是我下的JRuby 9K主结果(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) 

瑞克数字是有点慢,但不是5倍作为你的榜样慢。

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

+0

嘿查尔斯!非常感谢花时间看这个。我使用JRuby 9.1.7.0运行,结果绝对符合我的预期。 PS我会提交作为一个错误,但它似乎没有正确的地方:) –