HAProxy Version 1.6
HAProxy Version 1.6
HAProxy Version 1.6
HAProxy
Search...
Keyboard navigation:
Enabled
Starter Guide
version 1.6.5
(http://www.haproxy.org/)
This document doesn't provide any configuration help nor hint, but it explains
where to find the relevant documents. The summary below is meant to help you
search sections by name and navigate through the document.
Note to documentation contributors :
This document is formatted with 80 columns per line, with even number of
spaces for indentation and without tabs. Please follow these rules strictly
so that it remains easily printable everywhere. If you add sections, please
update the summary below for easier searching.
Summary
1.
Available documentation
2.
Introduction to HAProxy
What HAProxy is and is not
3.2.
How HAProxy works
3.3.
Basic features
3.3.1.
Proxying
3.3.2.
SSL
3.3.3.
Monitoring
3.3.4.
High availability
3.3.5.
Load balancing
3.3.6.
Stickiness
3.3.7.
Sampling and converting information
3.3.8.
Maps
3.3.9.
ACLs and conditions
3.3.10.
Content switching
3.3.11.
Stick-tables
3.3.12.
Formated strings
3.3.13.
HTTP rewriting and redirection
3.3.14.
Server protection
3.3.15.
Logging
3.3.16.
Statistics
3.4.
Advanced features
3.4.1.
Management
3.4.2.
System-specic capabilities
3.4.3.
Scripting
3.5.
Sizing
3.6.
How to get HAProxy
3.
3.1.
4.
4.1.
4.2.
4.3.
4.4.
Top
1.
Available documentation
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
1/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
2/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Top
Summary
Proxy-based load balancers are deployed as a server with their own IP address
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
3/26
6/20/2016
Search...
Keyboard navigation:
Enabled
and ports, without architecture changes. Sometimes this requires to perform some
adaptations to the applications so that clients are properly directed to the
load balancer's IP address and not directly to the server's. Some load balancers
may have to adjust some servers' responses to make this possible (eg: the HTTP
Location header field used in HTTP redirects). Some proxy-based load balancers
may intercept traffic for an address they don't own, and spoof the client's
address when connecting to the server. This allows them to be deployed as if
they were a regular router or firewall, in a cut-through mode very similar to
the packet based load balancers. This is particularly appreciated for products
which combine both packet mode and proxy mode. In this case DSR is obviously
still not possible and the return traffic still has to be routed back to the
load balancer.
A very scalable layered approach would consist in having a front router which
receives traffic from multiple load balanced links, and uses ECMP to distribute
this traffic to a first layer of multiple stateful packet-based load balancers
(L4). These L4 load balancers in turn pass the traffic to an even larger number
of proxy-based load balancers (L7), which have to parse the contents to decide
what server will ultimately receive the traffic.
The number of components and possible paths for the traffic increases the risk
of failure; in very large environments, it is even normal to permanently have
a few faulty components being fixed or replaced. Load balancing done without
awareness of the whole stack's health significantly degrades availability. For
this reason, any sane load balancer will verify that the components it intends
to deliver the traffic to are still alive and reachable, and it will stop
delivering traffic to faulty ones. This can be achieved using various methods.
The most common one consists in periodically sending probes to ensure the
component is still operational. These probes are called "health checks". They
must be representative of the type of failure to address. For example a pingbased check will not detect that a web server has crashed and doesn't listen to
a port anymore, while a connection to the port will verify this, and a more
advanced request may even validate that the server still works and that the
database it relies on is still accessible. Health checks often involve a few
retries to cover for occasional measuring errors. The period between checks
must be small enough to ensure the faulty component is not used for too long
after an error occurs.
Other methods consist in sampling the production traffic sent to a destination
to observe if it is processed correctly or not, and to evince the components
which return inappropriate responses. However this requires to sacrify a part
of the production traffic and this is not always acceptable. A combination of
these two mechanisms provides the best of both worlds, with both of them being
used to detect a fault, and only health checks to detect the end of the fault.
A last method involves centralized reporting : a central monitoring agent
periodically updates all load balancers about all components' state. This gives
a global view of the infrastructure to all components, though sometimes with
less accuracy or responsiveness. It's best suited for environments with many
load balancers and many servers.
Layer 7 load balancers also face another challenge known as stickiness or
persistence. The principle is that they generally have to direct multiple
subsequent requests or connections from a same origin (such as an end user) to
the same target. The best known example is the shopping cart on an online
store. If each click leads to a new connection, the user must always be sent
to the server which holds his shopping cart. Content-awareness makes it easier
to spot some elements in the request to identify the server to deliver it to,
but that's not always enough. For example if the source address is used as a
key to pick a server, it can be decided that a hash-based algorithm will be
used and that a given IP address will always be sent to the same server based
on a divide of the address by the number of available servers. But if one
server fails, the result changes and all users are suddenly sent to a different
server and lose their shopping cart. The solution against this issue consists
in memorizing the chosen target so that each time the same visitor is seen,
he's directed to the same server regardless of the number of available servers.
The information may be stored in the load balancer's memory, in which case it
may have to be replicated to other load balancers if it's not alone, or it may
be stored in the client's memory using various methods provided that the client
is able to present this information back with every request (cookie insertion,
redirection to a sub-domain, etc). This mechanism provides the extra benefit of
not having to rely on unstable or unevenly distributed information (such as the
source IP address). This is in fact the strongest reason to adopt a layer 7
load balancer instead of a layer 4 one.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
4/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Since a layer 7 load balancer may perform a number of complex operations on the
traffic (decrypt, parse, modify, match cookies, decide what server to send to,
etc), it can definitely cause some trouble and will very commonly be accused of
being responsible for a lot of trouble that it only revealed. Often it will be
discovered that servers are unstable and periodically go up and down, or for
web servers, that they deliver pages with some hard-coded links forcing the
clients to connect directly to one specific server without passing via the load
balancer, or that they take ages to respond under high load causing timeouts.
That's why logging is an extremely important aspect of layer 7 load balancing.
Once a trouble is reported, it is important to figure if the load balancer took
a wrong decision and if so why so that it doesn't happen anymore.
3.
Introduction to HAProxy
3.1.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
5/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Top
- a web server : during startup, it isolates itself inside a chroot jail and
drops its privileges, so that it will not perform any single file-system
access once started. As such it cannot be turned into a web server. There
Summary
are excellent open-source software for this such as Apache or Nginx, and
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
6/26
6/20/2016
Search...
Keyboard navigation:
Enabled
- a packet-based load balancer : it will not see IP packets nor UDP datagrams,
will not perform NAT or even less DSR. These are tasks for lower layers.
Some kernel-based components such as IPVS (Linux Virtual Server) already do
this pretty well and complement perfectly with HAProxy.
3.2.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
7/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Top
Frontends and backends are sometimes considered as half-proxies, since they only
look at one side of an end-to-end connection; the frontend only cares about the
clients while the backend only cares about the servers. HAProxy also supports
full proxies which are exactly the union of a frontend and a backend. When HTTP
processing is desired, the configuration will generally be split into frontends
and backends as they open a lot of possibilities since any frontend may pass a
connection to any backend. With TCP-only proxies, using frontends and backends
Summary
rarely provides a benefit and the configuration can be more readable with full
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
8/26
6/20/2016
3.3.
Search...
Keyboard navigation:
Enabled
Basic features
This section will enumerate a number of features that HAProxy implements, some
of which are generally expected from any modern load balancer, and some of
which are a direct benefit of HAProxy's architecture. More advanced features
will be detailed in the next section.
3.3.1.
Proxying is the action of transferring data between a client and a server over
two independant connections. The following basic features are supported by
HAProxy regarding proxying and connection management :
- Provide the server with a clean connection to protect them against any
client-side defect or attack;
- Listen to multiple IP address and/or ports, even port ranges;
- Transparent accept : intercept traffic targetting any arbitrary IP address
that doesn't even belong to the local system;
- Server port doesn't need to be related to listening port, and may even be
translated by a fixed offset (useful with ranges);
- Transparent connect : spoof the client's (or any) IP address if needed
when connecting to the server;
- Provide a reliable return IP address to the servers in multi-site LBs;
- Offload the server thanks to buffers and possibly short-lived connections
to reduce their concurrent connection count and their memory footprint;
- Optimize TCP stacks (eg: SACK), congestion control, and reduce RTT impacts;
- Support different protocol families on both sides (eg: IPv4/IPv6/Unix);
- Timeout enforcement : HAProxy supports multiple levels of timeouts depending
on the stage the connection is, so that a dead client or server, or an
attacker cannot be granted resources for too long;
- Protocol validation: HTTP, SSL, or payload are inspected and invalid
protocol elements are rejected, unless instructed to accept them anyway;
- Policy enforcement : ensure that only what is allowed may be forwarded;
- Both incoming and outgoing connections may be limited to certain network
namespaces (Linux only), making it easy to build a cross-container,
multi-tenant load balancer;
- PROXY protocol presents the client's IP address to the server even for
non-HTTP traffic. This is an HAProxy extension that was adopted by a number
of third-party products by now, at least these ones at the time of writing :
- client : haproxy, stud, stunnel, exaproxy, ELB, squid
- server : haproxy, stud, postfix, exim, nginx, squid, node.js, varnish
3.3.2.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
9/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.3.3.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
10/26
6/20/2016
Search...
Keyboard navigation:
Enabled
- Health checks support two hysteresis for up and down transitions in order
to protect against state flapping;
- Checks can be sent to a different address/port/protocol : this makes it
easy to check a single service that is considered representative of multiple
ones, for example the HTTPS port for an HTTP+HTTPS server.
- Servers can track other servers and go down simultaneously : this ensures
that servers hosting multiple services can fail atomically and that noone
will be sent to a partially failed server;
- Agents may be deployed on the server to monitor load and health : a server
may be interested in reporting its load, operational status, administrative
status independantly from what health checks can see. By running a simple
agent on the server, it's possible to consider the server's view of its own
health in addition to the health checks validating the whole path;
- Various check methods are available : TCP connect, HTTP request, SMTP hello,
SSL hello, LDAP, SQL, Redis, send/expect scripts, all with/without SSL;
- State change is notified in the logs and stats page with the failure reason
(eg: the HTTP response received at the moment the failure was detected). An
e-mail can also be sent to a configurable address upon such a change ;
- Server state is also reported on the stats interface and can be used to take
routing decisions so that traffic may be sent to different farms depending
on their sizes and/or health (eg: loss of an inter-DC link);
- HAProxy can use health check requests to pass information to the servers,
such as their names, weight, the number of other servers in the farm etc...
so that servers can adjust their response and decisions based on this
knowledge (eg: postpone backups to keep more CPU available);
- Servers can use health checks to report more detailed state than just on/off
(eg: I would like to stop, please stop sending new visitors);
- HAProxy itself can report its state to external components such as routers
or other load balancers, allowing to build very complete multi-path and
multi-layer infrastructures.
3.3.4.
Just like any serious load balancer, HAProxy cares a lot about availability to
ensure the best global service continuity :
- Only valid servers are used ; the other ones are automatically evinced from
load balancing farms ; under certain conditions it is still possible to
force to use them though;
- Support for a graceful shutdown so that it is possible to take servers out
of a farm without affecting any connection;
- Backup servers are automatically used when active servers are down and
replace them so that sessions are not lost when possible. This also allows
to build multiple paths to reach the same server (eg: multiple interfaces);
- Ability to return a global failed status for a farm when too many servers
are down. This, combined with the monitoring capabilities makes it possible
for an upstream component to choose a different LB node for a given service;
- Stateless design makes it easy to build clusters : by design, HAProxy does
its best to ensure the highest service continuity without having to store
information that could be lost in the event of a failure. This ensures that
a takeover is the most seamless possible;
- Integrates well with standard VRRP daemon keepalived : HAProxy easily tells
keepalived about its state and copes very will with floating virtual IP
addresses. Note: only use IP redundancy protocols (VRRP/CARP) over clusterbased solutions (Heartbeat, ...) as they're the ones offering the fastest,
most seamless, and most reliable switchover.
Top
Summary
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
11/26
6/20/2016
HAProxy offers a fairly complete set of load balancing features, most of which
are unfortunately not available in a number of other load balancing products :
Search...
Keyboard navigation:
Enabled
- no less than 9 load balancing algorithms are supported, some of which apply
to input data to offer an infinite list of possibilities. The most common
ones are round-robin (for short connections, pick each server in turn),
leastconn (for long connections, pick the least recently used of the servers
with the lowest connection count), source (for SSL farms or terminal server
farms, the server directly depends on the client's source address), uri (for
HTTP caches, the server directly depends on the HTTP URI), hdr (the server
directly depends on the contents of a specific HTTP header field), first
(for short-lived virtual machines, all connections are packed on the
smallest possible subset of servers so that unused ones can be powered
down);
- all algorithms above support per-server weights so that it is possible to
accommodate from different server generations in a farm, or direct a small
fraction of the traffic to specific servers (debug mode, running the next
version of the software, etc);
- dynamic weights are supported for round-robin, leastconn and consistent
hashing ; this allows server weights to be modified on the fly from the CLI
or even by an agent running on the server;
- slow-start is supported whenever a dynamic weight is supported; this allows
a server to progressively take the traffic. This is an important feature
for fragile application servers which require to compile classes at runtime
as well as cold caches which need to fill up before being run at full
throttle;
- hashing can apply to various elements such as client's source address, URL
components, query string element, header field values, POST parameter, RDP
cookie;
- consistent hashing protects server farms against massive redistribution when
adding or removing servers in a farm. That's very important in large cache
farms and it allows slow-start to be used to refill cold caches;
- a number of internal metrics such as the number of connections per server,
per backend, the amount of available connection slots in a backend etc makes
it possible to build very advanced load balancing strategies.
3.3.6.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
12/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.3.7.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
13/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.3.8.
3.3.9.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
14/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.3.10.
3.3.11.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
15/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Stick tables may use 3 different types of samples for their keys : integers,
strings and addresses. Only one stick-table may be referenced in a proxy, and it
is designated everywhere with the proxy name. Up to 8 key may be tracked in
parallel. The server identifier is committed during request or response
processing once both the key and the server are known.
Stick-table contents may be replicated in active-active mode with other HAProxy
nodes known as "peers" as well as with the new process during a reload operation
so that all load balancing nodes share the same information and take the same
routing decision if a client's requests are spread over multiple nodes.
Since stick-tables are indexed on what allows to recognize a client, they are
often also used to store extra information such as per-client statistics. The
extra statistics take some extra space and need to be explicitly declared. The
type of statistics that may be stored includes the input and output bandwidth,
the number of concurrent connections, the connection rate and count over a
period, the amount and frequency of errors, some specific tags and counters,
etc... In order to support keeping such information without being forced to
stick to a given server, a special "tracking" feature is implemented and allows
to track up to 3 simultaneous keys from different tables at the same time
regardless of stickiness rules. Each stored statistics may be searched, dumped
and cleared from the CLI and adds to the live troubleshooting capabilities.
While this mechanism can be used to surclass a returning visitor or to adjust
the delivered quality of service depending on good or bad behaviour, it is
mostly used to fight against service abuse and more generally DDoS as it allows
to build complex models to detect certain bad behaviours at a high processing
speed.
3.3.12.
There are many places where HAProxy needs to manipulate character strings, such
as logs, redirects, header additions, and so on. In order to provide the
greatest flexibility, the notion of formated strings was introduced, initially
for logging purposes, which explains why it's still called "log-format". These
strings contain escape characters allowing to introduce various dynamic data
including variables and sample fetch expressions into strings, and even to
adjust the encoding while the result is being turned into a string (for example,
adding quotes). This provides a powerful way to build header contents or to
customize log lines. Additionally, in order to remain simple to build most
common strings, about 50 special tags are provided as shortcuts for information
commonly used in logs.
3.3.13.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
16/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.3.14.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
17/26
6/20/2016
Search...
Keyboard navigation:
Enabled
HAProxy does a lot to maximize service availability, and for this it deploys
large efforts to protect servers against overloading and attacks. The first
and most important point is that only complete and valid requests are forwarded
to the servers. The initial reason is that HAProxy needs to find the protocol
elements it needs to stay synchronized with the byte stream, and the second
reason is that until the request is complete, there is no way to know if some
elements will change its semantics. The direct benefit from this is that servers
are not exposed to invalid or incomplete requests. This is a very effective
protection against slowloris attacks, which have almost no impact on HAProxy.
Another important point is that HAProxy contains buffers to store requests and
responses, and that by only sending a request to a server when it's complete and
by reading the whole response very quickly from the local network, the server
side connection is used for a very short time and this preserves server
resources as much as possible.
A direct extension to this is that HAProxy can artificially limit the number of
concurrent connections or outstanding requests to a server, which guarantees
that the server will never be overloaded even if it continuously runs at 100% of
its capacity during traffic spikes. All excess requests will simply be queued to
be processed when one slot is released. In the end, this huge resource savings
most often ensures so much better server response times that it ends up actually
being faster than by overloading the server. Queued requests may be redispatched
to other servers, or even aborted in queue when the client aborts, which also
protects the servers against the "reload effect", where each click on "reload"
by a visitor on a slow-loading page usually induces a new request and maintains
the server in an overloaded state.
The slow-start mechanism also protects restarting servers against high traffic
levels while they're still finalizing their startup or compiling some classes.
Regarding the protocol-level protection, it is possible to relax the HTTP parser
to accept non stardard-compliant but harmless requests or responses and even to
fix them. This allows bogus applications to be accessible while a fix is being
developped. In parallel, offending messages are completely captured with a
detailed report that help developers spot the issue in the application. The most
dangerous protocol violations are properly detected and dealt with and fixed.
For example malformed requests or responses with two Content-length headers are
either fixed if the values are exactly the same, or rejected if they differ,
since it becomes a security problem. Protocol inspection is not limited to HTTP,
it is also available for other protocols like TLS or RDP.
When a protocol violation or attack is detected, there are various options to
respond to the user, such as returning the common "HTTP 400 bad request",
closing the connection with a TCP reset, faking an error after a long delay
("tarpit") to confuse the attacker. All of these contribute to protecting the
servers by discouraging the offending client from pursuing an attack that
becomes very expensive to maintain.
HAProxy also proposes some more advanced options to protect against accidental
data leaks and session crossing. Not only it can log suspicious server responses
but it will also log and optionally block a response which might affect a given
visitors' confidentiality. One such example is a cacheable cookie appearing in a
cacheable response and which may result in an intermediary cache to deliver it
to another visitor, causing an accidental session sharing.
3.3.15.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
18/26
6/20/2016
Search...
Keyboard navigation:
Enabled
HAProxy provides very detailed logs, with millisecond accuracy and the exact
connection accept time that can be searched in firewalls logs (eg: for NAT
correlation). By default, TCP and HTTP logs are quite detailed an contain
everything needed for troubleshooting, such as source IP address and port,
frontend, backend, server, timers (request receipt duration, queue duration,
connection setup time, response headers time, data transfer time), global
process state, connection counts, queue status, retries count, detailed
stickiness actions and disconnect reasons, header captures with a safe output
encoding. It is then possible to extend or replace this format to include any
sampled data, variables, captures, resulting in very detailed information. For
example it is possible to log the number cumulated requests for this client or
the number of different URLs for the client.
The log level may be adjusted per request using standard ACLs, so it is possible
to automatically silent some logs considered as pollution and instead raise
warnings when some abnormal behaviour happen for a small part of the traffic
(eg: too many URLs or HTTP errors for a source address). Administrative logs are
also emitted with their own levels to inform about the loss or recovery of a
server for example.
Each frontend and backend may use multiple independant log outputs, which eases
multi-tenancy. Logs are preferably sent over UDP, maybe JSON-encoded, and are
truncated after a configurable line length in order to guarantee delivery.
3.3.16.
3.4.
Advanced features
3.4.1.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
19/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.4.2.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
20/26
6/20/2016
Search...
Keyboard navigation:
Enabled
The transparent bind and connect features, the support for binding connections
to a specific network interface, as well as the ability to bind multiple
processes to the same IP address and ports are only available on Linux and BSD
systems, though only Linux performs a kernel-side load balancing of the incoming
requests between the available processes.
On Linux, there are also a number of extra features and optimizations including
support for network namespaces (also known as "containers") allowing HAProxy to
be a gateway between all containers, the ability to set the MSS, Netfilter marks
and IP TOS field on the client side connection, support for TCP FastOpen on the
listening side, TCP user timeouts to let the kernel quickly kill connections
when it detects the client has disappeared before the configured timeouts, TCP
splicing to let the kernel forward data between the two sides of a connections
thus avoiding multiple memory copies, the ability to enable the "defer-accept"
bind option to only get notified of an incoming connection once data become
available in the kernel buffers, and the ability to send the request with the
ACK confirming a connect (sometimes called "biggy-back") which is enabled with
the "tcp-smart-connect" option. On Linux, HAProxy also takes great care of
manipulating the TCP delayed ACKs to save as many packets as possible on the
network.
Some systems have an unreliable clock which jumps back and forth in the past
and in the future. This used to happen with some NUMA systems where multiple
processors didn't see the exact same time of day, and recently it became more
common in virtualized environments where the virtual clock has no relation with
the real clock, resulting in huge time jumps (sometimes up to 30 seconds have
been observed). This causes a lot of trouble with respect to timeout enforcement
in general. Due to this flaw of these systems, HAProxy maintains its own
monotonic clock which is based on the system's clock but where drift is measured
and compensated for. This ensures that even with a very bad system clock, timers
remain reasonably accurate and timeouts continue to work. Note that this problem
affects all the software running on such systems and is not specific to HAProxy.
The common effects are spurious timeouts or application freezes. Thus if this
behaviour is detected on a system, it must be fixed, regardless of the fact that
HAProxy protects itself against it.
3.4.3.
HAProxy can be built with support for the Lua embedded language, which opens a
wide area of new possibilities related to complex manipulation of requests or
responses, routing decisions, statistics processing and so on. Using Lua it is
even possible to establish parallel connections to other servers to exchange
information. This way it becomes possible (though complex) to develop an
authentication system for example. Please refer to the documentation in the file
"doc/lua-api/index.rst" for more information on how to use Lua.
3.5.
Sizing
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
21/26
6/20/2016
Search...
Keyboard navigation:
Enabled
Usages vary a lot between users, some focus on bandwidth, other ones on request
rate, others on connection concurrency, others on SSL performance. this section
aims at providing a few elements to help in this task.
It is important to keep in mind that every operation comes with a cost, so each
individual operation adds its overhead on top of the other ones, which may be
negligible in certain circumstances, and which may dominate in other cases.
When processing the requests from a connection, we can say that :
- forwarding data costs less than parsing request or response headers;
- parsing request or response headers cost less than establishing then closing
a connection to a server;
- establishing an closing a connection costs less than a TLS resume operation;
- a TLS resume operation costs less than a full TLS handshake with a key
computation;
- an idle connection costs less CPU than a connection whose buffers hold data;
- a TLS context costs even more memory than a connection with data;
So in practice, it is cheaper to process payload bytes than header bytes, thus
it is easier to achieve high network bandwidth with large objects (few requests
per volume unit) than with small objects (many requests per volume unit). This
explains why maximum bandwidth is always measured with large objects, while
request rate or connection rates are measured with small objects.
Some operations scale well on multiple process spread over multiple processors,
and others don't scale as well. Network bandwidth doesn't scale very far because
the CPU is rarely the bottleneck for large objects, it's mostly the network
bandwidth and data busses to reach the network interfaces. The connection rate
doesn't scale well over multiple processors due to a few locks in the system
when dealing with the local ports table. The request rate over persistent
connections scales very well as it doesn't involve much memory nor network
bandwidth and doesn't require to access locked structures. TLS key computation
scales very well as it's totally CPU-bound. TLS resume scales moderately well,
but reaches its limits around 4 processes where the overhead of accessing the
shared table offsets the small gains expected from more power.
The performance numbers one can expect from a very well tuned system are in the
following range. It is important to take them as orders of magnitude and to
expect significant variations in any direction based on the processor, IRQ
setting, memory type, network interface type, operating system tuning and so on.
The following numbers were found on a Core i7 running at 3.7 GHz equiped with
a dual-port 10 Gbps NICs running Linux kernel 3.10, HAProxy 1.6 and OpenSSL
1.0.2. HAProxy was running as a single process on a single dedicated CPU core,
and two extra cores were dedicated to network interrupts :
- 20 Gbps of maximum network bandwidth in clear text for objects 256 kB or
higher, 10 Gbps for 41kB or higher;
- 4.6 Gbps of TLS traffic using AES256-GCM cipher with large objects;
- 83000 TCP connections per second from client to server;
- 82000 HTTP connections per second from client to server;
- 97000 HTTP requests per second in server-close mode (keep-alive with the
client, close with the server);
- 243000 HTTP requests per second in end-to-end keep-alive mode;
- 300000 filtered TCP connections per second (anti-DDoS)
- 160000 HTTPS requests per second in keep-alive mode over persistent TLS
connections;
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
22/26
6/20/2016
Search...
Keyboard navigation:
Enabled
3.6.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
23/26
6/20/2016
Search...
Keyboard navigation:
Enabled
In order to ensure that the version you're using is the latest one in your
branch, you need to proceed this way :
- verify which HAProxy executable you're running : some systems ship it by
default and administrators install their versions somewhere else on the
system, so it is important to verify in the startup scripts which one is
used;
- determine which source your HAProxy version comes from. For this, it's
generally sufficient to type "haproxy -v". A development version will
appear like this, with the "dev" word after the branch number :
HA-Proxy version 1.6-dev3-385ecc-68 2015/08/18
A stable version will appear like this, as well as unmodified stable
versions provided by operating system vendors :
HA-Proxy version 1.5.14 2015/07/02
Top
And a nightly snapshot of a stable version will appear like this with an
Summary
hexadecimal sequence after the version, and with the date of the snapshot
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
24/26
6/20/2016
Search...
Keyboard navigation:
Enabled
HAProxy will have to be updated according to the source it came from. Usually it
follows the system vendor's way of upgrading a package. If it was taken from
sources, please read the README file in the sources directory after extracting
the sources and follow the instructions for your operating system.
4.
HAProxy integrates fairly well with certain products listed below, which is why
they are mentionned here even if not directly related to HAProxy.
4.1.
Apache is the de-facto standard HTTP server. It's a very complete and modular
project supporting both file serving and dynamic contents. It can serve as a
frontend for some application servers. In can even proxy requests and cache
responses. In all of these use cases, a front load balancer is commonly needed.
Apache can work in various modes, certain being heavier than other ones. Certain
modules still require the heavier pre-forked model and will prevent Apache from
scaling well with a high number of connections. In this case HAProxy can provide
a tremendous help by enforcing the per-server connection limits to a safe value
and will significantly speed up the server and preserve its resources that will
be better used by the application.
Apache can extract the client's address from the X-Forwarded-For header by using
the "mod_rpaf" extension. HAProxy will automatically feed this header when
"option forwardfor" is specified in its configuration. HAProxy may also offer a
nice protection to Apache when exposed to the internet, where it will better
resist to a wide number of types of DoS.
4.2.
NGINX
NGINX is the second de-facto standard HTTP server. Just like Apache, it covers a
wide range of features. NGINX is built on a similar model as HAProxy so it has
no problem dealing with tens of thousands of concurrent connections. When used
as a gateway to some applications (eg: using the included PHP FPM), it can often
be beneficial to set up some frontend connection limiting to reduce the load
on the PHP application. HAProxy will clearly be useful there both as a regular
load balancer and as the traffic regulator to speed up PHP by decongestionning
it. Also since both products use very little CPU thanks to their event-driven
architecture, it's often easy to install both of them on the same system. NGINX
implements HAProxy's PROXY protocol, thus it is easy for HAProxy to pass the
client's connection information to NGINX so that the application gets all the
relevant information. Some benchmarks have also shown that for large static
file serving, implementing consistent hash on HAProxy in front of NGINX can be
beneficial by optimizing the OS' cache hit ratio, which is basically multiplied
by the number of server nodes.
4.3.
Varnish
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
25/26
6/20/2016
Search...
Keyboard navigation:
Enabled
4.4.
Alternatives
Linux Virtual Server (LVS or IPVS) is the layer 4 load balancer included within
the Linux kernel. It works at the packet level and handles TCP and UDP. In most
cases it's more a complement than an alternative since it doesn't have layer 7
knowledge at all.
Pound is another well-known load balancer. It's much simpler and has much less
features than HAProxy but for many very basic setups both can be used. Its
author has always focused on code auditability first and wants to maintain the
set of features low. Its thread-based architecture scales less well with high
connection counts, but it's a good product.
Pen is a quite light load balancer. It supports SSL, maintains persistence using
a fixed-size table of its clients' IP addresses. It supports a packet-oriented
mode allowing it to support direct server return and UDP to some extents. It is
meant for small loads (the persistence table only has 2048 entries).
NGINX can do some load balancing to some extents, though it's clearly not its
primary function. Production traffic is used to detect server failures, the
load balancing algorithms are more limited, and the stickiness is very limited.
But it can make sense in some simple deployment scenarios where it is already
present. The good thing is that since it integrates very well with HAProxy,
there's nothing wrong with adding HAProxy later when its limits have been faced.
Varnish also does some load balancing of its backend servers and does support
real health checks. It doesn't implement stickiness however, so just like with
NGINX, as long as stickiness is not needed that can be enough to start with.
And similarly, since HAProxy and Varnish integrate so well together, it's easy
to add it later into the mix to complement the feature set.
Top
http://cbonte.github.io/haproxy-dconv/intro-1.6.html
Summary
26/26