【发布时间】: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