Hash mapping method and device, equipment and storage medium

By optimizing the distribution of server nodes on the hash ring and selecting target server nodes by combining the initial server nodes and candidate offset angles, the problem of data skew in hash mapping is solved, achieving more efficient load balancing and improved system performance.

CN120872584APending Publication Date: 2025-10-31GUANGDONG LEHUA HOME FURNISHING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510938785.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-08
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

The data skew problem caused by uneven distribution of server nodes in existing hash mapping leads to a decrease in system performance and an increase in operation and maintenance costs.

Method used

By determining candidate server nodes on the hash ring based on the initial server node and candidate offset angle of the new server, and selecting the target server node by combining the spacing on the ring, hash mapping is performed to avoid introducing virtual nodes and optimize the distribution of server nodes.

Benefits of technology

It effectively prevents data skew, reduces system performance loss and maintenance costs, and improves system stability and scalability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872584A_ABST
    Figure CN120872584A_ABST
Patent Text Reader

Abstract

The invention discloses a Hash mapping method, device and equipment and a storage medium, and the method comprises the steps: when a new server to be added into a Hash ring exists and a server node exists on the Hash ring, adding the new server into the Hash ring; determining candidate server nodes on the hash ring according to the initial server node and the candidate deviation angle of the new server on the hash ring; and determining a target server node of the new server on the Hash ring according to the ring spacing between the initial server node and each server node on the Hash ring and between the candidate server node and each server node on the Hash ring, and performing Hash mapping through the target server node. According to the mode, under the conditions that excessive system performance is not consumed and system complexity is not increased, server nodes are distributed more uniformly, data skew can be effectively prevented, the situation that node loads are too heavy is avoided, meanwhile, virtual nodes do not need to be introduced, system performance loss, operation and maintenance cost and calculation expenditure are reduced, and the system performance is improved. And the stability and the expandability of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to hash mapping methods, apparatus, devices and storage media. Background Technology

[0002] During hash mapping, the uneven distribution of server nodes on the hash ring causes most network traffic to concentrate on the same server node, leading to data skew. To alleviate this problem, existing technologies introduce virtual node mechanisms, but this approach has significant drawbacks: on the one hand, the introduction of virtual nodes increases system complexity and operational costs; on the other hand, it significantly increases the overhead of hash calculations, ultimately leading to a decline in system performance. Summary of the Invention

[0003] The main objective of this application is to provide a hash mapping method, apparatus, device, and storage medium, which aims to solve the technical problem of how to effectively resolve data skew while reducing system complexity and performance loss.

[0004] To achieve the above objectives, this application proposes a hash mapping method, which includes:

[0005] In the case where there is a new server to be added to the hash ring and there are server nodes on the hash ring, the candidate server nodes of the new server on the hash ring are determined based on the initial server node of the new server on the hash ring and the candidate offset angle.

[0006] Based on the ring spacing between the initial server node and each server node on the hash ring, and the ring spacing between the candidate server node and each server node on the hash ring, the target server node of the new server on the hash ring is determined.

[0007] The new server is hash-mapped based on the target server node.

[0008] In one embodiment, the ring spacing includes a clockwise ring spacing and a counterclockwise ring spacing;

[0009] The step of determining the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node, and the ring spacing between the candidate server node and each server node, includes:

[0010] The distance difference is calculated based on the clockwise ring spacing between the initial server node and each server node on the hash ring and the counterclockwise ring spacing between the initial server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the initial server node are determined.

[0011] The distance difference is calculated based on the clockwise ring spacing between the candidate server node and each server node on the hash ring and the counterclockwise ring spacing between the candidate server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the candidate server node are determined.

[0012] The target server node of the new server on the hash ring is determined based on the absolute values ​​of multiple distance differences corresponding to the initial server node and the absolute values ​​of multiple distance differences corresponding to the candidate server nodes.

[0013] In one embodiment, the step of determining the target server node of the new server on the hash ring based on the absolute values ​​of multiple distance differences corresponding to the initial server node and the absolute values ​​of multiple distance differences corresponding to the candidate server nodes includes:

[0014] The absolute values ​​of multiple distance differences corresponding to the initial server node are summed to determine the distribution uniformity score corresponding to the initial server node.

[0015] The absolute values ​​of multiple distance differences corresponding to the candidate server nodes are summed to determine the distribution uniformity score corresponding to the candidate server nodes.

[0016] Based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server node, the target server node of the new server on the hash ring is determined.

[0017] In one embodiment, the step of determining the target server node of the new server on the hash ring based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server nodes includes:

[0018] The distribution uniformity score corresponding to the initial server node is compared with the distribution uniformity score corresponding to the candidate server node;

[0019] When the distribution uniformity score corresponding to the initial server node is less than the distribution uniformity score corresponding to the candidate server node, the initial server node is taken as the target server node of the new server on the hash ring.

[0020] When the distribution uniformity score corresponding to the initial server node is greater than or equal to the distribution uniformity score corresponding to the candidate server node, the candidate server node is selected as the target server node of the new server on the hash ring.

[0021] In one embodiment, before the step of determining the candidate server nodes of the new server on the hash ring based on the initial server nodes and candidate offset angles of the new server on the hash ring, the method further includes:

[0022] The hash value of the new server is determined by calculating the hash value of the server address and server port.

[0023] The initial server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value.

[0024] In one embodiment, the method further includes:

[0025] If there is a new server to be added to the hash ring and there are no server nodes on the hash ring, calculate the hash value of the new server's server address and server port to determine the node hash value of the new server.

[0026] The target server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value.

[0027] The new server is hash-mapped based on the target server node.

[0028] In one embodiment, after the step of hash mapping the new server based on the target server node, the method further includes:

[0029] Upon receiving a service request to be processed, the request hash value of the service request is determined based on the basic information of the service request;

[0030] The request node of the service request on the hash ring is determined by taking the modulo between the hash ring size and the request hash value.

[0031] Based on the server nodes existing on the hash ring and the request node of the service request on the hash ring, a processing server node is determined, which is used to process the service request.

[0032] Furthermore, to achieve the above objectives, this application also proposes a hash mapping device, which includes:

[0033] The processing module is used to determine the candidate server nodes of the new server on the hash ring based on the initial server node of the new server on the hash ring and the candidate offset angle when there is a new server to be added to the hash ring and there are server nodes on the hash ring.

[0034] The processing module is further configured to determine the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node on the hash ring and the ring spacing between the candidate server node and each server node on the hash ring.

[0035] The mapping module is used to perform hash mapping on the new server based on the target server node.

[0036] In addition, to achieve the above objectives, this application also proposes a hash mapping device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the hash mapping method as described above.

[0037] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the hash mapping method as described above.

[0038] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the hash mapping method as described above.

[0039] This application, when a new server is to be added to a hash ring and server nodes already exist on the hash ring, determines candidate server nodes for the new server on the hash ring based on the initial server node and candidate offset angles. It then determines the target server node for the new server on the hash ring based on the ring-wide spacing between the initial server node and other server nodes, and the ring-wide spacing between the candidate server node and other server nodes. Finally, it performs hash mapping on the new server based on the target server node. By using the initial server node of the new server on the hash ring and combining it with candidate offset angles to select candidate server nodes, and determining the final mapped node of the new server based on the ring-wide spacing of each position with other server nodes, the distribution of server nodes on the hash ring becomes more even. This effectively prevents data skew and avoids overloading of some server nodes. Furthermore, it eliminates the need for virtual nodes, significantly reducing system performance degradation, system maintenance costs, and hash calculation overhead, while improving system stability and scalability. Attached Figure Description

[0040] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0041] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0042] Figure 1 This is a flowchart illustrating the hash mapping method of this application in Embodiment 1.

[0043] Figure 2 A schematic diagram of a hash ring for the hash mapping method provided in Embodiment 1 of this application;

[0044] Figure 3 A schematic diagram of a virtual node for the hash mapping method provided in Embodiment 1 of this application;

[0045] Figure 4 This is a flowchart illustrating the second embodiment of the hash mapping method in this application.

[0046] Figure 5 This is a flowchart illustrating the hash mapping method of this application in Embodiment 3;

[0047] Figure 6 This is a schematic diagram of the module structure of the hash mapping device according to an embodiment of this application;

[0048] Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the hash mapping method in this application embodiment.

[0049] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0050] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0051] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0052] The main solution of this application embodiment is as follows: when there is a new server to be added to the hash ring and there are server nodes on the hash ring, the candidate server nodes of the new server on the hash ring are determined according to the initial server nodes and candidate offset angles of the new server on the hash ring; the target server node of the new server on the hash ring is determined according to the ring spacing between the initial server node and each server node on the hash ring and the ring spacing between the candidate server nodes and each server node on the hash ring; and the new server is hash-mapped according to the target server node.

[0053] In the daily operation of the Internet of Things (IoT), with the continuous increase in the number of smart devices, the IoT platform faces a large amount of data access pressure. Therefore, each server on the IoT platform is deployed in a distributed manner. To ensure that the various identical services in the IoT can evenly bear the network access pressure from the terminals, a load balancing strategy is adopted for the IoT platform. In the field of load balancing, consistent hashing algorithm is usually used to achieve load balancing. Consistent hashing algorithm has the following advantages: 1. Dynamic load balancing: When adding or removing server nodes, consistent hashing algorithm only needs to migrate a small amount of data, rather than globally redistributing it. This local data migration greatly reduces the complexity and cost of system expansion. 2. Monotonicity: When nodes are added or removed, only adjacent data is affected, and the position of most data remains unchanged. This characteristic makes the system more stable and efficient when facing node changes. 3. Balance: By using virtual nodes, consistent hashing algorithm can ensure that data is evenly distributed across different servers, avoiding hotspot problems and ensuring that each server bears a reasonable load. 4. Fault tolerance: When a node fails or is deleted, only the counter-clockwise real nodes are affected, not all nodes, which improves the fault tolerance and stability of the system. 5. Scalability: When adding or removing servers, only a small amount of data needs to be migrated, without causing a global redistribution of data, which makes the system easier to expand and maintain.

[0054] Currently, in actual hash mapping processes, the distribution of server nodes on the hash ring is uneven, causing most network traffic to concentrate on the same server node, thus leading to data skew. To address this issue, the consistent hashing algorithm introduces a virtual node mechanism. Virtual nodes are logical extensions of actual server nodes; by allocating multiple virtual nodes to each actual server node on the hash ring, the request distribution becomes more even. However, introducing virtual nodes introduces the following problems: 1. Increased system complexity. 2. Requires additional configuration and management to maintain the mapping relationship between virtual and actual nodes, increasing operational costs. 3. Calculating the data storage location requires first determining the virtual node and then finding the corresponding actual node, increasing the overhead of hash calculation and lookup, which may impact system performance, especially with large data volumes and frequent requests.

[0055] This application provides a solution that selects candidate server nodes for the new server on the hash ring by using the initial server node of the new server on the hash ring and the candidate offset angle. Based on the ring distance between each position and other server nodes, the final mapped node of the new server is determined, making the distribution of server nodes on the hash ring more uniform. This effectively prevents data skew and avoids the situation where some server nodes are overloaded. At the same time, it eliminates the need to introduce virtual nodes, significantly reducing system performance loss, system operation and maintenance costs, and hash calculation overhead, while improving system stability and scalability.

[0056] It should be noted that the execution subject in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or a hash mapping device capable of performing the above functions. The following description uses a hash mapping device as the execution subject to illustrate this embodiment and the subsequent embodiments.

[0057] Based on this, the embodiments of this application provide a hash mapping method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the hash mapping method of this application.

[0058] In this embodiment, the hash mapping method includes steps S10 to S40:

[0059] Step S10: If there is a new server to be added to the hash ring and there are server nodes on the hash ring, determine the candidate server nodes of the new server on the hash ring based on the initial server node of the new server on the hash ring and the candidate offset angle.

[0060] It's important to note that the commonly used consistent hashing algorithm generally follows these steps: 1. Constructing a hash ring: The hash ring is a circular array that all server nodes and requests rely on for sorting and calculation. 2. Hash mapping: Calculate the hash value of each node using a hash function and then assign it to its corresponding position on the hash ring. 3. Request processing: When a new request arrives, calculate its hash value using a hash function and map it to a position on the hash ring. Once located, find a node with a larger hash value than the request along the hash ring clockwise. 4. Node addition / removal: When adding or deleting a server node, only requests near the affected node's hash mapping will change; the mapping of other nodes remains unchanged. 5. Virtual nodes: To address node skew, the concept of virtual nodes is introduced. Each actual node can correspond to multiple virtual nodes on the hash ring, making the node mapping more even and improving load balancing. 6. Repetition: Repeat steps 3-6 to achieve continuous load balancing.

[0061] Understandably, without the introduction of a virtual node mechanism, consistent hashing algorithms can lead to uneven data distribution and data skew, such as... Figure 2 As shown, server nodes Node1, Node2, and Node3 are densely clustered along a small arc on the right side of the hash ring. When the distribution of server nodes on the hash ring is not random enough, or when the hash values ​​of the data themselves exhibit clustering, some server nodes may be responsible for an excessively large range of data, while other server nodes may have a lighter load. This situation can cause some server nodes to bear excessive request and data storage pressure, while the resources of other server nodes are not fully utilized, thus affecting the performance and scalability of the entire system.

[0062] In practical implementation, after the consistent hashing algorithm introduces a virtual node mechanism, such as Figure 3 As shown, the virtual nodes Node1ˋ, Node2ˋ, and Node3ˋ are logical extensions of the actual server nodes Node1, Node2, and Node3, increasing the node size and thus increasing the complexity of node maintenance and management.

[0063] It should be noted that the purpose of this embodiment is to solve the data skew problem of the consistent hashing algorithm without introducing a virtual node mechanism, so as to make the server nodes on the hash ring more evenly distributed and thus avoid the situation where some nodes are overloaded.

[0064] It is understood that a new server refers to a physical or virtual server to be added to the hash ring; the initial server node is the default position point on the hash ring that the server is mapped to after hash function calculation; the candidate offset angle is used to offset the initial position of the new server; the candidate server node is the position point obtained by offsetting the initial server node with the candidate offset angle. In this embodiment, the candidate offset angle is set to 180°, but it can also be dynamically generated by an algorithm, such as random numbers, deterministic formulas, or other methods. This embodiment does not limit this.

[0065] In this implementation, taking a candidate offset angle of 180° as an example, when there is a new server to be added to the hash ring, and one or more server nodes already exist on the hash ring, the initial server node NodeN of the new server on the hash ring is determined based on the new server's IP (Internet Protocol) address and port number, combined with the hash function. Each input of variable length will produce a uniform fixed-length output after being calculated by the hash function. The hash function can be MD5, SHA-1, or other function algorithms, etc. This embodiment does not restrict the choice of hash function.

[0066] It should be noted that after obtaining the initial server node NodeN, the node that is 180° away from the initial server node NodeN on the hash ring is searched and marked as the candidate server node NodeNˋ of the new server on the hash ring.

[0067] In one feasible implementation, steps A11 to A12 may be included before step S10:

[0068] Step A11: Calculate the hash value of the server address and server port of the new server to determine the node hash value of the new server.

[0069] It should be noted that the server address refers to the IP address of the new server, which can also be a unique identifier for other new servers on the network. The server port refers to the communication port number of the application on the new server. The server address and server port of the new server are combined into a string, and a hash function is used to calculate the hash value Hash1 of the combined string. This fixed-length hash value is the node hash value Hash1 of the new server.

[0070] Step A12: Determine the initial server node of the new server on the hash ring by performing a modulo operation based on the hash ring size and the node hash value.

[0071] It should be noted that the hash ring size refers to the upper limit of the range of values ​​that the hash ring can take, which is usually 2.n In this embodiment, the hash ring size is set to 2. 32 The node hash values ​​Hash1 and Hash2 are used to... 32 Taking the modulo of -1 (i.e., hash ring size - 1) yields the initial server node NodeN of the new server on the hash ring.

[0072] Step S20: Determine the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node on the hash ring, and the ring spacing between the candidate server node and each server node on the hash ring.

[0073] It should be noted that the ring spacing includes both clockwise and counterclockwise ring spacing. In this embodiment, the specific calculation formula for the clockwise ring spacing is as follows: Where S is the size of the hash ring, and H M H is the hash value of the original server node M on the hash ring. N This is the hash value of the initial server node NodeN or the candidate server node NodeN'. The specific formula for calculating the counter-clockwise ring spacing is as follows:

[0074] Understandably, based on the distance between the initial server node and each server node on the hash ring, and the distance between the candidate server node and each server node on the hash ring, a selection is made from the initial server node and the candidate server nodes. The selected server node is then used as the target server node for the new server on the hash ring, and the distance between the target server node and the original server nodes on the hash ring is the most evenly distributed.

[0075] In specific implementation, when selecting the target server node, the following methods can be used: calculate the sum or variance of the ring distances between the initial server node and all existing server nodes on the ring to evaluate the data distribution uniformity; calculate the sum or variance of the ring distances between the candidate server node and all existing server nodes on the ring to evaluate the data distribution uniformity. If the distance distribution of the candidate server node is more uniform, then the candidate server node is selected as the target server node; if the distance distribution of the initial server node is more uniform, then the initial server node is selected as the target server node. In this embodiment, in addition to the above methods, other methods can also be used to evaluate the distribution uniformity, and this embodiment does not limit this.

[0076] Step S30: Perform hash mapping on the new server based on the target server node.

[0077] It should be noted that formally mapping the new server to the target server node involves logically binding the new server's IP address, server port, and other physical identifiers to the target server node, forming a mapping relationship between the server instance and its location on the ring, updating the node distribution data structure of the hash ring, and synchronizing the information of the target server node to all relevant server nodes to ensure the consistency of routing rules within the cluster.

[0078] In one feasible implementation, the method may further include steps B11 to B13:

[0079] Step B11: If there is a new server to be added to the hash ring and there are no server nodes on the hash ring, calculate the hash value of the server address and server port of the new server to determine the node hash value of the new server.

[0080] It should be noted that when there is a new server to be added to the hash ring, and there are no server nodes on the hash ring, the server address and server port of the new server are combined into a string, and the combined string is calculated by a hash function to generate a fixed-length hash value Hash1. The fixed-length hash value is the node hash value Hash1 of the new server.

[0081] Step B12: Based on the hash ring size and the node hash value, perform modulo operation to determine the target server node of the new server on the hash ring.

[0082] Step B13: Perform hash mapping on the new server based on the target server node.

[0083] It should be noted that the node hash values ​​Hash1 and Hash2 are... 32 Taking the modulo operation of -1 (i.e., hash ring size - 1) yields the target server node NodeN on the hash ring for the new server. The new server is then formally mapped to the target server node. The IP address, port, and other physical identifiers of the new server are logically bound to the target server node, forming a mapping relationship between the server instance and its location on the ring. The node distribution data structure of the hash ring is updated, and the information of the target server node is synchronized to all relevant server nodes, ensuring the consistency of routing rules within the cluster.

[0084] The approach described in this embodiment offers the following advantages: 1. It avoids adding unnecessary nodes, requiring no additional configuration or management, and thus does not increase operational costs or hash calculation overhead. 2. By selecting a hash mapping node on the hash ring that promotes even node distribution for the new server, it ensures that each server node can uniformly handle network data requests, thereby improving the overall performance and stability of the system. 3. All server nodes on the hash ring are real physical nodes; there are no virtual nodes. This streamlined number of server nodes allows the server platform to quickly allocate a suitable server node based on the load balancing strategy when network data requests are sent to the server.

[0085] This embodiment determines candidate server nodes for the new server on the hash ring based on the initial server node and candidate offset angle, when a new server is to be added to the hash ring and server nodes exist on the hash ring. It then determines the target server node for the new server on the hash ring based on the ring-wide spacing between the initial server node and other server nodes, and the ring-wide spacing between the candidate server node and other server nodes. Finally, it performs hash mapping on the new server based on the target server node. By using the initial server node of the new server on the hash ring and combining it with the candidate offset angle to select candidate server nodes, and determining the final mapped node of the new server based on the ring-wide spacing of each position with other server nodes, the distribution of server nodes on the hash ring becomes more even. This effectively prevents data skew and avoids overloading some server nodes. Furthermore, it eliminates the need for virtual nodes, significantly reducing system performance degradation, system maintenance costs, and hash calculation overhead, while improving system stability and scalability.

[0086] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 4 The ring spacing in the hash mapping method includes the ring spacing corresponding to clockwise and the ring spacing corresponding to counterclockwise. Step S20 further includes steps S21 to S23:

[0087] Step S21: Calculate the distance difference based on the clockwise ring spacing between the initial server node and each server node on the hash ring and the counterclockwise ring spacing between the initial server node and each server node on the hash ring, and determine the absolute values ​​of multiple distance differences corresponding to the initial server node.

[0088] It should be noted that, for the initial server node NodeN: the clockwise and counterclockwise ring distances between the initial server node NodeN and each of the existing server nodes on the hash ring are obtained. Using the clockwise and counterclockwise ring distances between the initial server node NodeN and the same existing server nodes, the difference between the clockwise and counterclockwise ring distances is calculated and moduloed to obtain the absolute value of the distance difference. When there are multiple server nodes on the hash ring, the initial server node will correspond to multiple absolute distance differences M1, M2, M3...Mn.

[0089] Step S22: Calculate the distance difference between the candidate server node and each server node on the hash ring in a clockwise direction and in a counterclockwise direction, and determine the absolute values ​​of multiple distance differences corresponding to the candidate server node.

[0090] It should be noted that, for the candidate server node NodeNˋ: the clockwise and counterclockwise ring distances between the candidate server node NodeNˋ and each of the original server nodes on the hash ring are obtained. Using the clockwise and counterclockwise ring distances between the candidate server node NodeNˋ and the same original server node, the difference between the clockwise and counterclockwise ring distances is calculated and moduloed to obtain the absolute value of the distance difference. When there are multiple server nodes on the hash ring, the candidate server node NodeNˋ will correspond to multiple absolute distance differences M1ˋ, M2ˋ, M3ˋ...Mnˋ.

[0091] Step S23: Determine the target server node of the new server on the hash ring based on the multiple absolute values ​​of distance differences corresponding to the initial server node and the multiple absolute values ​​of distance differences corresponding to the candidate server nodes.

[0092] It should be noted that the data distribution uniformity is evaluated by calculating the sum or variance of the absolute values ​​of multiple distance differences corresponding to the initial server node NodeN; similarly, the data distribution uniformity is evaluated by calculating the sum or variance of the absolute values ​​of multiple distance differences corresponding to the candidate server nodes NodeNˋ. If the spacing distribution of the candidate server nodes is more uniform, the candidate server node is selected as the target server node; if the spacing distribution of the initial server nodes is more uniform, the initial server node is selected as the target server node. In this embodiment, other methods besides the above-described method can also be used to evaluate the distribution uniformity, and this embodiment does not limit this.

[0093] In one feasible implementation, step S23 may further include steps C11 to C13:

[0094] Step C11: Sum the absolute values ​​of multiple distance differences corresponding to the initial server node to determine the distribution uniformity score corresponding to the initial server node.

[0095] It should be noted that the sum of the absolute values ​​of the multiple distance differences M1, M2, M3...Mn corresponding to the initial server node NodeN is the distribution uniformity score DN corresponding to the initial server node.

[0096] Step C12: Sum the absolute values ​​of multiple distance differences corresponding to the candidate server nodes to determine the distribution uniformity score corresponding to the candidate server nodes.

[0097] It should be noted that the result of summing up the absolute values ​​of the multiple distance differences M1ˋ, M2ˋ, M3ˋ...Mnˋ corresponding to the candidate server node NodeNˋ is the distribution uniformity score DNˋ corresponding to the candidate server node.

[0098] Step C13: Determine the target server node of the new server on the hash ring based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server node.

[0099] It should be noted that by comparing the distribution uniformity score DN corresponding to the initial server node and the distribution uniformity score DNˋ corresponding to the candidate server node, the relationship between the two is obtained. The smaller the distribution uniformity score, the more evenly the server nodes are distributed when mapped onto the hash ring. The node with the smaller score is selected as the target server node of the new server on the hash ring.

[0100] In one feasible implementation, step C13 may further include steps D11 to D13:

[0101] Step D11: Compare the distribution uniformity score corresponding to the initial server node with the distribution uniformity score corresponding to the candidate server node.

[0102] Step D12: When the distribution uniformity score corresponding to the initial server node is less than the distribution uniformity score corresponding to the candidate server node, the initial server node is selected as the target server node of the new server on the hash ring.

[0103] It should be noted that the distribution uniformity score DN corresponding to the initial server node and the distribution uniformity score DNˋ corresponding to the candidate server node are compared to determine their relative magnitudes. If the distribution uniformity score DN corresponding to the initial server node is smaller than the distribution uniformity score DNˋ corresponding to the candidate server node, it indicates that mapping the initial server node NodeN onto the hash ring makes the distribution of server nodes more even. In this case, the initial server node NodeN is taken as the target server node for the new server on the hash ring, and the candidate server node NodeNˋ is deleted.

[0104] Step D13: When the distribution uniformity score corresponding to the initial server node is greater than or equal to the distribution uniformity score corresponding to the candidate server node, the candidate server node is selected as the target server node of the new server on the hash ring.

[0105] It should be noted that if the distribution uniformity score DN corresponding to the initial server node is greater than or equal to the distribution uniformity score DNˋ corresponding to the candidate server node, it means that the distribution of each server node is more uniform after the candidate server node NodeNˋ is mapped onto the hash ring. In this case, the candidate server node NodeNˋ is taken as the target server node of the new server on the hash ring, and the initial server node NodeN is deleted.

[0106] This embodiment determines multiple absolute values ​​of distance differences corresponding to the initial server node by calculating the distance differences between the initial server node and each other on the hash ring in clockwise and counterclockwise directions. Similarly, it determines multiple absolute values ​​of distance differences corresponding to the candidate server nodes by calculating the distance differences between the candidate server nodes and each other on the hash ring in clockwise and counterclockwise directions. Finally, it determines the target server node of the new server on the hash ring based on these multiple absolute values ​​of distance differences. This method accurately determines the target server node of the new server on the hash ring, resulting in a more even distribution of server nodes on the ring.

[0107] Based on the first embodiment of this application, in the third embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 5 After step S30, the hash mapping method further includes steps S31 to S32:

[0108] Step S01: Upon receiving a service request to be processed, determine the request hash value of the service request based on the basic information of the service request.

[0109] It should be noted that basic information includes, but is not limited to, the URL (Uniform Resource Locator) of the service request and parameter values ​​used to describe the specific requirements of the request.

[0110] Understandably, when a service request that needs to be sent by the terminal device is received, a hash function is used to calculate the basic information of the service request, generating a fixed-length hash value Hash2. This fixed-length hash value Hash2 is the request hash value of the service request. In this embodiment, if there are multiple information items (such as URL, parameter values, etc.) in the basic information, these multiple information items are combined into a string, and the hash function is used to calculate the request hash value.

[0111] Step S02: Perform modulo operation based on the hash ring size and the request hash value to determine the request node of the service request on the hash ring.

[0112] It should be noted that the request hash value Hash2 and the hash ring size -1 (e.g., 2) are used. 32 -1) Take the modulo to get the request node R1 of the service request on the hash ring.

[0113] Step S03: Determine the processing server node based on the server nodes existing on the hash ring and the request node of the service request on the hash ring. The processing server node is used to process the service request.

[0114] It should be noted that, based on the existing server nodes on the hash ring, the first server node greater than or equal to the request node R1 is found along the clockwise direction of the hash ring, and this is used as the processing server node to handle the service request.

[0115] This embodiment determines the request hash value of a service request based on its basic information upon receiving it; it then determines the request node on the hash ring by performing a modulo operation based on the hash ring size and the request hash value; finally, it determines a processing server node based on the existing server nodes on the hash ring and the request node of the service request on the hash ring. This processing server node is used to process the service request. Through this method, load balancing is achieved, ensuring the stability of request processing.

[0116] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the hash mapping method of this application. Any simple transformations based on this technical concept are within the protection scope of this application.

[0117] This application also provides a hash mapping device, please refer to... Figure 6 The hash mapping device includes:

[0118] Processing module 10 is used to determine the candidate server node of the new server on the hash ring based on the initial server node of the new server on the hash ring and the candidate offset angle when there is a new server to be added to the hash ring and there are server nodes on the hash ring.

[0119] The processing module 10 is further configured to determine the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node on the hash ring and the ring spacing between the candidate server node and each server node on the hash ring.

[0120] The mapping module 20 is used to perform hash mapping on the new server based on the target server node.

[0121] Optionally, the processing module 10 is further configured to:

[0122] The distance difference is calculated based on the clockwise ring spacing between the initial server node and each server node on the hash ring and the counterclockwise ring spacing between the initial server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the initial server node are determined.

[0123] The distance difference is calculated based on the clockwise ring spacing between the candidate server node and each server node on the hash ring and the counterclockwise ring spacing between the candidate server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the candidate server node are determined.

[0124] The target server node of the new server on the hash ring is determined based on the absolute values ​​of multiple distance differences corresponding to the initial server node and the absolute values ​​of multiple distance differences corresponding to the candidate server nodes.

[0125] Optionally, the processing module 10 is further configured to:

[0126] The absolute values ​​of multiple distance differences corresponding to the initial server node are summed to determine the distribution uniformity score corresponding to the initial server node.

[0127] The absolute values ​​of multiple distance differences corresponding to the candidate server nodes are summed to determine the distribution uniformity score corresponding to the candidate server nodes.

[0128] Based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server node, the target server node of the new server on the hash ring is determined.

[0129] Optionally, the processing module 10 is further configured to:

[0130] The distribution uniformity score corresponding to the initial server node is compared with the distribution uniformity score corresponding to the candidate server node;

[0131] When the distribution uniformity score corresponding to the initial server node is less than the distribution uniformity score corresponding to the candidate server node, the initial server node is taken as the target server node of the new server on the hash ring.

[0132] When the distribution uniformity score corresponding to the initial server node is greater than or equal to the distribution uniformity score corresponding to the candidate server node, the candidate server node is selected as the target server node of the new server on the hash ring.

[0133] Optionally, the processing module 10 is further configured to:

[0134] The hash value of the new server is determined by calculating the hash value of the server address and server port.

[0135] The initial server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value.

[0136] Optionally, the processing module 10 is further configured to:

[0137] If there is a new server to be added to the hash ring and there are no server nodes on the hash ring, calculate the hash value of the new server's server address and server port to determine the node hash value of the new server.

[0138] The target server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value.

[0139] The new server is hash-mapped based on the target server node.

[0140] Optionally, the mapping module 20 is further configured to:

[0141] Upon receiving a service request to be processed, the request hash value of the service request is determined based on the basic information of the service request;

[0142] The request node of the service request on the hash ring is determined by taking the modulo between the hash ring size and the request hash value.

[0143] Based on the server nodes existing on the hash ring and the request node of the service request on the hash ring, a processing server node is determined, which is used to process the service request.

[0144] The hash mapping device provided in this application, employing the hash mapping method in the above embodiments, can solve the technical problem of how to effectively resolve data skew while reducing system complexity and performance loss. Compared with the prior art, the beneficial effects of the hash mapping device provided in this application are the same as those of the hash mapping method provided in the above embodiments, and other technical features in the hash mapping device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0145] This application provides a hash mapping device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the hash mapping method in Embodiment 1 above.

[0146] The following is for reference. Figure 7 The diagram illustrates a structural schematic of a hash mapping device suitable for implementing embodiments of this application. The hash mapping device in these embodiments may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 7 The hash mapping device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0147] like Figure 7As shown, the hash mapping device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the hash mapping device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the hash mapping device to communicate wirelessly or wiredly with other devices to exchange data. While the figure shows hash mapping devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0148] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0149] The hash mapping device provided in this application, employing the hash mapping method described in the above embodiments, can solve the technical problem of how to effectively resolve data skew while reducing system complexity and performance loss. Compared with the prior art, the beneficial effects of the hash mapping device provided in this application are the same as those of the hash mapping method provided in the above embodiments, and other technical features of this hash mapping device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0150] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0151] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0152] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the hash mapping method in the above embodiments.

[0153] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0154] The aforementioned computer-readable storage medium may be included in a hash mapping device; or it may exist independently and not be assembled into a hash mapping device.

[0155] The aforementioned computer-readable storage medium carries one or more programs that, when executed by a hash mapping device, cause the hash mapping device to: determine, when a new server to be added to the hash ring exists and server nodes exist on the hash ring, a candidate server node for the new server on the hash ring based on the initial server node and candidate offset angle of the new server on the hash ring; determine a target server node for the new server on the hash ring based on the ring-on-ring spacing between the initial server node and each server node, and the ring-on-ring spacing between the candidate server node and each server node on the hash ring; and perform hash mapping on the new server based on the target server node.

[0156] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0157] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0158] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0159] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described hash mapping method. This solves the technical problem of effectively addressing data skew while reducing system complexity and performance degradation. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the hash mapping method provided in the above embodiments, and will not be repeated here.

[0160] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the hash mapping method described above.

[0161] The computer program product provided in this application can solve the technical problem of how to effectively resolve data skew while reducing system complexity and performance loss. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the hash mapping method provided in the above embodiments, and will not be repeated here.

[0162] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A hash mapping method, characterized in that, The method includes: In the case where there is a new server to be added to the hash ring and there are server nodes on the hash ring, the candidate server nodes of the new server on the hash ring are determined based on the initial server node of the new server on the hash ring and the candidate offset angle. Based on the ring spacing between the initial server node and each server node on the hash ring, and the ring spacing between the candidate server node and each server node on the hash ring, the target server node of the new server on the hash ring is determined. The new server is hash-mapped based on the target server node.

2. The method as described in claim 1, characterized in that, The ring spacing includes the ring spacing corresponding to clockwise and the ring spacing corresponding to counterclockwise; The step of determining the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node, and the ring spacing between the candidate server node and each server node, includes: The distance difference is calculated based on the clockwise ring spacing between the initial server node and each server node on the hash ring and the counterclockwise ring spacing between the initial server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the initial server node are determined. The distance difference is calculated based on the clockwise ring spacing between the candidate server node and each server node on the hash ring and the counterclockwise ring spacing between the candidate server node and each server node on the hash ring, and the absolute values ​​of multiple distance differences corresponding to the candidate server node are determined. The target server node of the new server on the hash ring is determined based on the absolute values ​​of multiple distance differences corresponding to the initial server node and the absolute values ​​of multiple distance differences corresponding to the candidate server nodes.

3. The method as described in claim 2, characterized in that, The step of determining the target server node of the new server on the hash ring based on the absolute values ​​of multiple distance differences corresponding to the initial server node and the absolute values ​​of multiple distance differences corresponding to the candidate server nodes includes: The absolute values ​​of multiple distance differences corresponding to the initial server node are summed to determine the distribution uniformity score corresponding to the initial server node. The absolute values ​​of multiple distance differences corresponding to the candidate server nodes are summed to determine the distribution uniformity score corresponding to the candidate server nodes. Based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server node, the target server node of the new server on the hash ring is determined.

4. The method as described in claim 3, characterized in that, The step of determining the target server node of the new server on the hash ring based on the distribution uniformity score corresponding to the initial server node and the distribution uniformity score corresponding to the candidate server node includes: The distribution uniformity score corresponding to the initial server node is compared with the distribution uniformity score corresponding to the candidate server node; When the distribution uniformity score corresponding to the initial server node is less than the distribution uniformity score corresponding to the candidate server node, the initial server node is taken as the target server node of the new server on the hash ring. When the distribution uniformity score corresponding to the initial server node is greater than or equal to the distribution uniformity score corresponding to the candidate server node, the candidate server node is selected as the target server node of the new server on the hash ring.

5. The method as described in claim 1, characterized in that, Before the step of determining the candidate server nodes of the new server on the hash ring based on the initial server nodes and candidate offset angles of the new server on the hash ring, the method further includes: The hash value of the new server is determined by calculating the hash value of the server address and server port. The initial server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value.

6. The method as described in claim 1, characterized in that, The method further includes: If there is a new server to be added to the hash ring and there are no server nodes on the hash ring, calculate the hash value of the new server's server address and server port to determine the node hash value of the new server. The target server node of the new server on the hash ring is determined by taking the modulo between the hash ring size and the node hash value. The new server is hash-mapped based on the target server node.

7. The method according to any one of claims 1 to 6, characterized in that, After the step of performing hash mapping on the new server based on the target server node, the method further includes: Upon receiving a service request to be processed, the request hash value of the service request is determined based on the basic information of the service request; The request node of the service request on the hash ring is determined by taking the modulo between the hash ring size and the request hash value. Based on the server nodes existing on the hash ring and the request node of the service request on the hash ring, a processing server node is determined, which is used to process the service request.

8. A hash mapping device, characterized in that, The hash mapping device includes: The processing module is used to determine the candidate server nodes of the new server on the hash ring based on the initial server node of the new server on the hash ring and the candidate offset angle when there is a new server to be added to the hash ring and there are server nodes on the hash ring. The processing module is further configured to determine the target server node of the new server on the hash ring based on the ring spacing between the initial server node and each server node on the hash ring and the ring spacing between the candidate server node and each server node on the hash ring. The mapping module is used to perform hash mapping on the new server based on the target server node.

9. A hash mapping device, characterized in that, The device includes: a memory, a processor, and a hash mapping program stored in the memory and executable on the processor, the hash mapping program being configured to implement the steps of the hash mapping method as described in any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium stores a hash mapping program, which, when executed by a processor, implements the steps of the hash mapping method as described in any one of claims 1 to 7.