Project

General

Profile

Actions

Feature #20276

closed

Introduce Fiber interfaces for Blocking operations on Ractors

Added by forthoney (Seong-Heon Jung) 3 months ago. Updated 2 months ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:116827]

Description

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.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0