Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maxconn limit per backend in haproxy

Our haproxy loadbalancer opens thousands of connections to its backends even though its settings say to open no more than 10 connections per server instance (see below). When I uncomment "option http-server-close" the number of backend connection drops however I would like to have keep-alive backend connections.

Why maxconn is not respected with http-keep-alive? I verified with ss that the opened backend connections are in ESTABLISHED state.

defaults
     log global
     mode    http
     option http-keep-alive
     timeout http-keep-alive 60000
     timeout connect 6000
     timeout client  60000
     timeout server  20000


 frontend http_proxy
     bind    *:80
     default_backend backends

 backend backends
     option prefer-last-server

     # option http-server-close
     timeout http-keep-alive 1000
     server s1 10.0.0.21:8080 maxconn 10
     server s2 10.0.0.7:8080  maxconn 10
     server s3 10.0.0.22:8080 maxconn 10
     server s4 10.0.0.16:8080 maxconn 10
like image 755
Roman Avatar asked May 22 '17 10:05

Roman


People also ask

How many connections can HAProxy handle?

In HAProxy, you can add more servers to handle more concurrent connections. In this example, HAProxy allows 30 active connections per server. If all of the servers are maxed out, connections queue up, waiting for an available server.

What is Maxconn in HAProxy?

maxconn. The maxconn setting limits the maximum number of connections that HAProxy will accept. Its purpose is to protect your load balancer from running out of memory. You can determine the best value for your environment by consulting the sizing guide for memory requirements.

What is backend in HAProxy?

HAProxy Enterprise frontend sections accept incoming connections that can then be forwarded to a pool of servers. The backend section is where those pools of servers that will service requests are defined. You may add as many backend sections as needed.

What is HAProxy session rate?

Session Rate [rate] This is the rate at which HAProxy creates the connections between the frontend and the client. One session can be mapped to a unique client. These are TCP sessions created by each client, over which multiple HTTP requests can be sent.


1 Answers

In keep-alive mode idle connections are not accounted. As explained in this HAProxy mailthread

The thing is, you don't want to leave requests waiting in a server's queue while the server has a ton of idle connections.

This even makes more sense, knowing that browsers initiate preconnect to improve page performance. So in keep-alive mode only outstanding/active connections are taken into account.

You can still enforce maxconn limits regardless of the connection state using tcp mode, especially that I don't see a particular reason to using mode http in your current configuration (apart from having reacher logs).
Or you can use http-reuse with http mode to achieve a lowest number of concurrent connections.

like image 160
Mo3m3n Avatar answered Oct 13 '22 02:10

Mo3m3n