Distributed load state calculation method of bounded load consistency hash
By dividing node hashes into slots in a distributed system and using consistent hashing algorithms for task allocation and resource management, the problem of uneven load distribution and information asynchronousness is solved, and the consistency of load status and system performance are achieved. promote.
Patent Information
- Application Number
- CN202410808207.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-10-15
Smart Images

Figure CN118779098A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed technology, and in particular to a distributed load state calculation method of bounded load consistent hashing. Background Art
[0002] In a distributed system, the distribution of data and tasks usually needs to be carried out across multiple nodes. The traditional consistent hashing algorithm is widely used in load balancing of distributed systems due to its simplicity and effectiveness. However, the traditional consistent hashing algorithm has the problem of uneven load distribution, which may cause some nodes to be overloaded while other nodes may be idle. In addition, due to the limited load, the back-end load status calculation and update in a distributed environment cannot be synchronized between nodes, further exacerbating the problem of load imbalance.
[0003] In a distributed system, each node needs to regularly report its load status, calculate and update the load status. However, due to network delays and inconsistencies in data transmission, the load information of each node may be out of sync. This results in the load of some nodes being overestimated or underestimated during task allocation, thus affecting the load balancing effect of the overall system. Summary of the invention
[0004] The purpose of the present invention is to solve the shortcomings of the above-mentioned prior art and provide a distributed load state calculation method of bounded load consistent hashing, aiming to achieve consistency of load state calculation and update through a distributed method, ensure information synchronization of each node in the load distribution process, thereby improving the overall performance and reliability of the distributed system, including the following steps:
[0005] S1: Divide the node hash into different slots, each slot corresponds to a scheduler, and each scheduler autonomously manages its own nodes;
[0006] S2: When processing a request, first perform a hash calculation on the request to determine its corresponding slot, and then forward the request to the scheduler that manages the slot;
[0007] S3: Perform secondary scheduling. The scheduler uses a consistent hashing algorithm to select a suitable node from the nodes it manages for task allocation and performs corresponding resource deductions.
[0008] S4: Through slot division and secondary search mechanism, ensure that the load information of each node remains consistent in the distributed system.
[0009] Furthermore, in step S1, when the scheduler processes a request, it routes the request to a correct slot and a node to which the slot is assigned, and data is shared among different nodes through the slot.
[0010] Preferably, the allocation of the slots is dynamically adjusted according to the performance of each node, and each node automatically monitors and recovers changes in the allocation of its slots. The slots can be transferred between different nodes. If a node fails, all the slots it is responsible for are quickly transferred to other healthy nodes.
[0011] Furthermore, in step S2, a hash algorithm with a high conflict avoidance rate and efficient computing speed is selected to ensure that each request can be quickly and uniquely mapped to a target slot, specifically including:
[0012] When the request reaches any node, the key flag of the request is processed by the hash algorithm to generate a unique hash value, the node responsible for processing the request is determined based on the hash ring and the hash value, and the request is forwarded to the target slot of the node.
[0013] Furthermore, in step S3, the secondary scheduling process ensures that each node performs load calculation in one scheduler, thereby avoiding over-allocation problems caused by asynchronous node load information.
[0014] Wherein, step S3 specifically includes:
[0015] Using the consistent hashing algorithm, each node is mapped to a hash ring through a hash value;
[0016] When a task arrives, the hash value of the task is calculated, and the first node encountered in the clockwise direction on the hash ring is found, and the task is assigned to this node;
[0017] Once the task is assigned to the node, the corresponding resource amount is deducted from the resources of the node to reflect the usage of the resources.
[0018] Furthermore, step S4 specifically includes:
[0019] The slot division is to store data in multiple nodes according to certain rules, that is, to evenly distribute the load to each node, so that each node is only responsible for responding to a part of the data requests, so as to realize parallel processing of more requests;
[0020] The data is sharded in the order in which it arrives. After a search locates the approximate shard, a second precise search is performed within the shard to ensure data accuracy and consistency.
[0021] Compared with the prior art, the present invention has the following beneficial effects:
[0022] (1) The present invention achieves consistency in load state calculation and update through a distributed method, ensuring information synchronization of each node during the load distribution process;
[0023] (2) The present invention ensures the independence of load distribution between schedulers by slot division;
[0024] (3) The present invention ensures that each node performs load calculation in only one scheduler through consistent load calculation, thus avoiding the over-allocation problem caused by asynchronous node load information; BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0026] In the attached picture:
[0027] Figure 1 A flow chart of a distributed load state calculation method of bounded load consistent hashing according to the present invention; DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0029] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0030] Consistent hashing algorithms are widely used in distributed systems, especially in scenarios where nodes need to be added or removed dynamically. By mapping each node to one or more virtual nodes on the hash ring, data storage can be decentralized to achieve load balancing. When adding or removing nodes, only part of the data needs to be redistributed without affecting the entire system.
[0031] The specific implementation of the present invention is described below with reference to the accompanying drawings and embodiments.
[0032] Example 1
[0033] like Figure 1 As shown, this embodiment provides a distributed load state calculation method of bounded load consistent hashing, including the following steps:
[0034] S1: Divide the node hash into different slots, each slot corresponds to a scheduler, and each scheduler autonomously manages its own nodes;
[0035] S2: When processing a request, first perform a hash calculation on the request to determine its corresponding slot, and then forward the request to the scheduler that manages the slot;
[0036] S3: Perform secondary scheduling. The scheduler uses a consistent hashing algorithm to select a suitable node from the nodes it manages for task allocation and performs corresponding resource deductions.
[0037] S4: Through slot division and secondary search mechanism, ensure that the load information of each node remains consistent in the distributed system.
[0038] In step S1, when the scheduler processes a request, it routes the request to the correct slot and the node to which the slot is assigned, and data is shared among different nodes through the slot.
[0039] Specifically, each scheduler is responsible for managing its assigned slots, including operations such as data storage, access, and migration. The scheduler can make independent decisions on how to optimize the data it manages, such as balancing the load through data migration. Since each scheduler only manages specific slots, the failure of a single node or scheduler will not affect other nodes, thereby improving the availability and stability of the system. The scheduler can dynamically adjust the data distribution according to the real-time load situation to ensure load balancing on each node and avoid hot spots.
[0040] This embodiment dynamically adjusts the allocation of the slots according to the performance of each node. Each node automatically monitors and recovers changes in the allocation of its slots. The slots can be transferred between different nodes. If a node fails, all the slots it is responsible for are quickly transferred to other healthy nodes.
[0041] In step S2, a hash algorithm with a high conflict avoidance rate and efficient computation speed is selected to ensure that each request can be quickly and uniquely mapped to the target slot, including:
[0042] When the request reaches any node, the key flag of the request is processed by the hash algorithm to generate a unique hash value, the node responsible for processing the request is determined based on the hash ring and the hash value, and the request is forwarded to the target slot of the node.
[0043] Specifically, in this embodiment, this strategy is mainly used in scenarios such as cache systems, database sub-libraries and sub-tables, and various distributed storage systems. The consistent hashing algorithm maps the entire hash value space into a virtual ring, calculates the hash value of each server node and maps it to the hash ring, then uses the hash algorithm to calculate the corresponding hash value for the data request sent by the service, and maps the calculated hash value to the hash ring, while searching in a clockwise direction along the ring, and the first server encountered is the corresponding server for processing the request.
[0044] In practical applications, the advantage of this strategy lies in its excellent scalability and load balancing capabilities. When the number of servers changes, the hash algorithm can ensure that only a minimum amount of data and requests need to be relocated, while most other data is not affected. This greatly reduces the data migration cost when the system is expanded or reduced in capacity.
[0045] By performing hash calculations on requests and forwarding them to the scheduler that manages the corresponding slot, load balancing and data routing can be effectively achieved, improving system performance and scalability. In actual applications, it is also necessary to combine specific business needs and technical environments, and continuously optimize hash algorithms and system architectures to adapt to complex and changing distributed system requirements.
[0046] Furthermore, in step S3, the secondary scheduling process ensures that each node performs load calculation in one scheduler, thereby avoiding over-allocation problems caused by asynchronous node load information.
[0047] Specifically, step S3 includes:
[0048] Using the consistent hashing algorithm, each node is mapped to a hash ring through a hash value;
[0049] When a task arrives, the hash value of the task is calculated, and the first node encountered in the clockwise direction on the hash ring is found, and the task is assigned to this node;
[0050] Once the task is assigned to the node, the corresponding resource amount is deducted from the resources of the node to reflect the usage of the resources.
[0051] Here is some sample code on how to use consistent hashing for task allocation:
[0052]
[0053]
[0054] We created a ConsistentHash class that can add and remove nodes, as well as get the node that should be assigned to a task based on its key. The hash method is used to generate hash values for nodes and tasks.
[0055] Furthermore, step S4 specifically includes:
[0056] The slot division is to store data in multiple nodes according to certain rules, that is, to evenly distribute the load to each node, so that each node is only responsible for responding to a part of the data requests, so as to realize parallel processing of more requests;
[0057] The data is sharded in the order in which it arrives. After a search locates the approximate shard, a second precise search is performed within the shard to ensure data accuracy and consistency.
[0058] Among them, data sharding allows the system to process multiple data requests in parallel, improving efficiency. At the same time, when a node fails, it will not affect the operation of the entire system, enhancing the robustness of the system. The secondary search mechanism is used when the data is divided into very fine granularity and the query requires very high precision. The secondary search can greatly improve the availability and accuracy of the data.
[0059] In summary, the present invention achieves consistency in load state calculation and update in a distributed scheduler through an improved bounded load consistent hashing architecture, effectively avoids the problem of over-allocation of back-end nodes under bounded load, and improves the load balancing effect and overall performance of the system.
[0060] Finally, it should be noted that the above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
[0061] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A distributed load state calculation method for bounded load consistent hashing, characterized in that: The steps include: S1: Divide the node hash into different slots, each slot corresponds to a scheduler, and each scheduler autonomously manages its own nodes; S2: When processing a request, first perform a hash calculation on the request to determine its corresponding slot, and then forward the request to the scheduler that manages the slot; S3: Perform secondary scheduling. The scheduler uses a consistent hashing algorithm to select a suitable node from the nodes it manages for task allocation and performs corresponding resource deductions. S4: Through slot division and secondary search mechanism, ensure that the load information of each node remains consistent in the distributed system.
2. The distributed load state calculation method of bounded load consistent hashing according to claim 1 is characterized in that: In step S1, when the scheduler processes a request, it routes the request to the correct slot and the node to which the slot is assigned, and data is shared among different nodes through the slot.
3. The distributed load state calculation method of bounded load consistent hashing according to claim 2 is characterized in that: The allocation of the slots is dynamically adjusted according to the performance of each node. Each node automatically monitors and recovers changes in the allocation of its slots. The slots can be transferred between different nodes. If a node fails, all the slots it is responsible for are quickly transferred to other healthy nodes.
4. The distributed load state calculation method of bounded load consistent hashing according to claim 1 is characterized in that: In step S2, a hash algorithm with a high conflict avoidance rate and efficient computation speed is selected to ensure that each request can be quickly and uniquely mapped to the target slot, including: When the request reaches any node, the key flag of the request is processed by the hash algorithm to generate a unique hash value, the node responsible for processing the request is determined based on the hash ring and the hash value, and the request is forwarded to the target slot of the node.
5. The distributed load state calculation method of bounded load consistent hashing according to claim 1 is characterized in that: In step S3, the secondary scheduling process ensures that each node performs load calculation in one scheduler to avoid over-allocation problems caused by asynchronous node load information.
6. The distributed load state calculation method of bounded load consistent hashing according to claim 5 is characterized in that: Step S3 specifically includes: Using the consistent hashing algorithm, each node is mapped to a hash ring through a hash value; When a task arrives, the hash value of the task is calculated, and the first node encountered in the clockwise direction on the hash ring is found, and the task is assigned to this node; Once the task is assigned to the node, the corresponding resource amount is deducted from the resources of the node to reflect the usage of the resources.
7. The distributed load state calculation method of bounded load consistent hashing according to claim 1 is characterized in that: Step S4 specifically includes: The slot division is to store data in multiple nodes according to certain rules, that is, to evenly distribute the load to each node, so that each node is only responsible for responding to a part of the data requests, so as to realize parallel processing of more requests; The data is sharded in the order in which it arrives. After a search locates the approximate shard, a second precise search is performed within the shard to ensure data accuracy and consistency.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the distributed load state calculation method of bounded load consistent hashing as described in any one of claims 1-7 is implemented.
9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the distributed load state calculation method of bounded load consistent hashing as described in any one of claims 1-7.
Citation Information
Cited By
Session sharing method and device, storage medium and computer equipment
CN120915830A
