Unicorn and HAProxy, 500 Internal errors after checks

Eric Wong normalperson at yhbt.net
Wed Dec 1 23:59:11 EST 2010

Lawrence Pit <lawrence.pit at gmail.com> wrote:
> Eric Wong <normalperson at yhbt.net> wrote:
>> HAProxy starts writing request bodies to Unicorn as soon as the upload
>> starts,
> Is that also true when the nginx upload module is used? (assuming nginx  
> sits between HAProxy and the unicorns, otherwise it doesn't make sense  
> anyways). Unicorn is only hit after the complete upload is finished by  
> nginx. I would assume this wouldn't be different if HAProxy is put in  
> front of all the nginx servers.

I would setup a test and confirm.  You can do this trivially with the
following Rack app:

  use Rack::ContentLength
  use Rack::ContentType
  run lambda { |env|
    input = env['rack.input']
    buf = input.each do |line|
      # each line is printed as Unicorn receives it,
      # if Unicorn is behind nginx, the times for each
      # line should be roughly/exactly the same.
      puts "#{Time.now} #{line.inspect}"
    [ 200, {}, [] ]

And then telnetting or netcatting to your frontend, and typing the
following (no leading spaces, use a proper hostname for vhosts):

  PUT / HTTP/1.1
  Host: example.com
  Content-Length: 6

...and then hit Enter a few times while watching your Unicorn
terminal/logs.  If you delay between hitting the Enter nginx
should be buffering that.

> keep-alive options are in HAProxy since 1.4
> There is further new development on this front if you're using SSL. See  
> the first quick news section at http://haproxy.1wt.eu/ :
> "The main advantage over the x-forwarded-for patch is that it now  
> supports keep-alive"


Eric Wong

More information about the mongrel-unicorn mailing list