ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:52086]  [Ruby master Bug#20489] Ractor behavior strange in ruby master
@ 2024-05-14  9:00 nekoyama32767 (Jinsong Yu) via ruby-dev
  2024-09-20  1:10 ` [ruby-dev:52115] " hsbt (Hiroshi SHIBATA) via ruby-dev
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: nekoyama32767 (Jinsong Yu) via ruby-dev @ 2024-05-14  9:00 UTC (permalink / raw)
  To: ruby-dev; +Cc: nekoyama32767 (Jinsong Yu)

Issue #20489 has been reported by nekoyama32767 (Jinsong Yu).

----------------------------------------
Bug #20489: Ractor behavior strange in ruby master
https://bugs.ruby-lang.org/issues/20489

* Author: nekoyama32767 (Jinsong Yu)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-05-14T01:58:31Z master 9d01f657b3) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This is a tarai program
Run`./ruby tarai_ractor.rb 2 8` is to use 2 thread to run 8 times tarai function total, that means 4 times tarai for each ractor(thread).

```
GC.disable

def split_len(len, split)
    ret = []
    mod = len % split
    head = 0
    tail = 0
    split.times do |i|
        if head >= len
            break
        end
        k = 0
        if i < mod then k = 1 end
        tail = tail + (len/split) + k
        ret.append(head...tail)
        head = tail
    end
    return ret
end

def ary_split(ary, split)
    return split_len(ary.length,split)
end
def item_check(item)
    if item[0] != nil
        1 + item_check(item[0]) + item_check(item[1])
    else
        1
    end
end


def tarai(x, y, z) =
    x <= y ? y : tarai(tarai(x-1, y, z),
                       tarai(y-1, z, x),
                       tarai(z-1, x, y))
  
times = ARGV[0].to_i
split = ARGV[1].to_i

p split_len(times, split)
split_len(times, split).each.map do |sp|
    Ractor.new (sp) {
        s = _1
        s.each do 
         tarai(13, 7, 0) 
        end
    }
end.each(&:take)
```
The problem is in ruby 3.1.2 and ruby 3.3
`./ruby tarai_ractor.rb 1 1` has simiular execute time with `./ruby tarai_ractor.rb 8 8` because each thread only run 1 time of tarai function, like follow:

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]:
```
time ruby exp_ractor_tarai.rb 1 1
[0...1]
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.

real    0m1.442s
user    0m1.429s
sys     0m0.014s

time ruby exp_ractor_tarai.rb 8 8
[0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8]
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.

real    0m1.857s
user    0m13.817s
sys     0m0.041s
```


But in ruby master(ruby 3.4.0dev) 
ruby 3.4.0dev (2024-05-14T01:58:31Z master 9d01f657b3) [x86_64-linux]
1 ractor 1 tarai:
```
time ../ruby exp_ractor_tarai.rb 1 1

`RubyGems' were not loaded.
`error_highlight' was not loaded.
`did_you_mean' was not loaded.
`syntax_suggest' was not loaded.
[0...1]
exp_ractor_tarai.rb:47: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.

real    0m1.671s
user    0m1.666s
sys     0m0.005s
```

8 ractor 8 tarai:

```
time ../ruby exp_ractor_tarai.rb 8 8

`RubyGems' were not loaded.
`error_highlight' was not loaded.
`did_you_mean' was not loaded.
`syntax_suggest' was not loaded.
[0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8]
exp_ractor_tarai.rb:47: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.

real    0m18.408s
user    1m58.659s
sys     0m0.021s
```
And in ruby 3.4.0dev when run `time ../ruby exp_ractor_tarai.rb 16 16` 16 thread should be used in system monitoring while only 8 threads are used.
Ruby 3.3 and Ruby 3.1.2 do not have this problem.


---Files--------------------------------
thead16_16.png (168 KB)
thread16_8.png (165 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-01-10  3:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14  9:00 [ruby-dev:52086] [Ruby master Bug#20489] Ractor behavior strange in ruby master nekoyama32767 (Jinsong Yu) via ruby-dev
2024-09-20  1:10 ` [ruby-dev:52115] " hsbt (Hiroshi SHIBATA) via ruby-dev
2025-01-08 22:01 ` [ruby-dev:52135] " luke-gru (Luke Gruber) via ruby-dev
2025-01-08 23:27 ` [ruby-dev:52136] " tenderlovemaking (Aaron Patterson) via ruby-dev
2025-01-09  0:04 ` [ruby-dev:52137] " tenderlovemaking (Aaron Patterson) via ruby-dev
2025-01-09  0:22 ` [ruby-dev:52138] " tenderlovemaking (Aaron Patterson) via ruby-dev
2025-01-09  1:11 ` [ruby-dev:52139] " tenderlovemaking (Aaron Patterson) via ruby-dev
2025-01-09  4:58 ` [ruby-dev:52140] " nekoyama32767 (Jinsong Yu) via ruby-dev
2025-01-09  5:16 ` [ruby-dev:52141] " nekoyama32767 (Jinsong Yu) via ruby-dev
2025-01-09  5:47 ` [ruby-dev:52142] " nekoyama32767 (Jinsong Yu) via ruby-dev
2025-01-09 19:14 ` [ruby-dev:52143] " tenderlovemaking (Aaron Patterson) via ruby-dev
2025-01-10  1:13 ` [ruby-dev:52144] " luke-gru (Luke Gruber) via ruby-dev
2025-01-10  3:47 ` [ruby-dev:52145] " nekoyama32767 (Jinsong Yu) via ruby-dev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).