Summary of Load Balancing Algorithms

 Common load balancing algorithms:

1. Polling method - allocating requests to the server in turn

 2. Weighted polling method


   For example, weight=3 represents three consecutive server1s. Each time a server is selected, poll from the head to the tail

3. Random method

4. Weighted random method

 

5. Source address hashing

  Get the hash value of the client IP , modulo the number of servers, and locate the specific server, but the disadvantage is that when some servers fail or new servers are added, the server located by the client will change greatly, which will make Server cache invalidation

6. Minimum number of connections

  Allocate requests to the server with the least current backlog of connections.

7. Consistent hash           advantage: will not cause drastic changes

Load balancing realizes session sharing: database, session frequently used is better placed in kv database.

DNS load balancing : A domain name corresponds to multiple IP addresses, and DNS resolves the domain name into one of the specific IP addresses according to the load balancing algorithm. (polling, closest to user)

An implementation of consistent Hash:

Answer: Organize the entire hash value space into a virtual ring [0-2^32-1] , map the server to the hash ring using the hash algorithm , and map the data to the hash ring using the same hash algorithm , the first server encountered clockwise from the map location is the data store location .

 

   Implementation: Hash algorithm: crc32 , based on MD5

         Data structure: TreeMap<hash,server> , the first one is greater than the data hash

                      The corresponding server of the value is the storage location.

         Solve uneven data distribution: one real server corresponds to multiple virtual servers, and the virtual servers are distributed on thehashring.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325642535&siteId=291194637