diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-11-11 02:16:50 +0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-11-11 07:18:20 +0800 |
commit | a89ccf321224f3248ddd00bb0edb320311604e4e (patch) | |
tree | 669d6af1eee6c70d72bdeba6f77d9a7114cf54ed /lib/unicorn/configurator.rb | |
parent | 7d44b5384758aeddcb49d7606a9908308df7c698 (diff) | |
download | unicorn-a89ccf321224f3248ddd00bb0edb320311604e4e.tar.gz |
This allows users to override the current Rack spec and disable the rewindable input requirement. This can allow applications to use less I/O to minimize the performance impact when processing uploads.
Diffstat (limited to 'lib/unicorn/configurator.rb')
-rw-r--r-- | lib/unicorn/configurator.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index dd515a7..2a83dea 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -39,6 +39,7 @@ class Unicorn::Configurator }, :pid => nil, :preload_app => false, + :rewindable_input => true, # for Rack 2.x: (Rack::VERSION[0] <= 1), } #:startdoc: @@ -373,12 +374,22 @@ class Unicorn::Configurator # cause the master process to exit with an error. def preload_app(bool) - case bool - when TrueClass, FalseClass - set[:preload_app] = bool - else - raise ArgumentError, "preload_app=#{bool.inspect} not a boolean" - end + set_bool(:preload_app, bool) + end + + # Toggles making <code>env["rack.input"]</code> rewindable. + # Disabling rewindability can improve performance by lowering + # I/O and memory usage for applications that accept uploads. + # Keep in mind that the Rack 1.x spec requires + # <code>env["rack.input"]</code> to be rewindable, so this allows + # intentionally violating the current Rack 1.x spec. + # + # +rewindable_input+ defaults to +true+ when used with Rack 1.x for + # Rack conformance. When Rack 2.x is finalized, this will most + # likely default to +false+ while still conforming to the newer + # (less demanding) spec. + def rewindable_input(bool) + set_bool(:rewindable_input, bool) end # Allow redirecting $stderr to a given path. Unlike doing this from @@ -469,6 +480,15 @@ private end end + def set_bool(var, bool) #:nodoc: + case bool + when true, false + set[var] = bool + else + raise ArgumentError, "#{var}=#{bool.inspect} not a boolean" + end + end + def set_hook(var, my_proc, req_arity = 2) #:nodoc: case my_proc when Proc |