How can I serve requests concurrently with Rails 4?

后端 未结 3 1560
感动是毒
感动是毒 2020-12-08 01:03

I\'m trying to serve multiple requests concurrently in Rails 4, something I was able to do very easily with config.threadsafe! and Puma in Rails 3.

3条回答
  •  天命终不由人
    2020-12-08 01:20

    It seems that by default, in Rails 4, concurrent requests are not enabled in the Development environment.

    I found this quote in the documentation.

    Rack::Lock wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when config.cache_classes is false.

    Which means that if config.cache_classes = false (which it is by default in dev env) we can't have concurrent requests.

    Concurrent requests do work with my example in production environment.

    One solution is to set config.cache_classes = true in the development environment, but then the code doesn't reload on a change, which doesn't really work for development.

    The second kind of hacky solution is to disable the Rack::Lock middleware in development.

    So if you were to add in development.rb the following line:

    config.middleware.delete Rack::Lock
    

    you should be able to have concurrent requests in development environment with cache classes disabled.

提交回复
热议问题