Comparison between consistent hash and common hash

Source: Internet
Author: User

Common Hash Algorithm

Assume that five cache hosts are cachea, cacheb, cachec, cached, and cachee.

When the program performs hash, each node first hash a value based on its unique parameters (for example, hash Based on IP addresses)

The hash value generated after the host hash is completed is as follows:

Cachea 0

Cacheb 1

Cachec 2

Cached 3

Cachee 4

After the host generates a hash value, we use the cache as an instance. For example, a user logs on to the instance with a unique PIN value.

This pin value is used to calculate the remainder by hash. Because the remainder is obtained by using 5, so the value will certainly be Xiaoyu 5, so there will be a point, and then

Cache data to the server

Consistent Hash Algorithm

Assume that five cache hosts are cachea, cacheb, cachec, cached, and cachee.

When the program performs hash, each node first hash a value based on its unique parameters (for example, hash Based on IP addresses)

The hash value generated after the host hash is completed is as follows:

Cachea key1

Cacheb key2

Cachec key3

Cached key4

Cachee key5

Then the five nodes are called a ring,

650) This. width = 650; "Title =" hash value of five machines "alt =" wkiom1pyobvj0ta2aacolmzs8xe909.jpg "src =" http://s3.51cto.com/wyfs02/M00/42/AD/wKiom1PYobvj0Ta2AACOLmzs8xE909.jpg "/>

After the host generates a hash value, we use the cache as an instance. For example, a user logs on to the instance with a unique PIN value.

This pin value is hashed. Note that, unlike normal hash, only hash does not require remainder. When hash generates a value

Then, check whether the value is between the two values, for example, between key4 and key5.

Find the first Cache Server and use it as the cache point.

. :

650) This. width = 650; "Title =" qq20140730131305.jpg "alt =" wkiol1pypgpcwqopaacwdnu05vo462.jpg "src =" http://s3.51cto.com/wyfs02/M02/42/AF/wKioL1PYpGPCWQoPAACWDnU05vo462.jpg "/>

Comparison:

After the above introduction, we can see that if a common hash is used when any machine is down

The cache will be stored securely. Why?

Because when a cache is down, we need to reselect the data point. The divisor has changed, so we need to re-set the cache,

Of course, it is not ruled out that some pin values are the same, but when the cache server is increased to a certain number

The possibility is almost 0, so it is called that all caches must be reset.

When one of the machines goes down using consistent hashing, the loop cache that comes above it becomes invalid, for example:

When cache3 is down, the pin falling between cache2 and cache3 will be invalid, so the point of failure will continue to follow.

If you find the cache server, the new point will be on cache4.

This article from the "loyal to the country" blog, please be sure to keep this source http://xinsir.blog.51cto.com/5038915/1532872

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.