In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the characteristics of Java consistent hash". In daily operation, I believe many people have doubts about the characteristics of Java consistent hash. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the characteristics of Java consistent hash?" Next, please follow the editor to study!
I. Preface
When solving the problem of load balancing in distributed systems, the Hash algorithm can be used to make a fixed part of the requests fall on the same server, so that each server regularly processes part of the requests (and maintains the information of these requests), which plays the role of load balancing.
However, the ordinary remainder hash (hash (for example, user id)% server machines) algorithm has poor scalability, and the mapping relationship between user id and server will fail massively when new server machines are added or offline. Consistent hash is improved by using hash ring.
II. Overview of consistent Hash
In order to intuitively understand the principle of consistent hash, this paper illustrates it with a simple example, assuming that there are four servers with the address of ip1,ip2,ip3,ip4.
Consistent hash is to first calculate the hash values corresponding to four ip addresses.
Hash (ip1), hash (ip2), hash (ip3), hash (ip3). The calculated hash value is a direct value of the 0 ~ largest positive integer. These four values are shown in the following figure on the consistent hash ring:
The hash ring starts clockwise from the integer 0 to the largest positive integer, and the hash value calculated based on the four ip must fall to some point on the hash ring, so we map the four ip of the server to the consistent hash ring.
When the user makes a request on the client, first calculate the routing rule (hash value) according to hash (user id), then see where the hash value falls on the hash ring, and find the nearest ip clockwise as the routing ip according to the position of the hash value on the hash ring.
According to the clockwise rule, the request of user1,user2 will be processed by the server ip3, while the processing server corresponding to the request of other users remains unchanged, that is, only the mapping relationship of some users previously processed by ip2 has been destroyed, and the request it is responsible for processing is delegated by the next node clockwise.
Let's consider what happens when new machines are added.
When an ip5 server is added, the consistent hash ring is roughly as shown below:
Server ip1,ip2,ip3 falls on the consistent hash ring after hash. From the distribution of hash values in the figure, we can see that ip1 is responsible for processing about 80% of requests, while ip2 and ip3 are only responsible for processing about 20% of requests. Although all three machines are processing requests, it is obvious that the load of each machine is uneven, which is called the tilt of consistent hash. The emergence of virtual nodes is to solve this problem.
5. Virtual node
The problem of consistent hash tilting mentioned in the previous section will occur when there are few server nodes. One solution is to add more machines, but there is a cost to add machines, so add virtual nodes, such as the above three machines. The figure of the consistent hash ring after each machine introduces one virtual node is as follows:
It can be seen that after the introduction of one virtual node to each service node, the situation is better than that before the introduction of the virtual node, but it is not balanced.
The goal of uniform hash is that if there are N servers and M hash values for clients, then each server should handle about N users. That is, the load of each server should be balanced as much as possible.
At this point, the study on "what are the characteristics of Java consistent hash" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.