[ruby-core:102287] [Ruby master Bug#17497] Ractor performance issue
From:
ko1@...
Date:
2021-01-29 08:46:10 UTC
List:
ruby-core #102287
Issue #17497 has been updated by ko1 (Koichi Sasada).
inversion (Yura Babak) wrote in #note-10:
> I also made 2 posts about strange performance testing results (with sources) and some conclusions.
> In my case, 2 ractors work 3-times longer than doing the same payload in the main thread.
With digest benchmark:
```
user system total real
serial/26_ruby 0 0.000239 0.000079 2.497317 ( 2.503279)
serial/27_ruby 0 0.000972 0.000324 2.306552 ( 2.310275)
serial/master_ruby 0 0.000293 0.000098 3.776824 ( 3.776623)
serial/ruby 0 0.000190 0.000063 2.668395 ( 2.668287)
r_serial/26_ruby N/A
r_serial/27_ruby N/A
r_serial/master_ruby 1 0.000407 0.000000 5.579597 ( 5.579969)
r_serial/ruby 1 0.000476 0.000000 2.682626 ( 2.683627)
r_parallel/26_ruby N/A
r_parallel/27_ruby N/A
r_parallel/master_ruby 1 0.000242 0.000000 48.298173 ( 12.959255)
r_parallel/ruby 1 0.000242 0.000000 3.782164 ( 0.984832)
```
seems solved.
----------------------------------------
Bug #17497: Ractor performance issue
https://bugs.ruby-lang.org/issues/17497#change-90142
* 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:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>