Server sent events, Puma, Rails and max dedicated threads for each client Server sent events, Puma, Rails and max dedicated threads for each client multithreading multithreading

Server sent events, Puma, Rails and max dedicated threads for each client


I am actually working on a project where we went with polling because of the open connection issues. We figured it would be easier to just poll every three seconds, then keep a connection open and hanging. But the data freshness requirement weren't very strict being three seconds, so it was doable, and kind of silly to waste a thread for three seconds.

So unless you have very strict requirements for data freshness, and/or have a restricted user base, and/or ability to have a lot of threads, regular polling is normally the way to go.

And on the other hand if they are going to be constantly hitting your server, and it would take longer to poll the data again then your data freshness requirement, you might as well keep the connection open to avoid having to deal with the whole stack again.

Also in puma 2, you can also run it in cluster mode, which means it spawns an addition workers with there own threads and you can end up with Workers X Threads = Total Threads. Which might help in your calculations.

https://github.com/puma/puma#clustered-mode