The load balancer keeps count of how many requests each server is still working on, and sends each new request to the server with the fewest. Unlike round robin, it reacts to what the servers are doing. Below, switch between least connections and round robin on the same traffic and see where they differ.
Each server drawn stands for one of your servers, and each dot for 100 real requests. Only the speed is slowed, so you can follow single requests. "In progress" under the balancer is what least connections compares: requests sent to each server and not yet answered. Switching the algorithm restarts the run with the same traffic.
Busiest hour vs the daily average. The book's estimate uses 2x.
Measured by load testing one server until it cannot go faster.
Headroom for spikes, slow requests and a failed server. 50 to 70% is common.
1. Average requests per second
2. Peak requests per second
3. Servers needed n
4. Load on each server
5. One server half as fast
6. About one request in five taking 4x as long
7. One server fails
Steps 1 and 2 are the estimation method from the back-of-the-envelope chapter of Alex Xu's System Design Interview, Vol. 1, including its 2x peak. The rest is standard capacity planning. The perfect split in step 5 is the same traffic spread over n - 1 full servers and one half server. Least connections only approaches it, because it evens out requests in progress, not how busy each server is.
Both offer it as an alternative to their round robin default, for traffic where requests differ.
least_conn in an upstream block, "a request is passed to the server with the least number of active connections, taking into account weights of servers." On ties: "If there are several such servers, they are tried in turn using a weighted round-robin balancing method." Its load balancing guide gives the reason to use it: it is fairer "in a situation when some of the requests take longer to complete."Both are the vendors' own documentation (primary sources). Quoted phrases are short attributed quotations; everything else is described in our words. Check the pages for current behaviour.