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