3 ms·
I've been enjoying using Puma in clustered mode for some production sites, but falling back to Thin for Server Sent Events (new EventSource()) - does anyone kno
by justkez 13y ago
I've been enjoying using Puma in clustered mode for some production sites, but falling back to Thin for Server Sent Events (new EventSource()) - does anyone know if this is ever likely to come to Puma, or is there a fundamental reason that the Puma process model can't support SSE?
- andrewhavens 13y agoSounds more like a problem with your implementation. I'm pretty sure Puma can handle SSE just fine. Your implementation probably depends on EventMachine which is not baked in like it is with Thin.
- justkez 13y agoI'm doing: content_type "text/event-stream" stream(:keep_open) { |out| settings.connections << out } From Sinatra, which I assume is then deferring to EventMachine, courtesy of Thin. I'll see if there's a way of forcing EM directly in to the Stream setup...thanks for the pointer.
- FooBarWidget 13y agoI'm one of the authors behind Phusion Passenger (https://www.phusionpassenger.com/ https://www.phusionpassenger.com/), a polyglot web server for Ruby, Python and Node.js. We recently wrote a demo demonstrating SSE on Phusion Passenger (https://github.com/phusion/passenger-ruby-server-side-events-demo https://github.com/phusion/passenger-ruby-server-side-events...). During writing of this demo, we found out that sinatra-contrib's streaming code relies on EventMachine. That means that sinatra-contrib's streaming only works on EventMachine-based servers, like Thin and on Goliath. Based on my knowledge about Puma, I'm pretty sure SSE works fine on Puma as well. The Phusion Passenger SSE demo uses the Rack socket hijacking API (which we've blogged about: http://blog.phusion.nl/2013/01/23/the-new-rack-socket-hijacking-api/ http://blog.phusion.nl/2013/01/23/the-new-rack-socket-hijack...) to implement SSE. This approach should work on Puma as well because it supports the Rack socket hijacking API too.
- sad 13y agoI created a sample app using Puma and Celluloid to work through similar troubles I was having with Sinatra's streams and Puma. If it helps, it's here: https://github.com/sdeming/cellfun https://github.com/sdeming/cellfun. This does not use EventMachine, depending instead on Celluloid. I work primarily in JRuby and EventMachine has always tripped me up.
- evilduck 13y agoTenderlove has a blog post about SSEs using Puma. http://tenderlovemaking.com/2012/07/30/is-it-live.html http://tenderlovemaking.com/2012/07/30/is-it-live.html
- cmer 13y agoAre you doing so with MRI/Ruby 2.0? Been considering Puma over Unicorn since it works so well for one of our JRuby apps but was wondering about how it would perform on MRI since it seems like it was never really designed with MRI in mind.
- jrochkind1 13y agoWhen I tried to benchmark a standardized app under MRI, I found that Puma works great _if_ your app is io-bound as opposed to cpu-bound. This makes sense because multi-threading is still a win under MRI even with the GIL, only so long as your app is io-bound (so threads can be switched out when waiting on io, for instance waiting on a db query). Most web apps I've worked with tend to be io-bound. https://github.com/jrochkind/fake_work_app/blob/master/README.md https://github.com/jrochkind/fake_work_app/blob/master/READM...