Yarin
Yarin

Reputation: 183919

Do SSE / long-polling connections tie up Unicorn processes on Heroku?

We've got a Rails app running on Unicorn/Heroku, with Unicorn configured to handle 3 concurrent worker processes.

We've also got delayed job set up, to asynchronously handle some long-running file processing tasks that get triggered by a client request.

We want to update the client when the task completes. We could do this with traditional polling, but are looking into using the new EventSource HQ Heroku add-on in order increase responsiveness and reduce the overhead of unnecessary HTTP polling requests.

EventSource HQ uses a mix of SSE and long-polling to ensure cross-browser compatibility. What I'm trying to figure out is if the connection that gets opened up by EventSource HQ ties up a Unicorn worker process for the lifetime of the connection? In other words, if I have 3 concurrent long-running tasks processing through EventSource HQ connections, is my web dyno unable to receive new requests?

Upvotes: 4

Views: 1248

Answers (1)

Joe Martinez
Joe Martinez

Reputation: 854

If you used something like EventSource, then no it would not block an Unicorn process for each connected client. This is because it is using a pub/sub model. The clients get subscribed to an EventSource socket(which you create from the server and pass the socket id to the client) which your server publishes to whenever it has events(like completing a job).

Now, if you want to implement your own pub/sub API, that is also fairly easy with node.js or non-blocking frameworks like Goliath

Upvotes: 1

Related Questions