diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 6df7c568dc..3a276d5aad 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added config.threadsafe! to toggle allow concurrency settings and disable the dependency loader [Josh Peek] + * Turn cache_classes on by default [Josh Peek] * Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers [Josh Peek] diff --git a/railties/environments/production.rb b/railties/environments/production.rb index e915e8be73..ec5b7bc865 100644 --- a/railties/environments/production.rb +++ b/railties/environments/production.rb @@ -4,6 +4,9 @@ # Code is not reloaded between requests config.cache_classes = true +# Enable threaded mode +# config.threadsafe! + # Use a different logger for distributed setups # config.logger = SyslogLogger.new diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index e876481cf1..f8b3a78dff 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -768,6 +768,18 @@ Run `rake gems:install` to install the missing gems. ::RAILS_ROOT.replace @root_path end + # Enable threaded mode. Allows concurrent requests to controller actions and + # multiple database connections. Also disables automatic dependency loading + # after boot + def threadsafe! + self.cache_classes = true + self.dependency_loading = false + self.active_record.allow_concurrency = true + self.action_controller.allow_concurrency = true + self.to_prepare { Rails.cache.threadsafe! } + self + end + # Loads and returns the contents of the #database_configuration_file. The # contents of the file are processed via ERB before being sent through # YAML::load.