Question
Can you use thin
with ActionController::Live
to implement server-side events (SSE) and long polling? If so, how?
Context
Although the name is a repetition. How do I get the Rails 4 ActionController :: Live Broadcast, working with Thin and Ruby 2? And how do Tin and Puma scale live? , OP tormented the water by asking two questions, and this question has not received an answer.
Several other posts suggest that you can use thin
for server side events (sse) if you run it through exec thin start --threaded
: Does Heroku support ActionController :: Live? and Are puma the only multi-threaded rails of 4 http servers? , Aaron seminal http://tenderlovemaking.com/2012/07/30/is-it-live.html and Ryan are consistently reliable http://railscasts.com/episodes/401-actioncontroller-live?view=asciicast . But even if I copy the Railscast example, I was not able to get it to work with thin
.
What i tried
# ----------------------------------------------------------------
_
# ---------------------------------------------------------------- # file: config/environments/development.rb Rails.application.configure do ... snip ... # see http:
_
# ---------------------------------------------------------------- # file: app/controllers/widgets_controller.rb class WidgetsController < ApplicationController include ActionController::Live # GET /widgets/events # see http:
_
# ----------------------------------------------------------------
Launch
In the shell A window:
$ bundle install Chalcedony[~/Projects/heroku-sample/widget-worker]$ thin start
Then in shell window B:
$ curl --no-buffer localhost:3000/widgets/events
In the shell A window, I see a request and responses that spit out at intervals of one second (there is one second delay between 0...
and 1...
and 2...
). It's good:
GET /widgets/events HTTP/1.1 User-Agent: curl/7.37.1 Host: localhost:3000 Accept: */* HTTP/1.1 200 OK X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Cache-Control: no-cache Content-Type: text/html; charset=utf-8 X-Request-Id: 95e64eb6-ee21-4e97-a33a-dbf579b3027c X-Runtime: 0.066925 Connection: close Server: thin 0... <delay...> 1... <delay...> 2... <delay...>
But in the shell B window, the printout is delayed and appears immediately. The same thing happens when I view a page in Chrome. Could you configure some settings correctly?
PS :.
$ rake about About your application environment Ruby version 2.1.4-p265 (x86_64-darwin14.0) RubyGems version 2.2.2 Rack version 1.5 Rails version 4.1.8 JavaScript Runtime JavaScriptCore Active Record version 4.1.8 Action Pack version 4.1.8 Action View version 4.1.8 Action Mailer version 4.1.8 Active Support version 4.1.8 Middleware Rack::Sendfile, ActionDispatch::Static, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fb0cb4ae1a0>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag Environment development Database adapter postgresql Database schema version 20141213003938
PPS
Right now you might be thinking, "Why aren't you using puma
like everyone else?" Good question. Right now, I cannot build puma pearls on my machine for reasons that I did not understand. And I use thin
in most applications deployed in my heroku application, so I like it. If I can not lose weight, I will put more effort into creating puma.