From: ko1@... Date: 2021-01-05T07:47:37+00:00 Subject: [ruby-core:101930] [Ruby master Bug#17497] Ractor performance issue Issue #17497 has been updated by ko1 (Koichi Sasada). flash report; ```ruby Warning[:experimental] = false if defined? Warning[] def task_inject (1..10_000_000).inject(:+) end alias task task_inject # p method(:task) MODE = (ARGV.shift || :r_parallel).to_sym TN = 4 case MODE when :serial TN.times{ task } when :r_serial exit(1) unless defined? Ractor TN.times{ Ractor.new{ task }.take } when :r_parallel exit(1) unless defined? Ractor TN.times.map{ Ractor.new{ task } }.each{|r| r.take} else raise end print "%4d" % GC.count ``` and ``` user system total real serial/26_mini 0 0.000000 0.000248 1.318308 ( 1.318555) serial/27_mini 0 0.000000 0.000627 1.209881 ( 1.209730) serial/master_mini 0 0.000000 0.000430 1.997904 ( 1.997656) serial/miniruby 0 0.000000 0.000254 1.723801 ( 1.723786) serial/26_ruby 0 0.000000 0.000481 1.256867 ( 1.256746) serial/27_ruby 0 0.000000 0.008709 1.098332 ( 1.098257) serial/master_ruby 0 0.000000 0.000312 1.915706 ( 1.916034) serial/ruby 0 0.000000 0.000288 1.921821 ( 1.921793) r_serial/26_mini N/A r_serial/27_mini N/A r_serial/master_mini 1 0.000000 0.000388 2.460095 ( 2.460922) r_serial/miniruby 1 0.000000 0.000359 2.784072 ( 2.784779) r_serial/26_ruby N/A r_serial/27_ruby N/A r_serial/master_ruby 1 0.000000 0.000216 2.690338 ( 2.690321) r_serial/ruby 1 0.000000 0.000237 2.982560 ( 2.983885) r_parallel/26_mini N/A r_parallel/27_mini N/A r_parallel/master_mini 1 0.000000 0.000210 23.172113 ( 6.316598) r_parallel/miniruby 1 0.000000 0.000248 25.933848 ( 7.054210) r_parallel/26_ruby N/A r_parallel/27_ruby N/A r_parallel/master_ruby 1 0.000000 0.000214 25.243151 ( 6.805798) r_parallel/ruby 1 0.000000 0.000181 28.647737 ( 7.991565) ``` * on serial execution, master is x2 slower than 2.6/2.7 * on serial execution with quiet ractor (multi-ractor-mode), master is -x2.5 times slower than 2.6/2.7 * on parallel execution with ractos, master is x7 slower than 2.6/2.7 ---------------------------------------- Bug #17497: Ractor performance issue https://bugs.ruby-lang.org/issues/17497#change-89778 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- There's a strange performance issue with Ractor (at least on MacOS, didn't run on other OS). I ran a benchmark doing 3 different types of work: * "fib": method calls (naive fibonacci calculation) * "cpu": `(0...1000).inject(:+)` * "sleep": call `sleep` I get the kind of results I was excepting for the `fib` and for sleeping, but the results for the "cpu" workload show a problem. It is so slow that my pure Ruby backport (using Threads) is 65x faster ���� on my Mac Pro (despite having 6 cores). Expected results would be 6x slower, so in that case Ractor is 400x slower than it should ���� On my MacBook (2 cores) the results are not as bad, the `cpu` workload is 3x faster with my pure-Ruby backport (only) instead of ~2x slower, so the factor is 6x too slow. ``` $ gem install backports Successfully installed backports-3.20.0 1 gem installed $ ruby ractor_test.rb :267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. fib: 110 ms | cpu: 22900 ms | sleep: 206 ms $ B=t ruby ractor_test.rb Using pure Ruby implementation fib: 652 ms | cpu: 337 ms | sleep: 209 ms ``` Notice the `sleep` run takes similar time, which is good, and `fib` is ~6x faster on my 6-core CPU (and ~2x faster on my 2-core MacBook), again that's good as the pure ruby version uses Threads and thus runs with a single GVL. The `cpu` version is the problem. Script is here: https://gist.github.com/marcandre/bfed626e538a3d0fc7cad38dc026cf0e -- https://bugs.ruby-lang.org/ Unsubscribe: