haproxy: retain existing sessions under high load, serve '503' to new arrivals

Solution 1:

Unfortunately, you appear to be completely confusing connections with application-level sessions. A user visiting the site might have a cookie which makes you think he owns a connection while it's not necessarily the case. He might open as many connections as needed to fetch objects and navigate pages.

The 90 seconds you're observing surely is the browser's keep alive timeout for idle connections.

It is possible to achieve what you want but it's a bit more complex than that, as you have to also consider the presence of the persistence cookie in the request to figure out whether the visitor is a new one or not.

Also in general it's more efficient to rely on the average per-server connection count than on the frontend connection count. The reason is that when a server dies, you need to readjust this number. The most efficient way to do it is to set up a server maxconn value to enable queuing, and to use avg_queue so that the limit applies to the average number of queued requests on servers. This allows you to correctly handle known visitors while softly moving new users to another backend when the load increases due to existing visitors.