Hi, I know that Unicorn forces TCP disconnection as it''s explained at
the top of lib/unicorn/http_response.rb:
# A design decision was made to force the client to not pipeline or
# keepalive requests. HTTP/1.1 pipelining really kills the
# performance due to how it has to be handled and how unclear the
# standard is. To fix this the HttpResponse always gives a
# "Connection: close" header which forces the client to close right
# away. The bonus for this is that it gives a pretty nice speed boost
# to most clients since they can close their connection immediately.
However I want to try TCP permanent connections from the client (or a
proxy) to Unicorn. I''ve tryed to modify same file as above by changing
at the end:
# Remove "Connection: close":
socket.write("HTTP/1.1 #{status}\r\n" \
"Date: #{Time.now.httpdate}\r\n" \
"Status: #{status}\r\n" \
"#{out.join('''')}\r\n")
end
body.each { |chunk| socket.write(chunk) }
# Don''t close the socket:
#socket.close # flushes and uncorks the socket immediately
ensure
body.respond_to?(:close) and body.close
But of course this is not enough and it fails. Not sure what exactly
happens, it seems that a Unicorn worker doesn''t process requests
anymore until replying the first response.
So I would like to know if it''s feasible to make Unicorn work in
persistent mode.
NOTE: I already know that the current design is really good, better
than using persistent connections, but I want to experiment with
persistent connections for other purposes I will explain in a future.
Thanks a lot.
--
I?aki Baz Castillo
<ibc at aliax.net>
I?aki Baz Castillo <ibc at aliax.net> wrote:> Hi, I know that Unicorn forces TCP disconnection as it''s explained at > the top of lib/unicorn/http_response.rb: > > # A design decision was made to force the client to not pipeline or > # keepalive requests. HTTP/1.1 pipelining really kills the > # performance due to how it has to be handled and how unclear the > # standard is. To fix this the HttpResponse always gives a > # "Connection: close" header which forces the client to close right > # away. The bonus for this is that it gives a pretty nice speed boost > # to most clients since they can close their connection immediately. > > > However I want to try TCP permanent connections from the client (or a > proxy) to Unicorn. I''ve tryed to modify same file as above by changing > at the end:<snip>> But of course this is not enough and it fails. Not sure what exactly > happens, it seems that a Unicorn worker doesn''t process requests > anymore until replying the first response. > > So I would like to know if it''s feasible to make Unicorn work in > persistent mode. > NOTE: I already know that the current design is really good, better > than using persistent connections, but I want to experiment with > persistent connections for other purposes I will explain in a future.Hi I?aki, Unicorn won''t try to read further requests from the socket (see process_client() in lib/unicorn.rb). However, you can use Rainbows! without specifying a concurrency model at all (or "use :Base"). That way you''ll get proper HTTP/1.1 keepalive support and you can control keepalive_timeout: # both of these values are the defaults for unconfigured Rainbows! Rainbows! do use :Base keepalive_timeout 5 end -- Eric Wong
2010/4/16 Eric Wong <normalperson at yhbt.net>:> Hi I?aki, > > Unicorn won''t try to read further requests from the socket (see > process_client() in lib/unicorn.rb).Ok, understood now.> However, you can use Rainbows! without specifying a concurrency model at > all (or "use :Base"). ?That way you''ll get proper HTTP/1.1 keepalive > support and you can control keepalive_timeout: > > # both of these values are the defaults for unconfigured Rainbows! > Rainbows! do > ?use :Base > ?keepalive_timeout 5 > endGreat! Thanks a lot. -- I?aki Baz Castillo <ibc at aliax.net>