Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails using Websockets with Nginx and Unicorn?

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?

like image 877
user782220 Avatar asked Feb 16 '13 02:02

user782220


1 Answers

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.

like image 82
D-side Avatar answered Nov 07 '22 23:11

D-side