Load Balancing: recap and quiz
The module in six sentences
Section titled “The module in six sentences”- What a load balancer does. One address in front of many servers that spreads the work, hides failures and allows change; a layer 4 balancer places connections from addresses and ports, a layer 7 balancer places requests from their content, and the balancer must itself not be a single machine.
- Balancing algorithms. Round robin and random look at nothing, least connections looks at every server, and two random choices look at two and come close; a slow server breaks the first two and not the others.
- Health checks. A balancer finds out by probing or by watching requests, so a dead server stays in rotation for more than (failures − 1) × interval and at most failures × interval, and a check cannot create capacity.
- Sticky sessions. Pinning a client turns the algorithm off for that client, which costs balance, loses the sessions of a failed server, and leaves a new server empty.
- Consistent hashing. Hash mod N moves most keys when the servers change, a ring moves only about 1/N of them, and neither balances load.
- Connection draining. To take a server out, tell the balancer, let what is in flight finish within a limit, and stop; none of that creates the spare capacity that a deploy needs.
What each one rests on
Section titled “What each one rests on”| Idea | The common mistake | The correction |
|---|---|---|
| Layer 4 or 7 | Choosing by speed and forgetting the unit | A layer 4 balancer places connections, so one busy connection can sit with an idle one |
| Algorithm | Believing that an equal share is an equal load | With one server twice as slow, round robin failed 216 requests and least connections none |
| Health check | Assuming a dead server is out at once | At 5 seconds and 3 failures, round robin sent it 25 requests a second for 14.5 seconds: 385 failed |
| Sticky sessions | Pinning in case state is needed | At 100% pinned, the mean rose from 34.8 ms to 55.4 ms, with every algorithm the same |
| Consistent hashing | Using hash mod N for a pool that changes | 80% of keys move from 4 servers to 5, against about 21% for a ring |
| Draining | Stopping the server and hoping | A stop without telling the balancer failed 530 requests, telling it first 4, draining 0 |
A list: check a balancing design
Section titled “A list: check a balancing design”A balancer is not finished when it spreads requests. Ask these in order.
- Which layer? Does the balancer need the path, the host or a header, or only the connection? If one connection carries many requests, only layer 7 spreads them.
- Which algorithm? Requests and servers alike: round robin. Requests or servers that differ, or a server that may slow down: least connections or two choices. At 80% utilisation with four 20 ms servers, the mean is 103.8 ms for random and 40.6 ms for least connections.
- How long does a failure last? Interval times failures, up to one interval more. Multiply by the share of traffic one server gets, and that is what is lost.
- Does anything pin clients? If the reason is state in the server, move the state out. If a client must stay, expect an imbalance, and plan for the loss of its server.
- How does a server leave? Tell the balancer, drain with a limit taken from the longest request, and keep spare capacity for the server being replaced. A pool at 90% utilisation fails requests during a deploy however well it drains.
Check what you have learnt
Section titled “Check what you have learnt”Eight questions cover the whole module. Every option is explained, whether it is right or wrong.
Load Balancing: module quiz
This quiz needs JavaScript to check your answers.
What comes next
Section titled “What comes next”The next module, Caching, asks a question that comes before all of these. A balancer chooses the server for a request that has to reach one. A cache answers some requests without reaching a server at all, and changes how much load there is to balance.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.