Skip to content

Load Balancing: recap and quiz

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
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 balancer is not finished when it spreads requests. Ask these in order.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

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.

Question 1 of 8

A team puts one address in front of its service. Requests whose path starts with /api must go to one group of servers, and those that start with /images to another.

Which balancer can do this?

Choose one answer.

Question 2 of 8

A pool has four servers, and the first takes twice as long on every request as the others. Each of the others can serve 50 requests a second. Traffic is 100 requests a second, which is well below the pool's capacity of 175.

What do round robin and least connections do?

Choose one answer.

Question 3 of 8

Which statement about power of two choices is true?

Choose one answer.

Question 4 of 8

A balancer probes each server every 5 seconds, and takes a server out of rotation after 3 failed probes in a row. A server dies.

At most how long after the server dies is it taken out?

Enter a number and choose its unit.

seconds
Question 5 of 8

Sessions are pinned to servers by a cookie. One server fails, and the balancer's checks take it out of rotation.

What happens to the sessions that were pinned to it?

Choose one answer.

Question 6 of 8

A pool of 4 servers places each key with hash mod N. A fifth server is added, so N goes from 4 to 5.

About what percentage of the keys move to a different server?

Enter a number and choose its unit.

per cent
Question 7 of 8

A team replaces the servers of a service one at a time, and drains each before stopping it.

Which of these are true of draining a server? Select all that apply.

Choose every answer that applies.

Question 8 of 8

A server takes 400 requests a second, and each request takes 250 ms on average. It is stopped at once, with no draining.

On average, how many requests does the stop cut?

Enter a number and choose its unit.

requests

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.