- HAProxy
- High Availability Proxy
- Open source TCP/HTTP LB and Proxy solution for Linux/Solaris/FreeBSD
- used to improve the performance and reliability of system
- BackendA set of servers that receives forwarded requests. It contains :
- LB algorithm to use
- A list of servers and ports
Adding more servers to your backend will increase your potential load capacity by spreading the load over multiple servers
balance roundrobin
mode http
server blog1 blog1.abc.com:80 check
server blog1 blog1.abc.com:80 check
balance specifies LB algorithm
mode specifies use of layer 7 protocol
check specifies that health checks should be performed on those backend servers
mode specifies use of layer 7 protocol
check specifies that health checks should be performed on those backend servers
- Frontend
Defines how requests should be forwarded to backends. It consists : - A set of IP addresses and a port (e.g. 10.1.1.7:80, *:443, etc.)
- ACLs
- use_backend rules
which defines which backends to use depending on which ACL conditions are matched, and/or a default_backend rule that handles every other case
- Types of LB
- No LB : Single Web server. Slow experience when accessed by simultaneous users.
User > WS (Web server) > DB - Layer4 LB : forward user traffic based on IP range and port. LB selects the web server based on algorithm. All web server should serve the identical contents and all web servers connect to same DB.
User > LB (Backend) > WS1, WS2 > DB - Layer7 LB : forward requests to different backend servers based on the content of the user's request. Single LB can have multiple backend for multiple applications.
User > LB (Frontend) > Backend 1 > WS1, WS2 | Backend 2 > WS3, WS4
- Implementation of Layer7 LB
- Example : When user request abc.com/blog, forward it to blog backend. For other requests, forward to web backend.
In addition to backend config, there will be frontend config to map the backends.
frontend http
bind *:80
mode http
acl url_blog path_beg /blog
use_backend blog-backend if url_blog
default_backend web-backend
- LB Algorithms
- determines which server will be selected when load balancing
- Servers can be assigned a weight parameter to manipulate how frequently the server is selected compared to other servers.
- Most common algorithms are :
- roundrobin : Default Algo. Selects servers in turns.
- leastconn : Selects the server with the least number of connections. Recommended for longer sessions.
- source : selects which server to use based on a hash of the source IP. It ensure that a user will connect to the same server.
- Sticky Sessions
- Some applications require that a user continues to connect to the same backend server. This persistence is achieved through sticky sessions.
- Health Check
- It determines if a backend server is available to process requests by checking if the backend server is listening on the configured IP address and port.
This avoids having to manually remove a server from the backend if it becomes unavailable. - If a server fails a health check, it is automatically disabled in the backend so traffic will not be forwarded to it until it becomes healthy again.
- If all servers in a backend fail, the service will become unavailable until at least one of those backend servers becomes healthy again.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.