Using thin for concurrent requests
Asked Answered
E

1

6

I have a Rails 4.1 application with a simple controller which streams a response:

class ServerSentEventsController < ApplicationController
  include ActionController::Live

  def index
    response.headers['Content-Type'] = 'text/event-stream'
    sse = ServerSentEvent.new(response.stream)

    begin
      loop do
        sse.write(time: Time.now)
        sleep 1
      end
    rescue IOError
      # When the client disconnects, we'll get an IOError on write
    ensure
      sse.close
    end
  end
end

When I add puma to my gemfile and make a request against this route using curl I get a streamed response as expected:

curl -i 'http://localhost:3000/sse'
<!-- truncated headers output -->    
data: {"time":"2014-08-29 05:16:00 +0100"}

data: {"time":"2014-08-29 05:16:01 +0100"}

data: {"time":"2014-08-29 05:16:02 +0100"}

When I switch to thin in my gemfile and make a request the whole thing locks up. I've read in multiple places that thin can handle concurrent requests but I can't seem to make it work.

I'm starting puma simply by running bundle exec rails server. For thin I've tried bundle exec rails server and multiple configurations like bundle exec thin start -a 127.0.0.1 -threaded. Nothing seems to prevent thin from locking up.

How can I get thin to accept concurrent requests?

Ephraimite answered 29/8, 2014 at 4:21 Comment(11)
I have this working just fine over here. Adding the thin gem allows you do to rails s and you'll see when the server starts it says Booting Thin. I'm checking concurrency with ab as curl is only doing single requests.Ainslie
did you maybe forget to use two dashes? --threaded Call the Rack application in threads [experimental]Gagliardi
hey @David would uploading my sample project and showing you the ab output be sufficient here?Ainslie
@Ainslie I personally don't need the answer anymore since the problem was occurring on a test project which I've since abandoned. I'm not sure if it's me or ardavis who get's to award the bounty now. It was ardavis who opened it.Ephraimite
@Gagliardi I can't remember now. I'd guess that would generate an unexpected option error but I could be wrong.Ephraimite
you should delete the question thenGagliardi
@Gagliardi I can't find any instructions which say that I should delete my own questions just because I'm no longer personally interested in the answer. If an answer does come along it can still provide value to the community. I'm also not inclined to delete a question that a third-party has opened a bounty on. Can you point me to a meta post or help topic which adds evidence to your claim that I should delete the question?Ephraimite
if you don't provide further infos, how is anybody ever going to answer this? plus i think it was a user mistake because me and others had thin running in a multithreaded manner whatsoever.Gagliardi
Have you played with your environment as pointed here #15441802 ?Crawford
I apologize for not being around to comment on this. I added the bounty. This question was the exact issue I was having. With 'thin' my server would hang up when I tried to use Rails `ActionController::Live. With 'puma' I had no issues, but I had read that thin should work.Darbydarce
The environment @ruyrocha pointed out seems to work, although extremely unfortunate.Darbydarce
R
1

I had the same issue and I had to start the server like this

  bundle exec thin start -a 127.0.0.1 --threaded -e production
Rutheruthenia answered 7/1, 2015 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.