1. Shortest response time load balancing

  1. The service provider with the shortest response time is selected from multiple service providers, because there may be multiple service providers that meet such conditions. Therefore, multiple service providers should be analyzed according to their weight when they are selected.
  2. But if you only pick one, you just pick this one.
  3. If there are multiple, see if they all have the same weight, and if not, follow the logic of the weighted random algorithm.
  4. If they have the same weight, one is called randomly.
  • Successful response time = Total time of all successful responses/number of successful responses

2. Minimum connection algorithm

In this mode, a request is forwarded by NGINX to the service instance with the fewest active requests

3. Minimum active load balancing

4. Consistent hash load balancing

Determines which back-end service instance to forward the request to based on the hash value of the IP address that sent the request

5. Weighted polling load balancing

  • For example, the weight ratio of server A, SERVER B, and server C is 5:3:2. So out of 10 requests, server A will receive 5 of them, server B will receive 3 of them, and server C will receive 2 of them.
  • There is a bug and weighted smoothing is now commonly used

6. Smooth weighted polling load balancing

  • A brief explanation of the calculation process, direct paste code many people do not understand

  • Suppose the weights of A, B and C are 5,1,1,

  • Two of the weight

    • Static weight: 5:1:1
    • Dynamic weight: changes with each call, starting with 0,0,0
  • First call

  • currentWeight = currentWeight + Weight = 5 : 1: 1

  • Select current, 5, corresponding to server A to call, return A

  • After the call, the maximum current = 5 needs to subtract sum (weight) = 7 so the new currentWeight = -2:1:1

  • Second call

  • Go back to the first step and call currentWeight + Weight (5:1:1) = 3:2:2

  • Select the maximum current = 3 corresponding to server A return A

  • After this call, the maximum current = 3 needs to be subtracted from sum (weight) =7 so new currentWeight = -4:2:2

  • Third call

  • Go back to the first step and call currentWeight (-4:2:2) + Weight (5:1:1) = 1:3:3

  • Select the maximum current = 3 — corresponding to B server return B

  • After the call, the maximum current = 3 needs to subtract sum (weight) =7 so the new currentWeight = 1: -4:3

  • Fourth call

  • Go back to the first step and call currentWeight (1: -4:3) + Weight (5:1:1) = 6: -3:4

  • Select the maximum current = 6 — corresponding to A server return A

  • After the call, the maximum current = 6 needs to subtract sum (weight) =7 so the new currentWeight = -1: -3:4

reference

  • Juejin. Cn/post / 684490…