我试图用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选项可用,并寻找没有任何的运气这个信息。如果我能找到这个问题的根本原因以及我将如何解决问题,那将是非常好的。
嘿查尔斯!非常感谢花时间看这个。我使用JRuby 9.1.7.0运行,结果绝对符合我的预期。 PS我会提交作为一个错误,但它似乎没有正确的地方:) –