HAProxy and customer Mongrel Handler for Health check

From: Ladislav Martincik <ladislav.martincik#gmail.com>
Date: Thu, 4 Sep 2008 11:42:30 +0100


Hello guys,

I'm using HAProxy for our project in company I work for. The application is written with *Ruby and Rails* and we really love HAProxy for Low balancing among Mongrels. One problem we have right now is unnecessary trafic caused by HAProxy *Health check with OPTION* requests sending *"http:// / "* or*"http://:/
"*. I've tried to modify standard configuration of health checks to send request to particular *URI "/health_check" *and because I wanted to not have the log full of unnecessary log informations of healt checks I've decided to write custom *Mongrel handler* to send plain text with timestamp. The problem is that it didn't worked for me and I still have "http:// / " requests inside our production log. I'll paste all config files and source codes here so you can have a look and hopefully help me find the problem why isn't working as it should be.

We're using HAProxy* 1.3.15.2 released 2008/06/21*.

I've *compiled and installed* HAProxy with this steps: cd /usr/src/
sudo wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.2.tar.gz sudo tar zxvf haproxy-1.3.15.2.tar.gz
sudo aptitude install libpcre++-dev
sudo make TARGET=linux26 CPU=i386 USE_STATIC_PCRE=1 sudo make install

Here *HAProxy* *configuration* I'm using right now:

global
  daemon
  maxconn 4096 # total max connections (dependent on ulimit)

  nbproc            2               # number of processing cores
  pidfile           /var/run/haproxy.pid

defaults
  mode              http
  clitimeout        2m              # maximum inactivity time on the client
side
  srvtimeout        2m              # maximum inactivity time on the server
side
  timeout connect   4s              # maximum time to wait for a connection
attempt to a server to succeed

  option httpclose # disable keepalive (HAProxy does not yet support the HTTP keep-alive mode)
  option abortonclose # enable early dropping of aborted requests from pending queue

# option            httpchk
  *option            httpchk HEAD /health_check HTTP/1.0*
  option            forwardfor      # enable insert of X-Forwarded-For
headers
  option            httplog
  option            abortonclose
  retries           3
  option            redispatch


  balance           roundrobin      # each server is used in turns,
according to assigned weight
  stats enable                      # enable web-stats at /haproxy?stats
  stats auth        admin:xxxxxx  # force HTTP Auth to view stats
  stats refresh     5s                    # refresh rate of stats page

listen aeryn_proxy 127.0.0.1:8100
  log global
# - equal weights on all servers
# - maxconn will queue requests at HAProxy if limit is reached
# - minconn dynamically scales the connection concurrency (bound my
maxconn) depending on size of HAProxy queue
# - check health every 20000 microseconds

  server mongrel_0  127.0.0.1:8000 weight 1 maxconn 1 check inter 20000
  server mongrel_1  127.0.0.1:8001 weight 1 maxconn 1 check inter 20000
  server mongrel_2  127.0.0.1:8002 weight 1 maxconn 1 check inter 20000
  server mongrel_3  127.0.0.1:8003 weight 1 maxconn 1 check inter 20000

Here's my custom *Mongrel handler:

*class HealthCheckHandler < Mongrel::HttpHandler   def process(request, response)
    response.start(200) do |head, out|

      head["Content-Type"] = "text/html"
      out.write Time.now

    end
  end
end

uri '/health_check', :handler => HealthCheckHandler.new, :in_front => true

I'll appreciate any help or feedback.

Thank you, Ladislav Martincik Received on 2008/09/04 12:42

This archive was generated by hypermail 2.2.0 : 2008/09/04 12:45 CEST