Ha Proxy Best Practice
Ha Proxy Best Practice
HAProxy Technologies
HAProxy best practice
EMEA Headquarters
3, rue du petit Robinson
ZAC des Metz
78350 Jouy en Josas
France
http://www.haproxy.com
Source: http://fr.slideshare.net/Docker/docker-opensourceathon-2015
+-----------------------------------------------------------------------------------------------------------+
| |
| +----------+ |
| | HAProxy | |
| | | |
| +----------+ |
| +--------+ TCP | kernel | TCP +--------+ |
| | client | <----------> | | <----------> | server | |
| +--------+ connection +----------+ connection +--------+ |
| |
+-----------------------------------------------------------------------------------------------------------+
+-----------------------------------------------------------------------------------------------------------+
| |
| +---+ |
| | | client |
| +---+ |
| /___/ |
| | |
| V |
| H +----------+ |
| A | frontend | listnening IP:port and protocol definition, HTTP validation, |
| P | | backend selection |
| r +----------+ |
| o | backend | server monitoring, load-balancing, queueing |
| x | | |
| y +----------+ |
| | |
| V |
| +--------+ |
| | server | |
| +--------+ |
| |
+-----------------------------------------------------------------------------------------------------------+
non-exhaustive list!!
defaults
mode http
timeout client 10s
timeout connect 4s
timeout server 30s
frontend fe
bind 10.0.0.1:80
bind 10.0.0.1:443 ssl crt ./my.pem
default_backend be
backend be
server s1 10.0.0.101:80 check
server s2 10.0.0.102:80 check
[WARNING] 177/011147 (8652) : Setting tune.ssl.default-dh-param to 1024 by default, if your workload permits it
Configuration file is valid
NOTE: this does not prevent you from reading the F.ck.ng manual :)
iptables tuning:
• net.netfilter.nf_conntrack_max = 131072
=> when improperly configured, conntrack will prevent HAProxy from reaching high performance.
NOTE: just enabling iptables with connection tracking takes 20% of CPU, even with no rules.
DEMO #2 !!!
defaults
log global # 'pointer' to the global section
option httplog
backend be
option httplog
DEMO #3 !!!
Other timeouts:
• timeout queue : how long a request can remain in the queue
• timeout tarpit : how long the tarpitted connection is maintained
• Configuration example for a TCP service with long time connections (POP, IMAP, etc)
defaults HTTP
mode http
timeout client 1m
timeout connect 4s
timeout server 1m
timeout client-fin 1s
timeout server-fin 1s
DEMO #4 !!!
• When multiple strings are given to the fetch, a logical implicit OR is applied:
hdr_end(Host) -i .domain.com .domain.fr .domain.net .domain.org
• Mutliple ACLs can have the same name, a logical OR is then applied:
acl myapi path_beg -i /api/
acl myapi hdr_beg(Host) -i api.
use_backend bk_api if myapi
DEMO #5 !!!
DEMO #6 !!!
• Simply setup maxconn parameters on the server line statement in HAProxy's backend
• there are no magic values. Benchmarking the application is the only way
• From our experience, maxconn value is from 50 to 300
DEMO #7 !!!
• When different workloads are expected, it is possible to route requests to different backends with
different maxconn values
frontend f_myapp
use_backend b_light if { path_beg /api/ /foo/ /bar/ }
use_backend b_heavy if { path_beg /search /massivefoo /heavybar }
backend b_light
server s1 server1:80 maxconn 300
backend b_heavy
server s1 server1:80 maxconn 10
• Stats page is per process! In case of nbproc > 1, it is recommended to create one stats page or one
UNIX socket per process
• in case of nbproc > 1, one unix path and one TCP port should be provided per process
DEMO #8 !!!