簡體   English   中英

對並發請求使用thin

[英]Using thin for concurrent requests

我有一個Rails 4.1應用程序,帶有一個簡單的控制器,可以響應:

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

當我向我的gemfile添加puma並使用curl對此路由發出請求時,我得到了預期的流式響應:

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"}

當我在我的gemfile中切換到thin並發出請求時,整個事情都會鎖定。 我已經在多個地方讀過,瘦可以處理並發請求,但我似乎無法使它工作。

我只是通過運行bundle exec rails server啟動puma。 對於瘦我已經嘗試了bundle exec rails server和多個配置,如bundle exec thin start -a 127.0.0.1 -threaded 似乎沒有什么能阻止瘦身鎖定。

如何輕松接受並發請求?

我有同樣的問題,我必須像這樣啟動服務器

  bundle exec thin start -a 127.0.0.1 --threaded -e production

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM