From a89ccf321224f3248ddd00bb0edb320311604e4e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 11 Nov 2010 02:16:50 +0800 Subject: configurator: enable "rewindable_input" directive 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. --- lib/unicorn/configurator.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'lib/unicorn/configurator.rb') 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 env["rack.input"] 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 + # env["rack.input"] 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 -- cgit v1.2.3-24-ge0c7