透明思考


Transparent Thoughts


Move To Multi-threaded Rails

When doing performance in local box, we found that requests are waiting to be processed due to Railsissingle-threaded by default. We changed the configuration to enable multi-threaded mode as describedin this blogentry:

Thread safety for your Rails

(also refer toRails 2.2 releasenotes)

The most important change was to eager-load /lib directory, and thus move libraries for test out ofit.

config.threadsafe! also disables automatic loading by ActiveSupport::Dependencies.Alternatively, youcan just add lib/ directory to eager load paths. The following inside production.rb will do that :
config.eager_load_paths  “#{RAILS_ROOT}/lib”

We had some rough tests to ensure the functionality is not broken. Multi-threaded mode also mightrequire morememory than single-threaded mode. Still keep testing.