我正在尝试诊断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选项,并搜索了有关这方面的信息,但一无所获。如果我能找到这个问题的根本原因,以及我该如何解决这个问题,那就太好了。
发布于 2017-02-24 04:10:09
如果您将其作为JRuby错误归档,即使它不是真正的错误,也可能会更好地引起我们的注意:-)
我相信您的数字可能低于JIT1.7,或者不能独立编译代码块的JRuby 9k的早期版本。这是我在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)以强制编译所有文件,但有些文件可能无法成功编译。
https://stackoverflow.com/questions/42406243
复制相似问题