config.threadsafe!
和Puma
非常容易实现的功能。假设我有以下控制器:
class ConcurrentController < ApplicationController
def index
sleep 10000
end
def show
end
end
之前我可以使用puma -t 2:16 -p 3000
(用于至少2个线程,端口为3000)启动puma,并访问index
和show
页面,且show
页面能正常渲染。
但是在Rails 4中,如果我尝试做同样的事情,Puma会在index
请求上锁定,导致show
页面无法渲染。当我停止服务器时,Puma会给我这个错误:
Rack app error: #<ThreadError: Attempt to unlock a mutex which is locked by another thread>
我在Rails 4中如何实现并发?不需要使用
config.threadsafe!
(即使尝试使用也没有任何影响),请问我还需要做什么?
config/environments/development.rb
中将config.cache_classes = false
,但是没有遇到这个问题。 - kbridge4096-w 2
。这将启动两个应用程序实例来处理请求。 - Joshua Pinter