Project

General

Profile

Actions

Bug #17995

closed

Slow down when mjit and Ractor are being used at same time

Added by nekoyama32767 (Jinsong Yu) over 3 years ago. Updated almost 2 years ago.

Status:
Closed
Target version:
-
ruby -v:
Ruby 3.0.1p64 (2021-04-05 revison 0fb782ee38)[x86-64-linux] ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x64-mingw32]
[ruby-core:104328]

Description

When using --jit and Ractor at same time, benchmark would be slow down with recursion function such like Tarai function an Fibonacci function.
The slow down is confirmed under both gcc(linux) and mingw64(windows MSYS2).

Test environment:
Cpu:Ryzen9 8core/16thread
Memory:32GB@3200Mhz
OS:Ubuntu 21.04/Windows 10

Because of this cpu has 8 physic core,the parallel thread number is set to 8

Slow down is also confirmed with using only ractor (without sequence running).

When runing 'par' before 'seq' and using --mjit,'seq' is more slower than runing 'seq' berfore 'par'

Tarai function

def tarai(x, y, z) =
  x <= y ? y : tarai(tarai(x-1, y, z),
                     tarai(y-1, z, x),
                     tarai(z-1, x, y))
require 'benchmark'
Benchmark.bm do |x|
  # sequential version
  x.report('seq'){ 8.times{ tarai(14, 7, 0) } }

  # parallel version
  x.report('par'){
    8.times.map do
      Ractor.new { tarai(14, 7, 0) }
    end.each(&:take)
  }
end

Fibonacci function

def fib(n)
  if n==1 then return 1 end
  if n==2 then return 1 end
  fib(n-1)+fib(n-2)
end

require 'benchmark'
Benchmark.bm do |x|
   # sequential version
  x.report('fib:seq'){ 8.times{ fib(40) } }

  # parallel version
  x.report('fib:par '){
    8.times.map do
      Ractor.new {fib(40) }
    end.each(&:take)
  }
end
Actions #1

Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Description updated (diff)
Actions #2

Updated by k0kubun (Takashi Kokubun) over 2 years ago

  • Assignee set to k0kubun (Takashi Kokubun)

Updated by k0kubun (Takashi Kokubun) almost 2 years ago

  • Status changed from Open to Closed

Closing this since I replaced the implementation in [Feature #19420]. It doesn't mean that it works well with Ractor, but the current issue with Ractor should be reported separately since it's a completely different symptom.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0