From: "tenderlovemaking (Aaron Patterson) via ruby-dev" <ruby-dev@ml.ruby-lang.org>
To: ruby-dev@ml.ruby-lang.org
Cc: "tenderlovemaking (Aaron Patterson)" <noreply@ruby-lang.org>
Subject: [ruby-dev:52136] [Ruby master Bug#20489] Ractor behavior strange in ruby master
Date: Wed, 08 Jan 2025 23:27:55 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-111373.20250108232754.51663@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20489.20240514090024.51663@ruby-lang.org>
Issue #20489 has been updated by tenderlovemaking (Aaron Patterson).
Status changed from Assigned to Feedback
I also can't seem to reproduce this:
```
[aaron@tc-lan-adapter ~/g/ruby (master)]$ time ruby -v test.rb 8 8
ruby 3.3.4 (2024-07-16 revision 425e468d25) [arm64-darwin23]
[0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8]
test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
________________________________________________________
Executed in 5.97 secs fish external
usr time 28.54 secs 78.00 micros 28.54 secs
sys time 0.14 secs 736.00 micros 0.14 secs
[aaron@tc-lan-adapter ~/g/ruby (master)]$ chruby ruby-3.4.1
[aaron@tc-lan-adapter ~/g/ruby (master)]$ time ruby -v test.rb 8 8
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24]
[0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8]
test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
________________________________________________________
Executed in 6.42 secs fish external
usr time 28.45 secs 0.09 millis 28.45 secs
sys time 0.09 secs 1.33 millis 0.08 secs
[aaron@tc-lan-adapter ~/g/ruby (master)]$ time ./ruby -v test.rb 8 8
ruby 3.5.0dev (2025-01-08T20:42:35Z master 96f23306f0) +PRISM [arm64-darwin24]
[0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8]
test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
________________________________________________________
Executed in 6.04 secs fish external
usr time 28.74 secs 0.10 millis 28.74 secs
sys time 0.10 secs 1.31 millis 0.10 secs
```
----------------------------------------
Bug #20489: Ractor behavior strange in ruby master
https://bugs.ruby-lang.org/issues/20489#change-111373
* Author: nekoyama32767 (Jinsong Yu)
* Status: Feedback
* Assignee: ko1 (Koichi Sasada)
* 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/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
next prev parent reply other threads:[~2025-01-08 23:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 9:00 [ruby-dev:52086] " 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 ` tenderlovemaking (Aaron Patterson) via ruby-dev [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-111373.20250108232754.51663@ruby-lang.org \
--to=ruby-dev@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).