ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "forthoney (Seong-Heon Jung) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "forthoney (Seong-Heon Jung)" <noreply@ruby-lang.org>
Subject: [ruby-core:117217] [Ruby master Feature#20276] Introduce Fiber interfaces for Blocking operations on Ractors
Date: Mon, 18 Mar 2024 19:09:35 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-107303.20240318190935.53072@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20276.20240217205535.53072@ruby-lang.org

Issue #20276 has been updated by forthoney (Seong-Heon Jung).


ioquatix (Samuel Williams) wrote in #note-7:
> If I had to take a guess, I'd say it's a bug with waiting on a Ractor while handling signals?

Under closer inspection, the `Thread#join` workaround should work in theory but actually deadlocks in practice, likely due to an implementation bug. [Here](https://bugs.ruby-lang.org/issues/20346)'s the relevant bug report. IRB is likely unresponsive because of this deadlock.

----------------------------------------
Feature #20276: Introduce Fiber interfaces for Blocking operations on Ractors
https://bugs.ruby-lang.org/issues/20276#change-107303

* Author: forthoney (Seong-Heon Jung)
* Status: Feedback
----------------------------------------
### Motivation
I am trying to build a web server with Ractors. The lifecycle for a request in the current implementation is 

1. main ractor sends request to worker ractor
2. worker ractor handles response
3. worker ractor sends response to main ractor
4. main ractor writes response
5. repeat

The main ractor utilizes the Async gem (specifically async-http) to handle connections concurrently, meaning each request is handled on a separate fiber.
The issue I am running into is after I send a request to a worker ractor, I need to do a blocking wait until I receive a response.
While I am waiting for the response, I cannot take any more connections.


### Solution
If the fiber scheduler had a hook for `Ractor.receive` or `Ractor#take` (both of which are blocking), the main ractor can send the message, handle other connections while the worker processes the request. When the worker produces a message, it will then take the reqeust and write it in the socket. Specifically, I think the `block` and `unblock` hooks should be implemented for Ractors, considering Threads and Mutexes already use them.




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

      parent reply	other threads:[~2024-03-18 19:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17 20:55 [ruby-core:116827] [Ruby master Feature#20276] Introduce Fiber interfaces for Ractors forthoney (Seong-Heon Jung) via ruby-core
2024-02-19  1:40 ` [ruby-core:116836] [Ruby master Feature#20276] Introduce Fiber interfaces for Blocking operations on Ractors ko1 (Koichi Sasada) via ruby-core
2024-02-19 18:20 ` [ruby-core:116850] " forthoney (Seong-Heon Jung) via ruby-core
2024-03-11 23:06 ` [ruby-core:117102] " ioquatix (Samuel Williams) via ruby-core
2024-03-12  4:58 ` [ruby-core:117108] " forthoney (Seong-Heon Jung) via ruby-core
2024-03-12  5:00 ` [ruby-core:117109] " forthoney (Seong-Heon Jung) via ruby-core
2024-03-12 21:25 ` [ruby-core:117123] " ioquatix (Samuel Williams) via ruby-core
2024-03-18 19:09 ` forthoney (Seong-Heon Jung) via ruby-core [this message]

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-107303.20240318190935.53072@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.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 read-only IMAP folder(s) and NNTP newsgroup(s).