user1608602
user1608602

Reputation: 1

Load balancing according incoming traffic in haproxy

I am using haproxy with round-robin perfectly but now I am facing a problem: one of my backend server is loaded.

  1. I want to know if i can balancer the traffic according to the load on backend server.Also if one fails with limit of max. conn traffic goes to other backend server
  2. difference between least conn, round robin & global max conn, default max conn, and server max connection

Upvotes: 0

Views: 1369

Answers (1)

Willy Tarreau
Willy Tarreau

Reputation: 3424

If a server is more loaded than other ones, then mechanically it will see more concurrent connections for the same request rate. That's where it becomes useful to switch to the leastconn algorithm, which will ensure that all servers always run with the same number of concurrent connections. This is useful for instance if some of your requests are much longer than other ones (eg: complex requests in a database).

For the second point, I'll be short because everything is in the doc, but leastconn focuses on the number of concurrent connections while round robin focuses on the cumulated number of connections. With round robin, each server gets a request in turn, so the requests on a same server are optimally spaced. This is normally better for static servers or for applications with stickiness where users make a large number of requests once attached to a server, since this ensures you have the same number of users on the same server. Global maxconn is the total amount of concurrent connections a single haproxy process will support. It will stop accepting incoming connections when the limit is reached. The default maxconn applies to frontends only, and when a frontend's maxconn is reached, this frontend only will stop accepting new connections. The server maxconn ensures that haproxy never sends too many connections to a server. When the limit is reached, an other server is selected when possible (no cookie, etc), or the request is queued until the server releases a connection to pick it. If your servers are overloaded, you should check the number of connections and apply a server maxconn slightly below this value to protect them.

Upvotes: 1

Related Questions