I am considering implementing chess (which needs websockets) with Rails, and in production deployment using Nginx as a reverse proxy to a bunch of Unicorn processes.
In thinking about how to make that work led me to have the following questions:
As far as I understand websockets are a persistent connection. Since everything goes through the reverse proxy Nginx how exactly would a Unicorn worker process maintain a websocket connection to a client browser? Would Nginx maintain state about which Unicorn process each browser websocket is connected to and act as a kind of intermediary? Does keeping a persistent websocket connection in a Unicorn process block the entire worker process?
Is there a recommended way to implementing chess (with websockets) using Rails?
Connecting synchronous processing by Unicorn with asynchronous delivery using nginx would imply some logic on nginx side that seems at least awkward to me. At most - impossible.
There is a Railscast about Private Pub gem that makes use of Thin webserver. It's way more suitable for this task: it's asynchronous, it's able to handle many concurrent requests with event-based IO. So I suggest you replace Unicorn with Thin or install Thin side-by-side.
Puma webserver might also be an option, however, I can't give more info about that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With