Nginx LVS load balancing algorithm

1 Static algorithm

Static: Distribute user requests according to the free and fixed algorithm of LVS itself.

  1. Round Robin (Round Robin abbreviated'rr'): The round robin algorithm assumes that all servers have the same ability to process requests, and the scheduler will evenly distribute all requests to each real server (similar to Nginx polling)
  2. Weighted round robin (Weight Round Robin abbreviated'wrr'): installs the weight ratio to allocate user requests. The higher the weight, the more requests are allocated for processing. (Same as Nginx weight)
  3. Source Hash (Source Hash abbreviated'sh'): The request of the same user ip will be processed by the same RS. (Same as Nginx's ip_hash)
  4. Destination Hash (Destination Hash abbreviated'dh'): According to different urls, different RSs are requested. (Same as Nginx's url_hash)

2 dynamic algorithm

Dynamic: User requests will be allocated according to different traffic or different server pressures, which is calculated dynamically.

  1. Minimum number of connections (Least Connections abbreviated'lc'): ​​Allocate new connection requests to the server with the smallest number of connections currently.

  2. Weight Least Connections (Weight Least Connections abbreviated as'wlc'): ​​The processing performance of the server is represented by a numerical value. The greater the weight, the more requests are processed. Real Server may dynamically obtain the load status of different servers in performance, and distribute requests to servers with good performance and relatively idle.

  3. The shortest expected delay (Shortest Expected Delay abbreviated'sed'): a special wlc algorithm. For example, suppose there are three servers ABC, and the weights are 1, 2, and 3. If it is calculated using the wlc algorithm, it may be assigned to any one of ABC. After using the sed algorithm, the following operations will be performed:

    • A:(1+1)/1=2

    • B:(1+2)/2=3/2

    • C:(1+3)/3=4/3

      The final result, the request will be handed over to the server with the smallest calculation result

  4. Minimum queue scheduling (Never Queue abbreviated'nq'): Never use the queue. If the number of Real Server connections is equal to 0, the request will be allocated directly, and there is no need to wait in the queue for calculation

    1. Weight Least Connections (Weight Least Connections abbreviated as'wlc'): ​​The processing performance of the server is represented by a numerical value. The greater the weight, the more requests are processed. Real Server may
      dynamically obtain the load status of different servers in terms of performance, and distribute requests to servers with good performance and relatively idle.

    2. The shortest expected delay (Shortest Expected Delay abbreviated'sed'): a special wlc algorithm. For example, suppose there are three servers ABC, and the weights are 1, 2, and 3. If the wlc algorithm is used to
      find it, it may be assigned to any one of ABC. After using the sed algorithm, the following operations will be performed:
      A: (1+1)/1=2
      B: (1+2)/2=3/2
      C: (1+3)/3=4/3 The
      final result will be Give this request to the server with the smallest result.
      \4. Minimum queue scheduling (Never Queue abbreviated'nq'): Never use the queue. If the number of Real Server connections is equal to 0, the request is directly allocated, and there is no need to wait in the queue for calculation (s

3 Appendix information

In the actual use of LVS, the load balancing algorithm used is wlc or wrr, which is simple and easy to use.

  • Appendix 1

    Reference [official document]: http://www.linuxvirtualserver.org/zh/lvs4.html

  • Appendix 2

As an ordinary developer, you need to have a certain understanding of the load algorithm of the lvs cluster, because you need to communicate effectively with the operation and maintenance personnel; but if you are an operation and maintenance, then you must delve into LVS, if an enterprise uses LVS , Then the business volume is very huge, and there will be a dedicated operation and maintenance team responsible for the network architecture.

4 Related information

  • The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you

Guess you like

Origin blog.csdn.net/qq_15769939/article/details/113677040