HAProxy community

Maxconn handling


I am looking how to handling maxconn condition.


How’s does the haproxy handle if it reach to maxconn?
I would like to see it can return the custom error page if once reach to maxconn .

Thanks all!


To answer your first question:

The maxconn parameter can be configured in multiple locations in haproxy.cfg file with different implications.

  1. global maxconn: Limits the maximum number of concurrent connections per haproxy process. When this limit is reached, HAProxy stops accepting new connections and the incoming connections get queued to “Linux socket queue”. This is the greatest of all the 3 maxconn values.
  2. maxconn in frontend or listen section: Limits the maximum number of concurrent connections those are accepted by a frontend or listen section. When this limit is reached, the new connections get queued to a “frontend queue”. This is a value smaller than or equal to the global maxconn.
  3. server maxconn: Limits the maximum number of concurrent connections handled by a server. When this limit is reached the incoming connections get queued either to the “proxy queue” or to the “server queue”. A connection is queued to the server queue only if the incoming request is a persistent request.

In all the above cases, the duration for which a connection can stay in a queue is governed by the “timeout queue” parameter. An HTTP 503 Service unavailable message is thrown if this timeout is reached before the connection get served.

Now, to answer your second question:

If the global maxconn value is reached, the user would only notice a delay in the processing of the request due to queuing and would not encounter an error message until the socket queue gets saturated. If the socket queue gets saturated, HAProxy would anyhow not be able to handle the error as it would be at the kernel level.
Therefore, the need to handle an error using a custom error message would only arise in a scenario wherein the timeout queue value is reached for connections in frontend queue, proxy queue or server queue. In that case, you may display a custom error page by configuring errorfile parameter in haproxy.cfg as shown below:

errorfile 503 /etc/haproxy/errorfiles/503sorry.http

Hope this is helpful !