From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B39311F518 for ; Tue, 14 May 2024 09:01:58 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=cQADIzRU; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=hsb9JXsz; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id AB11884A02; Tue, 14 May 2024 09:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1715677301; bh=aBCnUfvSUa9z7zoCJt8Y4fOMQdHG71xO2FTTSuHWMuQ=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=cQADIzRUdnYqcNvMg5FpGOEi0cLl3EiTdsneUydU29+oRqG5MPVVZ4aNOANld+01x Cm4pVXBPE6vKXawqRAp35Jmi0JIKkBi29CchSn1cNAoz6+VzQ2dMtX8E+4kdj9E5TE BAC1F+2gAe5QXMDd4WtNDNACKz/yhzveJvvLofAA= Received: from s.wfbtzhsw.outbound-mail.sendgrid.net (s.wfbtzhsw.outbound-mail.sendgrid.net [159.183.224.105]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 87D74849E0 for ; Tue, 14 May 2024 09:00:25 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=hsb9JXsz; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=NIkd7cNc/FW4uusuExB64wiJx6C7a1tBeePko95hA7c=; b=hsb9JXszs0cbHweljAZ2WJ4YBDk6oCZYDzUtgJVTCQL1QziHbY19oRxDsx8lbSyOTUqM V8nfWvp63OkBx+czM2CC1TEoN0UTLtPssN/Pr/vMtCBbjYu/SJfSRwFgsJaaqHScfVONpm 8+rbESbiBuAcDzqKKAkWHGHeZNdHiNU34EPQaHJ2APWxW1qiWAcO+dr4ZeMkABxkwXeahJ AS2RpqA9dGTJFGQ7eWcvUdj+C09t6X+hkwdLVw+QlnojAoC6tGFHA6m/eUV91yW8wa0imh mrR1mbvFYoQ1t+GdaOUVmdbsuEqNaaGXmQKcDxloppFvfontsze4MYhR5jylPipA== Received: by filterdrecv-6576d68dbc-25vfq with SMTP id filterdrecv-6576d68dbc-25vfq-1-66432828-2F 2024-05-14 09:00:24.530900566 +0000 UTC m=+1246796.361795565 Received: from herokuapp.com (unknown) by geopod-ismtpd-20 (SG) with ESMTP id WsyO_mA8SzGySzyku65lvw for ; Tue, 14 May 2024 09:00:24.487 +0000 (UTC) Date: Tue, 14 May 2024 09:00:24 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20489 X-Redmine-Issue-Author: nekoyama32767 X-Redmine-Issue-Priority: Normal X-Redmine-Sender: nekoyama32767 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 94475 X-SG-EID: =?us-ascii?Q?u001=2EGXX7sv9RhnxNIUDyl2wW8t+eg5y1Gpa4gL7BdURBC20VYAHe9SKO8T8p7?= =?us-ascii?Q?GP27zkkIQrTegF1GrgMWRCKa7bUivsfG+IIlqFA?= =?us-ascii?Q?DZV7sW8l8vjrWrFUcfR++5O9Mpiat4O3DJ3XIxW?= =?us-ascii?Q?WjqNGqkNEUnP5U=2F4dUKfOtDD9mgNKaQBhqFYB44?= =?us-ascii?Q?O1fPmxz+G7alAT0EnlacXHoZYA1150HqnKK3I+Z?= =?us-ascii?Q?YC2W5Kip8NkR1+mMyGbY5Qg3iF20opNDZ5LAQn2?= =?us-ascii?Q?kiUIzg7R3dL+TAzCAHjXzOU4Wg=3D=3D?= To: ruby-dev@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: KMSZRYHMT4S4VBUZINGM5RM7FOVMLTMA X-Message-ID-Hash: KMSZRYHMT4S4VBUZINGM5RM7FOVMLTMA X-MailFrom: bounces+313651-12dc-ruby-dev=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: "Ruby developers (Japanese)" Subject: =?utf-8?q?=5Bruby-dev=3A52086=5D_?= [Ruby master Bug#20489] Ractor behavior strange in ruby master List-Id: "Ruby developers (Japanese)" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "nekoyama32767 (Jinsong Yu) via 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] :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] :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/