Ruby on rails 使用thin处理并发请求
我有一个Rails 4.1应用程序,它带有一个简单的控制器,可以流式传输响应:Ruby on rails 使用thin处理并发请求,ruby-on-rails,ruby,multithreading,ruby-on-rails-4,thin,Ruby On Rails,Ruby,Multithreading,Ruby On Rails 4,Thin,我有一个Rails 4.1应用程序,它带有一个简单的控制器,可以流式传输响应: class ServerSentEventsController < ApplicationController include ActionController::Live def index response.headers['Content-Type'] = 'text/event-stream' sse = ServerSentEvent.new(response.stream
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中切换到并发出请求时,整个过程都会锁定。我在多个地方读到thin可以处理并发请求,但我似乎无法让它工作
我只是通过运行bundle exec rails server
来启动puma。对于thin,我尝试了bundle-exec-rails服务器
和多种配置,如bundle-exec-thin-start-a 127.0.0.1-threaded
。似乎没有什么能阻止thin锁定
我怎样才能让瘦服务器接受并发请求呢?我也遇到了同样的问题,我不得不像这样启动服务器
bundle exec thin start -a 127.0.0.1 --threaded -e production
我这里的工作很好。添加
thin
gem允许您执行rails
操作,您将看到服务器启动时,它会显示Booting thin
。我正在用ab
检查并发性,因为curl只处理单个请求。您可能忘记使用两个破折号了吗<代码>--线程调用线程中的框架应用程序[实验]嘿@David上传我的示例项目并向您展示ab
输出是否足够?@phoet我找不到任何说明,说明我应该删除我自己的问题,因为我个人对答案不再感兴趣。如果答案确实出现,它仍然可以为社区提供价值。我也不想删除第三方悬赏的问题。你能给我指出一个元帖子或帮助主题,它为你的主张增加了证据,我应该删除这个问题吗?你有没有像这里指出的那样玩弄过你的环境?
bundle exec thin start -a 127.0.0.1 --threaded -e production