我有一个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当我将puma添加到我的gemfile中并使用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并发出请求时,整个程序都锁定了。我在很多地方读到过thin可以处理并发请求,但我似乎不能让它工作。
我只是通过运行bundle exec rails server来启动puma。对于thin,我尝试了bundle exec rails server和像bundle exec thin start -a 127.0.0.1 -threaded这样的多种配置。似乎没有什么能阻止thin锁定。
如何使用thin来接受并发请求?
发布于 2015-01-08 04:51:23
我遇到了同样的问题,我必须像这样启动服务器
bundle exec thin start -a 127.0.0.1 --threaded -e productionhttps://stackoverflow.com/questions/25561673
复制相似问题