Skip to content

Commit

Permalink
Added back ActionController::Base.allow_concurrency flag and moved lo…
Browse files Browse the repository at this point in the history
…ck down to controller processing.
  • Loading branch information
josh committed Jul 28, 2008
1 parent a5db148 commit 19db0b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*Edge*

* Added back ActionController::Base.allow_concurrency flag [Josh Peek]

* AbstractRequest.relative_url_root is no longer automatically configured by a HTTP header. It can now be set in your configuration environment with config.action_controller.relative_url_root [Josh Peek]

* Update Prototype to 1.6.0.2 #599 [Patrick Joyce]
Expand Down
15 changes: 14 additions & 1 deletion actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ class Base
@@debug_routes = true
cattr_accessor :debug_routes

# Indicates whether to allow concurrent action processing. Your
# controller actions and any other code they call must also behave well
# when called from concurrent threads. Turned off by default.
@@allow_concurrency = false
cattr_accessor :allow_concurrency

@@guard = Monitor.new

# Modern REST web services often need to submit complex data to the web application.
# The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
# <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
Expand Down Expand Up @@ -537,7 +545,12 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
forget_variables_added_to_assigns

log_processing
send(method, *arguments)

if @@allow_concurrency
send(method, *arguments)
else
@@guard.synchronize { send(method, *arguments) }
end

assign_default_content_type_and_charset
response.prepare! unless component_request?
Expand Down
18 changes: 7 additions & 11 deletions actionpack/lib/action_controller/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module ActionController
# Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true.
class Dispatcher
@@guard = Mutex.new

class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
Expand Down Expand Up @@ -101,15 +99,13 @@ def initialize(output = $stdout, request = nil, response = nil)
end

def dispatch
@@guard.synchronize do
begin
run_callbacks :before_dispatch
handle_request
rescue Exception => exception
failsafe_rescue exception
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
begin
run_callbacks :before_dispatch
handle_request
rescue Exception => exception
failsafe_rescue exception
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
end

Expand Down

4 comments on commit 19db0b7

@Roman2K
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the whole Rails framework now actually thread-safe so that we can have a multithreaded Rails app with ActionController::Base.allow_concurrency = ActiveRecord::Base.allow_concurrency = true?

@josh
Copy link
Contributor Author

@josh josh commented on 19db0b7 Jul 29, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Routes are (as of a5db148), so I moved the lock down. ActiveRecord connection pool is not committed yet, so no.

@NZKoz
Copy link
Member

@NZKoz NZKoz commented on 19db0b7 Jul 29, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AR still needs to merge the connection pool work from nick sieger, and of course we need to test the hell out of it.

You’re almost guaranteed to get better per-meg-of-memory performance with passenger and ruby-enterprise-edition than with a threaded mongrel or whatever. However it should help out the jruby guys.

@Roman2K
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh & NZKoz
OK. I didn’t know about Nick Sieger’s connection_pool branch. Thanks!

Please sign in to comment.