From 1dc79837c336ad8cb4762746acc6a489b8932c81 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 10 May 2009 18:59:43 -0700 Subject: app/exec_cgi: use explicit buffers for read/sysread This reduces garbage generation to improve performance. Rack 1.0 allows InputWrapper to read with an explicit buffer. --- lib/unicorn/app/exec_cgi.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb index d98b3e4..2c71df9 100644 --- a/lib/unicorn/app/exec_cgi.rb +++ b/lib/unicorn/app/exec_cgi.rb @@ -95,8 +95,9 @@ module Unicorn::App # Allows +out+ to be used as a Rack body. def out.each sysseek(@unicorn_app_exec_cgi_offset) + buf = '' begin - loop { yield(sysread(CHUNK_SIZE)) } + loop { yield(sysread(CHUNK_SIZE, buf)) } rescue EOFError end end @@ -126,7 +127,8 @@ module Unicorn::App tmp.binmode # Rack::Lint::InputWrapper doesn't allow sysread :( - while buf = inp.read(CHUNK_SIZE) + buf = '' + while inp.read(CHUNK_SIZE, buf) tmp.syswrite(buf) end tmp.sysseek(0) -- cgit v1.2.3-24-ge0c7