WEBrick はマルチスレッドですが、Rails 開発者はミューテックスをハードコーディングしているため、一度に 1 つのリクエストしか処理できません。モンキー パッチRails::Server
を適用すると、マルチスレッドの WEBrick を自由に実行できます。
WEBrick は、configconfig.cache_classes = true
とconfig.eager_load = true
の場合にのみマルチスレッド化されることに注意してください。これはRAILS_ENV=production
. これは、開発中のクラスの再ロードがスレッドセーフではないためです。
Rails 4.0 で WEBrick を完全にマルチスレッド化するには、これを に追加するだけconfig/initializers/multithreaded_webrick.rb
です:
# Remove Rack::Lock so WEBrick can be fully multi-threaded.
require 'rails/commands/server'
class Rails::Server
def middleware
middlewares = []
middlewares << [Rails::Rack::Debugger] if options[:debugger]
middlewares << [::Rack::ContentLength]
Hash.new middlewares
end
end
削除した問題のあるコードrails/commands/server.rb
は次のとおりです。
# FIXME: add Rack::Lock in the case people are using webrick.
# This is to remain backwards compatible for those who are
# running webrick in production. We should consider removing this
# in development.
if server.name == 'Rack::Handler::WEBrick'
middlewares << [::Rack::Lock]
end
Rails 4.2 では必要ありません。それはすぐに使用できる同時実行です。