I’d like to share some concepts with community regarding asynchronous
operations in Rails, hoping for feedback and advice.
We (Helicon Tech) currently work on Ruby on Rails implementation for
Microsoft IIS. Our goal is to make RoR available for shared Windows
hostings and developers. We currently work with several small hostings
to implement RoR shared hosting solution with them as proof of
So I was thinking… since we already have a working asynchronous server
implementation and asynchronous (after some tweaking) implementation
of FastCGI, we may utilize it to bring async into the RoR
Our concept is quite easy. I will show it on a simple chat application
example: Our server creates a fiber and puts a Rack call into the
fiber body, so all RoR code, like controller is executed inside a
fiber. There is a script to wait for new messages, which simply yields
(suspends) a fiber. So there could be number, maybe thousands of
suspended fibers at a time. When new message is received it is put
into the storage and all fibers waiting for it are resumed. They
process messages, return responses to their clients and then clients
makes another request to a wait script.
We have working proof of concept for it, but I need a feedback from
the community. Whether this future is needed at all and what possible
problems and flaws I need to take into consideration?
Also I am thinking on how to extend this concept to bring more
asynchronous operations into RoR. Imagine we have some time consuming
operation in the script. Like we are requesting whether forecast data
from remote server for analysis. We could start an asynchronous http
request operation, setting up a resume of current fiber as a callback,
and then suspend current fiber, allowing other requests to be served.
Such system could handle much more load that a synchronous system.
Unfortunately I cannot find appropriate concept of asynchronous
operations for Ruby – how to do an async HTTP request? Some use
'eventmachine' to do this. But while providing some asynchronous
operation support inside event loop, the loop itself completely blocks
execution thread. I think we may try to put our entire client-server
conversation into the event loop, need to try it first.
Anyway any feedback and suggestions are greatly appreciated.