我试图用 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 选项,并在没有任何运气的情况下搜索了有关此的信息。如果我能找到这个问题的根本原因以及我将如何解决这个问题,那就太好了。
如果您将其作为 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) 以强制编译所有文件,但有些文件可能无法成功编译。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句