[ruby-core:102286] [Ruby master Bug#17497] Ractor performance issue
From:
ko1@...
Date:
2021-01-29 08:41:54 UTC
List:
ruby-core #102286
Issue #17497 has been updated by ko1 (Koichi Sasada).
quoted from https://github.com/ruby/ruby/pull/4129#issuecomment-769613184
----
call the following methods as a task:
```ruby
def task_range_inject
(1..20_000_000).inject(:+)
end
```
with
* 4 times sequentially
* 4 times sequentially with a sleeping ractor
* 4 ractors in parallel
on
```
26_mini ruby 2.6.7p150 (2020-12-09 revision 67888) [x86_64-linux]
27_mini ruby 2.7.3p140 (2020-12-09 revision 9b884df6dd) [x86_64-linux]
master_mini ruby 3.1.0dev (2021-01-29T05:27:53Z master 9241211538) [x86_64-linux]
miniruby ruby 3.1.0dev (2021-01-29T06:21:39Z gh-4129 f996e15ff6) [x86_64-linux]
26_ruby ruby 2.6.7p150 (2020-12-09 revision 67888) [x86_64-linux]
27_ruby ruby 2.7.3p139 (2020-10-11 revision d1ba554551) [x86_64-linux]
master_ruby ruby 3.1.0dev (2021-01-29T05:27:53Z master 9241211538) [x86_64-linux]
ruby ruby 3.1.0dev (2021-01-29T06:21:39Z gh-4129 f996e15ff6) [x86_64-linux]
```
result:
```
user system total real
serial/26_mini 0 0.000145 0.000039 2.782685 ( 2.783691)
serial/27_mini 0 0.000133 0.000036 2.320257 ( 2.320305)
serial/master_mini 0 0.000141 0.000039 3.756926 ( 3.756963)
serial/miniruby 0 0.000136 0.000037 2.598088 ( 2.598126)
serial/26_ruby 0 0.000143 0.000038 2.695175 ( 2.704443)
serial/27_ruby 0 0.000139 0.000038 2.391679 ( 2.401067)
serial/master_ruby 0 0.000139 0.000038 4.391577 ( 4.391626)
serial/ruby 0 0.000128 0.000035 3.109923 ( 3.109991)
r_serial/26_mini N/A
r_serial/27_mini N/A
r_serial/master_mini 1 0.000146 0.000040 5.133049 ( 5.133056)
r_serial/miniruby 1 0.000133 0.000037 2.597336 ( 2.597300)
r_serial/26_ruby N/A
r_serial/27_ruby N/A
r_serial/master_ruby 1 0.000147 0.000040 5.910876 ( 5.910907)
r_serial/ruby 1 0.000135 0.000037 2.875752 ( 2.875727)
r_parallel/26_mini N/A
r_parallel/27_mini N/A
r_parallel/master_mini 1 0.000100 0.000028 39.297123 ( 10.160359)
r_parallel/miniruby 1 0.000110 0.000030 2.703400 ( 0.695634)
r_parallel/26_ruby N/A
r_parallel/27_ruby N/A
r_parallel/master_ruby 1 0.000122 0.000034 38.941810 ( 10.072950)
r_parallel/ruby 1 0.000131 0.000036 2.980137 ( 0.757672)
```
----------------------------------------
Bug #17497: Ractor performance issue
https://bugs.ruby-lang.org/issues/17497#change-90141
* Author: marcandre (Marc-Andre Lafortune)
* Status: Closed
* 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
<internal:ractor>: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: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>