From: keithrbennett@... Date: 2021-02-15T21:40:44+00:00 Subject: [ruby-core:102510] [Ruby master Bug#17497] Ractor performance issue Issue #17497 has been updated by keithrbennett (Keith Bennett). Koichi - Huge improvement! Thank you! I installed Ruby head and now have the following output from `ruby -v`: ``` ruby 3.1.0dev (2021-02-15T09:29:35Z master 37b90bcdc1) [x86_64-linux] ``` I made minor modifications to your script (see https://gist.github.com/keithrbennett/18f10124354d62eb8ba5feafaa9b39dc) and then ran it in the Ruby project root directory and got the following results: On my Linux (Kubuntu 20.04.2) desktop: ``` Measuring first sequentially on main ractor and then with 24 ractors: user system total real 14.969907 0.003891 14.973798 ( 14.977699) 29.087580 0.051934 29.139514 ( 1.243316) 0.515 User time difference factor 12.047 Real time difference factor ``` And then on my 2015 Mac: ``` Measuring first sequentially on main ractor and then with 4 ractors: user system total real 10.477194 0.047028 10.524222 ( 10.605862) 18.226199 0.068098 18.294297 ( 5.101498) 0.575 User time difference factor 2.079 Real time difference factor ``` It's interesting that the real time difference factor on both machines is so close to ((the number of CPU's and ractors) / 2.0). The original script I used to test (at https://github.com/keithrbennett/keithrbennett-ractor-test/blob/master/ractor-file-strings-test.rb) was not very good at distributing work among the ractors equally, and this made the real time observations less reliable, since the real time was really the real time of the longest running ractor. Your script is much better in that way. It would be interesting to test more parts of the standard library though, such as the `Set` instantiations and merges I had used; if I have time I'll look into that. ---- P.S. Sorry it took so long to respond; given that notifications don't seem to work, I need to develop a habit of manually checking here every day. ---------------------------------------- Bug #17497: Ractor performance issue https://bugs.ruby-lang.org/issues/17497#change-90404 * 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, 3.0: REQUIRED ---------------------------------------- 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: