hash algorithm consistent with the principle of

hash algorithm consistent with the principle of

consistent hash algorithm is used memcached cluster, memcached cluster mainly hash and consistency of hash. The following were to explain the principles of these two algorithms.

hash clustering algorithm.

Because memcached cluster approach is to store the contents of each node is different, so when the cluster is to use algorithms to select which server to store and read in. This is the hash algorithm, the algorithm is relatively simple, like haspmap algorithm, the remainder dispersed (the number is hashcode% server to decide which server is placed). The problem with this algorithm: a change in the number of servers, most of the data will be lost. Because the number of servers change, the remainder changed. So to cache restructuring , a large quantity of data words too costly.

Consistency hash

How to solve the cache restructuring . , Hashcode data server belongs associated virtual node into a clockwise macrocycle. Hashcode server and data are placed in the big ring.
Focus: the relationship between server nodes and data nodes what is it? Hashcode closest to a server node server hashcode data is the data node. So read and write data is to find the closest server node. Changes in the number of physical servers, without restructuring the entire cache. Because this ring is ordered, the point is deleted section will only affect the data on this node, the other without adjustment. When you add a new node, the data is the data point clockwise section closest to the new node that node closest to the migration to the new node on the line.

Adding Virtual Nodes

Just use a real node to form a ring structure may result in tilting of data, in order to solve such data asymmetry can be cached on the basis of the principle of the machine, the corresponding increase virtual nodes, such data will be uniform to play scattered to other nodes.

This time, when the client is looking for data access virtual node, rather than real physical node server.

Guess you like

Origin www.cnblogs.com/wolf12/p/12308279.html