Zbatery/Rainbows keepalive problem?

Jake Douglas jakecdouglas at gmail.com
Fri Nov 26 23:35:16 EST 2010

On Wed, Nov 24, 2010 at 2:14 PM, Eric Wong <normalperson at yhbt.net> wrote:
> Jake Douglas <jakecdouglas at gmail.com> wrote:
>> On Wed, Nov 24, 2010 at 1:17 PM, Eric Wong <normalperson at yhbt.net> wrote:
>> > Jake Douglas <jakecdouglas at gmail.com> wrote:
>> >> I am using zbatery with ThreadPool and just upgraded to 0.5.0, which
>> >> subsequently upgraded rainbows to 2.0.0 and unicorn to 3.0.0. My
>> >> browser(s) now hangs for a while during each request. I noticed some
>> >
>> > Are you setting a Content-Length or Transfer-Encoding in your app?
>> >
>> > You can add Rack::Chunked and Rack::ContentLength middlewares to your
>> > config (some frameworks like Rails already do this, I think).
>> >
>> > Which versions of Zbatery/Rainbows!/Unicorn were you using before which
>> > exhibited this?  Rainbows!/Zbatery has supported keepalive for some time
>> > and none of the three servers ever included
>> > Rack::Chunked/Rack::ContentLength in its middleware stack by default.
>> I was using zbatery 0.4.0, Unicorn 2.0.1, unsure of the rainbows
>> version. This is a Rails 3.0.3 app and I am not setting any headers
>> myself. Are you saying that Rails is doing something that is causing
>> the problem? Please bear with me, as I am not familiar with the
>> details of how keep alive works.
> <top posting corrected>
> Responses without keepalive don't need additional headers since the
> server just closes the connection to notify the client.
> HTTP/1.1 with keepalive requires a Content-Length (or Transfer-Encoding:
> chunked) header to determine response boundaries, otherwise clients
> would never know when one response ends and another begins.
> The normal Rails "render" path already seems[1] to add Content-Length;
> are you doing something else to send responses from Rails?
> Including the Rack::Chunked/Rack::ContentLength middlewares (at the top
> of the middleware stack) should solve all your problems.
> If you only serve HTTP/1.1, you can probably get away with only
> Rack::Chunked...
> [1] - I haven't had a chance to test this myself
> --
> Eric Wong

I am not doing anything special to send responses from Rails, only 'render'.

I can see in my browser that keep-alive is set, and Content-Length is
also set. It looks like the first couple requests finish quickly, and
then the remaining take an additional 5 seconds each. It seems the
browser is hanging for the default keep-alive timeout of 5 seconds on
each request before proceeding. This happens with different browsers.

Is there additional information I can provide to give better insight
into why this is happening?


More information about the rainbows-talk mailing list