4
我有一個簡單的控制器一個Rails 4.1的應用程序,流響應使用薄:當我添加puma我的Gemfile和使用作出反對這條路線的請求curl
,我收到了流的併發請求
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
響應預期:
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
開始美洲獅。對於瘦我試過bundle exec rails server
和多種配置,如bundle exec thin start -a 127.0.0.1 -threaded
。似乎沒有任何東西可以防止瘦身。
我如何才能接受併發請求?
我有這方面的工作就好在這裏。添加'thin' gem允許你做'rails s',你會看到服務器什麼時候啓動它,它會顯示'Booting Thin'。我正在用'ab'檢查併發性,因爲curl只做單個請求。 – Anthony 2014-11-05 22:03:39
你可能忘記使用兩個破折號? '--threaded在線程中調用Rack應用程序[實驗]' – phoet 2014-11-05 22:23:44
hey @David會上傳我的示例項目並向您顯示'ab'輸出在這裏足夠了嗎? – Anthony 2014-11-06 14:46:35