Feature #20276
closedIntroduce Fiber interfaces for Blocking operations on Ractors
Description
Motivation¶
I am trying to build a web server with Ractors. The lifecycle for a request in the current implementation is
- main ractor sends request to worker ractor
- worker ractor handles response
- worker ractor sends response to main ractor
- main ractor writes response
- 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.