A consensus reaching method, node, storage medium and program product

By constructing a node priority model and a comprehensive priority mechanism in the distributed system, the problem that Paxos and Raft algorithms failed to fully evaluate node performance during leader election and log replication is solved. This enables efficient election and dynamic replacement of leader nodes, improves system stability and reliability, and meets the high-efficiency computing needs of the AI ​​era.

CN120750928BActive Publication Date: 2026-02-24CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511251088.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-03
Publication Date
2026-02-24
Estimated Expiration
2045-09-03

AI Technical Summary

Technical Problem

Existing Paxos and Raft consensus algorithms suffer from complexity, real-time issues, and network sensitivity when achieving consensus among nodes, resulting in poor performance and insufficient reliability. In particular, they fail to fully assess the overall performance of nodes during leader election and log replication, affecting the stability and reliability of the system.

Method used

By having candidate nodes determine their own performance metrics and send election requests to follower nodes, and dynamically replace the leader node when its performance or network environment is poor, a node priority model is constructed using multi-dimensional performance metrics to ensure that the candidate node with the best performance is elected as the leader. A dynamic leader replacement mechanism based on comprehensive priority is proposed.

Benefits of technology

It improves the accuracy of leader node election and system stability, ensures high-performance leader node election, enhances the overall performance and reliability of the system, adapts to network and performance changes, and meets the needs of real-time data analysis and efficient computing in the AI ​​era.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120750928B_ABST
    Figure CN120750928B_ABST
Patent Text Reader

Abstract

The application discloses a consensus reaching method, a node, a storage medium and a program product. The method comprises the following steps: a candidate node determines a node priority according to a performance index of the candidate node, and sends an election request to a follower node, wherein the election request at least comprises the node priority; the candidate node receives a vote sent by one or more follower nodes in response to the election request, and determines whether to become a leader node according to a number of favorable votes obtained; in a case that it is determined to become the leader node, the candidate node determines a first comprehensive priority according to the performance index of the candidate node and network environment information, sends a heartbeat message to the follower node, wherein the heartbeat message comprises the first comprehensive priority; and the candidate node receives a heartbeat response sent by one or more follower nodes in response to the heartbeat message, and determines whether to replace the leader node according to a number of opposing votes in the heartbeat response.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed systems technology, specifically to a consensus-reaching method, a node, a storage medium, and a program product. Background Technology

[0002] In the context of rapid development in information technology, the emergence of the Internet and data centers has promoted the decentralization and sharing of computing resources, giving rise to the widespread application of distributed systems. However, distributed systems face the challenge of consistency issues when achieving high availability and reliability. If nodes cannot reach consensus, it may lead to data inconsistency and system unpredictability, which can have serious consequences in critical business scenarios. Therefore, how to achieve consistency among nodes has become a core issue in distributed system design. Against this backdrop, Paxos and Raft consensus algorithms have emerged.

[0003] The complexity of Paxos implementations often poses a challenge for developers. Furthermore, Paxos operations are sensitive to real-time performance and network conditions, potentially leading to poor performance in unstable network environments. In the Raft algorithm, the leader election mechanism fails to comprehensively evaluate the overall performance of nodes, which may result in the elected leader being unable to efficiently complete log replication and request processing in practical applications, thus impacting the overall system performance and reliability. Additionally, the Raft algorithm does not proactively replace the current leader node in the event of an anomaly, potentially leading to system instability and affecting system reliability and security. Summary of the Invention

[0004] To address the existing technical problems, embodiments of the present invention provide a consensus-reaching method, a node, a storage medium, and a program product.

[0005] To achieve the above objectives, the technical solution of this invention is implemented as follows:

[0006] This invention provides a consensus-reaching method, the method comprising:

[0007] Candidate nodes determine their node priorities based on their own performance metrics and send election requests to follower nodes, wherein the election requests include at least the node priorities.

[0008] Receive votes from one or more follower nodes in response to the election request, and determine whether to become the leader node based on the number of affirmative votes received;

[0009] Once determined to become the leader node, it determines a first comprehensive priority based on its own performance indicators and network environment information, and sends a heartbeat message to the follower nodes, wherein the heartbeat message includes the first comprehensive priority.

[0010] The leader node is determined to be replaced based on the number of dissenting votes in the heartbeat response sent by one or more follower nodes.

[0011] In the above scheme, the candidate nodes determine their priority based on their own performance indicators, including:

[0012] The candidate node determines the tolerance parameter corresponding to each performance indicator based on its own performance indicators and the corresponding threshold. The tolerance parameter represents the performance of the candidate node.

[0013] Node priorities are determined based on the tolerance parameters corresponding to each performance indicator.

[0014] In the above scheme, determining the first comprehensive priority based on its own performance indicators and network environment information includes: determining the first tolerance parameter corresponding to each performance indicator based on its own performance indicators and the corresponding threshold, and determining the second tolerance parameter corresponding to each network environment information based on the network environment information and the corresponding threshold; and determining the first comprehensive priority based on the first tolerance parameter and the second tolerance parameter.

[0015] The network environment information includes one or more of the following: throughput, number of write requests, and consistency latency.

[0016] In the above scheme, the performance indicators include node resource usage information and load information. The resource usage information includes one or more of the following indicators: central processing unit (CPU) utilization, memory usage, and disk input / output (I / O).

[0017] The tolerance parameter corresponding to the performance index satisfies:

[0018]

[0019] Where L1 represents the tolerance parameter corresponding to the performance index; x1 represents the threshold corresponding to the performance index; and X1 represents the performance index.

[0020] In the above scheme, the tolerance parameters corresponding to the number of write requests and / or the consistency delay satisfy:

[0021]

[0022] Where L2 represents the tolerance parameter corresponding to the number of write requests or consistency latency, x2 represents the threshold corresponding to the number of write requests or consistency latency, and X2 represents the number of write requests or consistency latency;

[0023] The tolerance parameter corresponding to the throughput satisfies:

[0024]

[0025] Where L5 represents the tolerance parameter corresponding to throughput, x5 represents the threshold corresponding to throughput, and X5 represents throughput.

[0026] In the above scheme, the node priority satisfies:

[0027]

[0028] Wherein, NP represents node priority; The sign of the node priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and N is the total number of performance indicators.

[0029] In the above scheme, the first comprehensive priority satisfies:

[0030]

[0031] Wherein, CP1 represents the first synthesis priority. The sign of the first overall priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and M is the total number of network environment information and performance indicators.

[0032] This invention also provides a consensus-reaching method, applied to follower nodes, the method comprising:

[0033] The follower node receives an election request sent by the candidate node, the election request including at least a node priority, the node priority being determined based on the performance metrics of the candidate node;

[0034] Based on the node priority of the candidate node, it is determined whether to vote in favor of the candidate node, and a vote is sent to the candidate node based on the determination result; wherein, the number of votes in favor is used to determine whether the candidate node becomes the leader node;

[0035] Receive a heartbeat message sent by the leader node, the heartbeat message including a first comprehensive priority, the first comprehensive priority being determined based on the leader node's performance indicators and network environment information;

[0036] At least based on the first comprehensive priority, it is determined whether to vote against the leader node, and a heartbeat response is sent to the leader node based on the determination result. In the case that it is determined to vote against the leader node, the heartbeat response includes the voting against the leader node. The number of voting against the leader node is used to determine whether the leader node should be replaced.

[0037] In the above scheme, the election request also includes a term value and a log index; the step of determining whether to vote in favor of the candidate node based on its node priority includes:

[0038] If it is determined that the term value of the candidate node is less than the term value of the follower node itself and / or the log index of the candidate node is less than the log index of the follower node itself, then it is determined to refuse to vote for the candidate node.

[0039] When it is determined that the term value of the candidate node is greater than or equal to the term value of the follower node itself, and the log index of the candidate node is greater than or equal to the log index of the follower node itself, it is determined whether to vote for the candidate node based on the node priority of the candidate node.

[0040] In the above scheme, determining whether to vote in favor of a candidate node based on its node priority includes:

[0041] If the node priority of the candidate node is determined to be negative, it is determined to refuse to vote for the candidate node.

[0042] When the node priority of the candidate node is determined to be positive, the node priority of the candidate node is compared with the node priority of the follower node itself.

[0043] When the node priority of a candidate node is greater than or equal to the node priority of the follower node itself, it is determined that the candidate node is voted in favor.

[0044] If the node priority of a candidate node is lower than the node priority of the follower node itself, it is determined to refuse to vote for the candidate node.

[0045] The node priority of the follower node is determined based on a tolerance parameter determined by the performance index of the follower node.

[0046] In the above scheme, the step of determining whether to vote against the leader node based at least on the first comprehensive priority includes:

[0047] When the first overall priority is determined to be negative, it is determined that the leader node will vote against it;

[0048] When the first comprehensive priority is determined to be positive, the network latency is compared with the corresponding threshold. When the network latency is greater than the corresponding threshold, it is determined that the leader node votes against it.

[0049] When the network latency is less than or equal to the corresponding threshold, a second comprehensive priority is determined based on the first comprehensive priority and the tolerance parameter corresponding to the network latency, and it is determined whether the second comprehensive priority is less than the overall system tolerance; wherein, the tolerance parameter corresponding to the network latency is determined by the follower node based on the network latency obtained by receiving the heartbeat message and the corresponding threshold;

[0050] If the second comprehensive priority is determined to be less than the overall system tolerance, it is determined that the leader node will vote against it.

[0051] If a follower node was previously a leader node, and the second overall priority is less than the lowest second overall priority when the follower node was a leader node, then the leader node is voted against.

[0052] In the above scheme, the second comprehensive priority satisfies:

[0053]

[0054] Wherein, CP2 represents the second synthesis priority, and CP1 represents the first synthesis priority. This represents the tolerance parameter corresponding to network latency. This represents the weight corresponding to network latency.

[0055] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method described in this invention.

[0056] This invention also provides a node, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method described in this invention.

[0057] This invention also provides a computer program product, including computer program instructions that cause a computer to perform the steps of the method described in this invention.

[0058] The consensus-building method, nodes, storage medium, and program products provided in this invention involve: Candidate nodes determining their node priority based on their performance metrics and sending election requests to follower nodes, the election requests including at least the node priority; follower nodes determining whether to vote in favor of the candidate node based on its node priority and sending votes to the candidate node based on the determination result; candidate nodes determining whether to become the leader node based on the number of votes received; if determined to become the leader node, determining a first comprehensive priority based on its performance metrics and network environment information and sending heartbeat messages to follower nodes, the heartbeat messages including the first comprehensive priority; follower nodes determining whether to vote against the leader node based at least on the first comprehensive priority and sending heartbeat responses to the leader node based on the determination result; and the leader node determining whether to change the leader node based on the number of opposing votes in the heartbeat responses. The technical solution adopted in this invention addresses two main issues. First, it utilizes multi-dimensional performance indicators to construct a node priority model and proposes a leader election method based on this model. This ensures that the candidate node with the best performance is elected as the leader node, improving the accuracy of leader node election and providing initial high-performance assurance for subsequent log replication nodes. Second, it comprehensively considers the performance indicators of the leader node and changes in the network environment, proposing a dynamic leader replacement mechanism based on comprehensive priority. In cases where the leader node's performance is poor and / or the network environment is unfavorable, the leader node can be replaced in a timely manner, improving the stability and reliability of the system and effectively optimizing the overall system performance. Attached Figure Description

[0059] Figure 1 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 1 ;

[0060] Figure 2 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 2 ;

[0061] Figure 3 A schematic diagram of the distributed system architecture and process used in the consensus-reaching method of this invention.

[0062] Figure 4 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 3 ;

[0063] Figure 5 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 4 ;

[0064] Figure 6 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 5 ;

[0065] Figure 7 This is a schematic diagram of the composition structure of the consensus-reaching device according to an embodiment of the present invention. Figure 1 ;

[0066] Figure 8 This is a schematic diagram of the composition structure of the consensus-reaching device according to an embodiment of the present invention. Figure 2 ;

[0067] Figure 9 This is a schematic diagram of the hardware structure of a node according to an embodiment of the present invention. Detailed Implementation

[0068] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.

[0069] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.

[0070] The terms “first,” “second,” etc., used in this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0071] Before providing a detailed description of the technical solutions of the embodiments of the present invention, the Raft algorithm will be briefly explained first.

[0072] Node States: In the Raft algorithm, each node is in one of three states: leader, follower, or candidate. During normal operation, there is only one leader, and all other nodes are followers. The leader is responsible for handling all client requests. Followers, as passive entities, do not initiate requests but respond to requests from other nodes. Candidates only come into play during the leader election process, where a new leader is elected.

[0073] Term mechanism: Raft divides time into multiple terms, each identified by an incrementing integer. This term mechanism helps nodes maintain consistency during the election process, ensuring that only one effective leader exists during a term. The initial period of a term is designated for leader election.

[0074] Logs: Logs include indexes, terms, and commands. An index is an incrementing number, a term indicates the term in which the log was recorded, and a command indicates the operation to be performed.

[0075] Leader election: The election of a leader is crucial to ensuring high system availability.

[0076] When the system starts, all nodes are in a follower state, meaning each node is a follower node at startup. A leader is randomly selected through a timeout mechanism. It should be noted that if a node receives valid information from the leader or a candidate, it will remain in the follower state.

[0077] If the leader crashes or, due to its own reasons, a follower does not receive a heartbeat signal from the leader for a certain period, it assumes there is no effective leader and initiates an election. To begin the election, the follower increments its current term and transitions to a candidate state. It then votes for itself and sends vote requests to other nodes in the system in parallel. Upon receiving a vote request, a follower node compares its own term value with the candidate's and the size of its log index to decide whether to vote. Finally, a candidate becomes the new leader only when it receives the support of more than half of the follower nodes.

[0078] Log Replication: Once a leader is successfully elected, it assumes responsibility for handling client requests and replicating the logs. In a Raft cluster, all client requests must go through the leader, which converts these requests into log entries and records them. The leader then replicates these log entries to all follower nodes to ensure data consistency. During log replication, the leader continuously sends heartbeat signals to maintain connections with followers and promptly handle any potential failures. This mechanism not only ensures system consistency and reliability but also provides the foundation for data processing in high-concurrency scenarios.

[0079] In today's era of Artificial Intelligence (AI), the dramatic increase in data volume is closely related to the widespread application of distributed systems. Massive amounts of data not only provide abundant resources for training AI models but also increase the demand for efficient data processing and real-time analysis capabilities. Against this backdrop, distributed systems have become the infrastructure supporting large-scale data processing and AI applications, and are crucial for ensuring high data availability and consistency.

[0080] Raft, a widely used distributed consensus protocol, aims to provide reliability and scalability by simplifying the leader election and log replication process. However, when facing the data processing demands of AI, Raft, which relies on a leader to achieve data consensus and consistent logs across nodes, faces the following significant leader performance bottleneck challenges:

[0081] Current election mechanisms primarily rely on term limits and log data, neglecting other key node performance metrics. However, these overlooked factors significantly impact a node's efficiency and response speed when processing requests.

[0082] For example, a node's workload directly affects its processing power. If a node is under high load during the election process, its ability to process requests may still be limited, even if it has a long tenure. A node's disk input / output (I / O) performance is also crucial, especially when dealing with large amounts of data read and write operations; I / O latency can lead to decreased efficiency in log replication and state updates. Similarly, the performance of the central processing unit (CPU) and memory capacity are key factors affecting a node's processing power, particularly important when performing complex calculations and multitasking.

[0083] Therefore, the current Raft system's leader election mechanism fails to comprehensively assess the overall performance of nodes, which may result in the elected leader being unable to efficiently complete log replication and request processing in practical applications, thereby affecting the performance and reliability of the entire system.

[0084] Based on this, embodiments of the present invention provide a consensus-reaching method. Figure 1 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 1 ;like Figure 1 As shown, the method includes:

[0085] Step 101: The candidate node determines its node priority based on its own performance indicators and sends an election request to the follower node. The election request includes at least the node priority.

[0086] Step 102: Receive votes from one or more follower nodes in response to the election request, and determine whether to become the leader node based on the number of votes received;

[0087] Step 103: If the node is determined to be the leader node, it determines the first comprehensive priority based on its own performance indicators and network environment information, and sends a heartbeat message to the follower nodes, wherein the heartbeat message includes the first comprehensive priority;

[0088] Step 104: Receive heartbeat responses from one or more follower nodes in response to the heartbeat message, and determine whether to change the leader node based on the number of dissenting votes in the heartbeat responses.

[0089] The consensus-reaching method in this embodiment is applied to a distributed system; the distributed system includes a Raft system or Raft cluster consisting of multiple nodes and the multiple clients it serves; for example, a node in the Raft system or Raft cluster can be a server, that is, a node can also be called a server node. In the distributed system, a node is selected as the leader node, responsible for handling read and write requests and log replication, while the remaining nodes act as follower nodes, participating in maintaining data consistency.

[0090] In this embodiment, candidate nodes determine their node priorities based on their own performance metrics, and the leader election process is executed based on these priorities. For example, node priorities can also be denoted as (NP, Node Priority). The process of a node transitioning to a candidate state can be based on the random timeout mechanism of the Raft algorithm. For example, a node sets a random election timeout during initialization. When a node's election timeout expires (i.e., the timeout expires), the node becomes a candidate node, triggering an election process.

[0091] In this embodiment, at the start of the election process, each node calculates its own node priority. That is, candidate nodes calculate their corresponding node priorities; each follower node calculates its corresponding node priority. To better measure node performance, the node priority of each node is determined based on its own performance metrics. Specifically, the node priority of candidate nodes is determined based on their own performance metrics, and the node priority of each follower node is determined based on its own performance metrics.

[0092] In this embodiment, node priority is obtained based on the node's own performance metrics. In some alternative embodiments, the better the performance metrics, the higher the node priority, and the greater the probability that a candidate node will become the leader node.

[0093] In this embodiment, a candidate node sends an election request carrying its priority. Upon receiving the election request, a follower node determines whether to vote for the candidate node based on the priority information. Based on the result, one or more follower nodes send an election response to the candidate node, which may include their votes. The candidate node determines whether to become the leader node based on the number of affirmative votes.

[0094] In various embodiments of the present invention, the election request may also be called a voting request, and correspondingly, the election response may also be called a voting response. These are request messages and response messages in the leader election process. In this embodiment, the names of the messages are not specifically limited.

[0095] In this embodiment, after a candidate node becomes the leader node, during the log replication phase, the leader will periodically send heartbeat messages (or heartbeat signaling) to the followers to maintain its leadership position until the leader node crashes and triggers a new election.

[0096] As a strong leader model, Raft systems can only have one leader node. The Raft algorithm relies on the leader node for log replication, and all client requests must be processed through the leader node. More importantly, in abnormal situations such as leader node crashes or going offline, even if external factors cause performance degradation, Raft will not actively replace the current leader node. For example, in high-concurrency scenarios, the leader node's load may increase rapidly, causing a delay in its response, but Raft will still maintain the current leader node. Therefore, Raft fails to consider the impact of leader node performance changes and network changes on system performance during normal operation. This issue can lead to system instability in practical applications, seriously affecting system reliability and security, thus failing to meet the requirements of real-time data analysis and efficient computing in today's AI era.

[0097] Therefore, to comprehensively consider the performance of the leader node in processing client requests and better cope with changes in network environment and leader node performance, this embodiment of the invention proposes a dynamic leader replacement mechanism based on comprehensive priority. In cases of poor leader node performance and / or poor network environment, a timely replacement of the leader node can be initiated, improving system performance, as well as enhancing system security and reliability. For example, comprehensive priority can also be referred to as (CP, Comprehensive Priority).

[0098] In this embodiment, the leader node can determine a first comprehensive priority based on its own performance indicators and network environment information. The first comprehensive priority can reflect the overall performance of the leader node's performance indicators and the quality of the network environment in which the leader node is located. The first comprehensive priority is carried through a heartbeat message. Follower nodes can determine whether to vote against the leader node based on the first comprehensive priority. The number of votes against the leader node is used to determine whether the leader node should be replaced. The leader node determines whether to replace the leader node based on the number of votes against the leader node it receives, that is, it initiates the replacement operation of the leader node.

[0099] The technical solution of this invention, on the one hand, utilizes multi-dimensional performance indicators to calculate tolerance parameters and constructs a node priority model based on the tolerance parameters, proposing a leader election method based on the node priority model. This ensures that the candidate node with the best performance is elected as the leader node, improving the accuracy of leader node election and providing initial high-performance assurance for subsequent log replication nodes. On the other hand, considering the performance indicators of the leader node and changes in the network environment, a dynamic leader replacement mechanism based on comprehensive priority is proposed. In the event of poor leader node performance and / or a poor network environment, the leader node can be replaced in a timely manner, improving system stability and effectively optimizing the overall system performance.

[0100] In some optional embodiments, the candidate node determines its priority based on its own performance indicators, including: the candidate node determines a tolerance parameter corresponding to each performance indicator based on its own performance indicators and corresponding thresholds, wherein the tolerance parameter represents the performance of the candidate node; and determines the node priority based on the tolerance parameter corresponding to each performance indicator.

[0101] In this embodiment, tolerance parameters are first determined based on the node's performance metrics and corresponding thresholds. Then, node priorities are determined based on the tolerance parameters corresponding to each performance metric. The threshold can also be called a critical threshold. If a performance metric exceeds this threshold, it indicates that the node's resources (such as CPU, memory, disk, etc.) are strained, and it may not be able to support more read / write requests. If a performance metric does not exceed the threshold, it indicates that the node has high availability and can handle more client services. If a node's performance metric does not exceed the corresponding threshold, as the difference between the performance metric and the threshold decreases, the node's performance correspondingly declines. Therefore, the tolerance parameters corresponding to the performance metrics represent the distance between the performance metric and the threshold, thus reflecting the node's performance.

[0102] In some optional embodiments, the performance metrics include node resource usage information and load information, wherein the resource usage information includes one or more of the following metrics: central processing unit (CPU) utilization, memory usage, and disk I / O; wherein:

[0103] CPU utilization (e.g., denoted as U) cpu CPU utilization represents the ratio of CPU usage time to total CPU time, specifically satisfying the following expression: CPU utilization = 1 - CPU idle time / total CPU time;

[0104] Memory usage rate (denoted as C): represents the ratio of system memory used to total system memory;

[0105] Disk I / O (e.g., denoted as R) io ): Indicates disk busy status, defined as the percentage of time the disk's I / O queue is not empty within a period;

[0106] Load information (e.g., denoted as N) load ): It can also be called system average load, which represents the average number of processes in the system that are in a runnable and / or uninterruptible state per unit time.

[0107] In some optional embodiments, the performance metrics include node resource usage information and load information, wherein the resource usage information includes one or more of the following metrics: CPU utilization, memory usage, and disk I / O; the tolerance parameters corresponding to the performance metrics satisfy:

[0108] (1)

[0109] Where L1 represents the tolerance parameter corresponding to the performance index; x1 represents the threshold corresponding to the performance index; and X1 represents the performance index.

[0110] In this embodiment, L represents the tolerance parameter as an example, and L1 represents the tolerance parameter corresponding to the performance index. When the tolerance parameter is positive, it indicates that the corresponding node performance index is good; as the tolerance parameter decreases, the service performance of the node gradually declines; when the tolerance parameter is 0, its corresponding performance index reaches the critical value; if the tolerance parameter is negative, it indicates that the node's resources are strained and its performance is limited.

[0111] For example, performance metrics include: CPU utilization (U cpu ), memory usage (C), disk I / O (R) io ) and load information (N load In the case of ), the tolerance parameter corresponding to the above performance index can be expressed as:

[0112] (2)

[0113] (3)

[0114] (4)

[0115] (5)

[0116] in, This parameter represents the tolerance level corresponding to CPU utilization. Indicates CPU utilization. This represents the threshold corresponding to CPU utilization. This parameter represents the tolerance level for memory usage, where C represents memory usage. This represents the threshold corresponding to memory usage. This represents the tolerance parameter for disk I / O. Indicates disk I / O, This represents the threshold corresponding to disk I / O; This indicates the tolerance parameter corresponding to the load information. Indicates load information, This indicates the threshold corresponding to the load information.

[0117] In this embodiment, to comprehensively consider node performance, the node priority can be obtained by weighted summation of tolerance parameters corresponding to each performance indicator. The sign of the node priority is determined by the sign of the tolerance parameters corresponding to each performance indicator and load information. If the sign of the tolerance parameter for any performance indicator is negative, it indicates that the node is severely limited in that performance aspect and may be unable to fulfill its leadership responsibilities. Therefore, if the tolerance parameter for any performance indicator is negative, the sign of the node priority will be negative.

[0118] In some alternative embodiments, the node priority satisfies:

[0119] (6)

[0120] Wherein, NP represents node priority; The sign of the node priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and N is the total number of performance indicators.

[0121] In expression (6), The weights represent the values ​​corresponding to the i-th tolerance parameter. All of them are positive numbers, and the larger the weight value, the greater the impact of the corresponding performance index.

[0122] In expression (6), satisfy:

[0123] (7)

[0124] It should be noted that in expression (7), the performance indicators include four types: CPU utilization, memory usage, disk I / O, and load information. That is, the maximum value of i is 4. In other optional embodiments, the performance indicators may include, but are not limited to, the above four performance indicators. Therefore, when the performance indicators are not limited to the above four performance indicators, the maximum value of i can be any integer greater than 4, specifically, the number of types of performance indicators.

[0125] In this embodiment, when the node priority (i.e., NP) is positive, the larger the node priority (i.e., NP), the better the node's performance, and the more likely the candidate node is to become the leader node during the election phase.

[0126] In some optional embodiments, determining whether to become a leader node based on the number of affirmative votes obtained includes: determining whether a node becomes a leader node when the ratio of the number of affirmative votes to the total number of nodes is greater than or equal to a preset threshold. For example, the preset threshold can be 50%, or other preset thresholds. It is understood that if a candidate node obtains a majority of affirmative votes (or votes), it can successfully become the current leader node.

[0127] In this embodiment, the performance metric used to determine the first overall priority may be the same as or partially the same as the aforementioned performance metric used to determine the node priority. For example, the performance metric may include one or more of the following: CPU utilization (U... cpu ), memory usage (C), disk I / O (R) io ), load information (N load ).

[0128] In some optional embodiments, the network environment information of the embodiments of the present invention includes one or more of the following: throughput, number of write requests, consistency latency, and network latency; wherein:

[0129] Throughput (e.g., denoted as T) ps ), is an important metric for system performance, defined as the number of write requests that a cluster can process per second;

[0130] Number of write requests (e.g., denoted as N) write ): Indicates the number of write requests received simultaneously by the leader node;

[0131] Consistent delay (e.g., denoted as T) consensus This represents the time elapsed between the client sending a request to the leader node and receiving a response.

[0132] Network latency (e.g., denoted as T) net ): This represents the time taken for the leader node to send a heartbeat to the follower node.

[0133] In the aforementioned network environment information, network latency needs to be determined by the tracker nodes based on the received heartbeat messages. Therefore, the leader node uses one or more of the following as network environment information: throughput, write request count, and consistency latency, and combines this with the leader node's own performance metrics to determine the first overall priority; network latency (such as T...) net The tolerance parameter corresponding to the following node is calculated by the follower node, so the overall priority determined by the follower node is denoted as the second overall priority.

[0134] In some optional embodiments, the leader node determines a first comprehensive priority based on its own performance metrics and network environment information, including: the leader node determines a first tolerance parameter corresponding to each performance metric based on its own performance metrics and corresponding thresholds, and determines a first tolerance parameter corresponding to each network environment information based on network environment information and corresponding thresholds; and determines the first comprehensive priority based on the first tolerance parameter and the first tolerance parameter; wherein the network environment information includes one or more of the following: throughput, number of write requests, and consistency latency.

[0135] In this embodiment, the leader node determines the tolerance parameters corresponding to each performance indicator based on its own performance metrics and corresponding thresholds, and determines the tolerance parameters corresponding to each network environment information based on network environment information and corresponding thresholds. For distinction, the tolerance parameters corresponding to performance indicators are designated as the first tolerance parameter, and the tolerance parameters corresponding to network environment information are designated as the second tolerance parameter. The first comprehensive priority is then determined based on the first and second tolerance parameters. The threshold can also be called the critical threshold. If a performance indicator exceeds this threshold, it indicates that the node's resources (such as CPU, memory, disk, etc.) are strained, and it may not be able to support more read / write requests. If a performance indicator does not exceed this threshold, it indicates that the node has high availability and can handle more client services. Regarding network environment information, a higher value for certain network environment information (such as throughput) indicates a better network environment. For such network environment information, if the network environment information exceeds the corresponding threshold, it indicates a good network environment; conversely, if the network information does not exceed the corresponding threshold, it indicates a poor network environment. The lower the values ​​of certain network environment parameters (such as write request count and consistency latency), the better the network environment. If these parameters exceed a certain threshold, the network environment is considered poor; conversely, if they do not exceed the threshold, the network environment is considered good. Therefore, the first tolerance parameter represents the distance between the performance indicator and the threshold, thus reflecting the node's performance; the second tolerance parameter represents the quality of the network environment.

[0136] In this embodiment, the process of determining the tolerance parameter (i.e. the first tolerance parameter) corresponding to each performance index during the process of determining the first comprehensive priority can be referred to the above expressions (1) to (5), and will not be repeated here.

[0137] In some alternative embodiments, the tolerance parameters corresponding to the number of write requests and / or the consistency latency satisfy:

[0138] (8)

[0139] Where L2 represents the tolerance parameter corresponding to the number of write requests or consistency latency, x2 represents the threshold corresponding to the number of write requests or consistency latency, and X2 represents the number of write requests or consistency latency;

[0140] The tolerance parameter corresponding to the throughput satisfies:

[0141] (9)

[0142] Where L5 represents the tolerance parameter corresponding to throughput, x5 represents the threshold corresponding to throughput, and X5 represents throughput.

[0143] In this embodiment, the throughput (T) of the leader node ps Let the threshold corresponding to T be denoted as x5. ps When x < 5, it indicates that the throughput of the leader node is too low, which may lead to a decrease in system performance; conversely, the leader node can support tasks with higher throughput requirements. Based on this, the tolerance parameter corresponding to the throughput is set as shown in expression (9).

[0144] In this embodiment, the number of write requests (N) of the leader node write Consistent delay (T) consensus ) and network latency (T net The corresponding thresholds can be x6, x7, and x8 respectively; then when N write When T > x6, it indicates that the leader node is receiving too many write requests simultaneously; when T consensus When T > x7, it indicates that the consistency latency of the leader node is too high; when T net A value greater than x8 indicates that the leader node's network latency is too high, which may severely impact system performance. If all three performance metrics are below their respective thresholds, the leader node can handle simultaneously received write requests, and the communication network environment with clients and follower nodes is good.

[0145] For example, in determining the first overall priority, the network environment information includes throughput (T) ps ), number of write requests (N) write ) and consistency delay (T)consensus In the case of ), throughput (T) ps The corresponding tolerance parameter can be shown in expression (9), and the number of write requests (N) write ) and consistency delay (T) consensus The corresponding tolerance parameters can be expressed as follows:

[0146] (10)

[0147] (11)

[0148] in, Represents the number of write requests (N) write The corresponding tolerance parameter, Indicates the number of write requests. This represents the threshold corresponding to the number of write requests; Indicates consistent delay (T) consensus The corresponding tolerance parameter, Indicates consistent delay. This represents the threshold corresponding to the consistent delay.

[0149] In this embodiment, as shown in expressions (8) to (11), when the tolerance parameter is positive, it indicates that the current leader node has good performance or a good network environment; as the tolerance parameter decreases, it indicates that the service performance of the leader node gradually decreases; when the tolerance parameter is zero, the performance of the leader node reaches a critical value; when the tolerance parameter is negative, it indicates that the leader node has limited resources and its performance is restricted.

[0150] In this embodiment, to comprehensively consider the leader node's performance metrics and network environment, the first comprehensive priority can be obtained by weighted summation of the first tolerance parameter corresponding to each performance metric and the second tolerance parameter corresponding to network environment information (excluding network latency). The sign of the first comprehensive priority is determined by the positive or negative value of each tolerance parameter. If any tolerance parameter is negative, it indicates that a certain performance aspect of the leader node is severely limited or the network environment parameters are poor, potentially preventing it from fulfilling its leadership responsibilities. Therefore, if any tolerance parameter for a performance metric or network environment information is negative, the sign of the first comprehensive priority is negative.

[0151] In some alternative embodiments, the first synthesis priority satisfies:

[0152] (12)

[0153] Wherein, CP1 represents the first synthesis priority. The sign of the first overall priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and M is the total number of network environment information and performance indicators.

[0154] In expression (12), The weights corresponding to the i-th tolerance parameter are all positive numbers. The larger the weight value, the greater the impact of the corresponding performance index or network environment parameter on the system.

[0155] In expression (12), satisfy:

[0156] (13)

[0157] It should be noted that in expression (13), the performance indicators include four types of performance indicators: CPU utilization, memory usage, disk I / O, and load information, as well as network environment information including throughput (T). ps ), Number of requests (N) write ) and consistency delay (T) consensus For example, the maximum value of i is 7. In other alternative embodiments, the performance indicators may include, but are not limited to, the above four performance indicators, and the network environment information may include, but is not limited to, the above three. Therefore, when the performance indicators are not limited to the above four and / or the network environment information is not limited to the above three, the maximum value of i can be any integer greater than 7, specifically, it can be the sum of the number of indicator types of the performance indicators and the number of information types contained in the network environment information.

[0158] In this embodiment, when the first comprehensive priority (CP1) is positive, the larger the value, the higher the priority, indicating that the node is more qualified to continue serving as the leader node; when the first comprehensive priority (CP1) is negative, it indicates that the leader node has limited performance indicators or a poor network environment, and may be at risk of crashing.

[0159] In this embodiment, the leader node receives heartbeat responses from one or more follower nodes in response to the heartbeat message, and determines whether to change the leader node based on the number of opposing votes in the heartbeat responses. For example, follower nodes can send a heartbeat response to the leader node after determining whether to vote against or refuse to vote against. As one implementation, if a follower node determines to vote against, the heartbeat response may include the confirmed opposing vote; if a follower node determines to refuse to vote against, the heartbeat response may not include the vote. As another implementation, if a follower node determines to vote against, the heartbeat response may include the confirmed opposing vote; if a follower node determines to refuse to vote against, the heartbeat response may include affirmative votes. The leader node can then determine whether to change the leader node based on the number of opposing votes.

[0160] As one implementation, determining whether to replace the leader node based on the number of opposing votes in the heartbeat response includes: determining whether to replace the leader node when the ratio of the number of opposing votes to the total number of nodes is greater than or equal to a preset threshold. For example, the preset threshold can be 50%, or other preset thresholds. It is understood that if a majority of opposing votes are obtained, it is possible to replace the leader node.

[0161] In some optional embodiments, determining whether to replace the leader node based on the number of opposing votes in the heartbeat response includes: determining to replace the leader node when the ratio of the number of opposing votes to the total number of nodes is greater than or equal to a preset threshold for N consecutive determinations.

[0162] In this embodiment, the value of N can be pre-configured, for example, N=3. The leader node can then send heartbeat messages carrying the first overall priority to follower nodes multiple times, and receive heartbeat responses carrying votes from follower nodes. If the ratio of the number of opposing votes to the total number of nodes is greater than or equal to a preset threshold for three consecutive times, a change of leader node can be determined. This avoids frequent elections due to instantaneous performance fluctuations, thereby improving system stability.

[0163] The technical solution of this invention, after the leader node is elected (i.e., on the log replication node), introduces a dynamic performance monitoring mechanism to evaluate the leader node's performance and network environment in real time. When the leader node's performance deteriorates, a dynamic leader node replacement method based on a comprehensive priority model is proposed, which can quickly trigger a re-election to select a better leader, thereby ensuring the continuous and stable operation of the system. Therefore, the combination of dynamic leader replacement and performance monitoring in this invention can adapt to constantly changing workloads and network environments, effectively improving the overall performance and responsiveness of the distributed system.

[0164] Based on the above embodiments, this invention provides a consensus-reaching method, which is applied to follower nodes. Figure 2 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 2 ;like Figure 2 As shown, the method includes:

[0165] Step 201: The follower node receives an election request sent by the candidate node, the election request including at least the node priority, the node priority being determined based on the performance metrics of the candidate node;

[0166] Step 202: Determine whether to vote in favor of the candidate node based on its node priority, and send a vote to the candidate node based on the determination result; wherein, the number of votes in favor is used to determine whether the candidate node becomes the leader node;

[0167] Step 203: Receive a heartbeat message sent by the leader node, wherein the heartbeat message includes a first comprehensive priority, which is determined based on the leader node's performance indicators and network environment information;

[0168] Step 204: Determine whether to vote against the leader node based at least on the first comprehensive priority, and send a heartbeat response to the leader node based on the determination result. In the case that it is determined to vote against the leader node, the heartbeat response includes the voting against the leader node. The number of voting against the leader node is used to determine whether the leader node should be replaced.

[0169] In this embodiment, when a candidate node triggers the start of the election process, each node calculates its own node priority. That is, candidate nodes calculate their corresponding node priorities; each follower node calculates its corresponding node priority. To better measure node performance, the node priority of each node is determined based on its own performance metrics. Specifically, the node priority of a candidate node is determined based on its own performance metrics, and the node priority of each follower node is determined based on its own performance metrics.

[0170] In some optional embodiments, the performance metrics include node resource usage information and load information. The resource usage information includes one or more of the following metrics: central processing unit (CPU) utilization, memory usage, and disk I / O. The specific meaning of each performance metric can be found in the descriptions in the above embodiments, and will not be repeated here.

[0171] In this embodiment, follower nodes can first determine tolerance parameters based on the node's performance indicators and corresponding thresholds, and then determine node priorities based on the tolerance parameters corresponding to each performance indicator. The specific method for follower nodes to determine tolerance parameters can be referred to expressions (1) to (5) in the above embodiments, and the specific method for determining node priorities based on tolerance parameters can be referred to expressions (6) and (7) in the above embodiments, which will not be repeated here.

[0172] In this embodiment, the follower node receives an election request sent by the candidate node, the election request including at least the candidate node's node priority; and determines whether to vote for the candidate node based on the node priority information.

[0173] In some optional embodiments of the present invention, the election request further includes a term value and a log index; the step of determining whether to vote in favor of the candidate node based on the node priority of the candidate node includes: determining to refuse to vote in favor of the candidate node when the term value of the candidate node is less than the term value of the follower node itself and / or the log index of the candidate node is less than the log index of the follower node itself; determining whether to vote in favor of the candidate node based on the node priority when the term value of the candidate node is greater than or equal to the term value of the follower node itself and the log index of the candidate node is greater than or equal to the log index of the follower node itself.

[0174] In this embodiment, when the system starts, the term value of each node is zero, and each node has not started processing client requests, nor does any node have logs. Therefore, in one implementation, when the system starts, the election request includes the node priority of the candidate nodes, but does not include the term value and log index.

[0175] After the system starts up and runs normally, the term value gradually accumulates from zero. The elected leader node begins to process client requests and replicate logs, and logs begin to exist in the node. Therefore, in another implementation, that is, during system operation, the election request includes not only the node priority of the candidate node, but also the term value and log index.

[0176] In the first implementation described above, since the election request does not include term values ​​and log indexes, follower nodes directly determine whether to vote in favor of the candidate node based on the candidate node's node priority. In the second implementation described above, the election request also includes term values ​​and log indexes. Follower nodes then determine whether to refuse to vote in favor of the candidate node according to the Raft algorithm. Specifically, follower nodes compare the term values ​​of the candidate node and follower nodes, and compare the log indexes of the candidate node and follower nodes. If the term value of the candidate node is less than the follower node's own term value, and / or the log index of the candidate node is less than the follower node's log index, then the follower node determines to refuse to vote in favor of the candidate node, or this can also be called refusing to vote. If the term value of the candidate node is greater than or equal to the follower node's own term value, and the log index of the candidate node is greater than or equal to the follower node's own log index, then the follower node determines whether to vote in favor of the candidate node based on the candidate node's node priority.

[0177] In various embodiments of the present invention, during the election phase, follower nodes vote in favor of candidate nodes, which can also be referred to as follower nodes voting for candidate nodes.

[0178] In some optional embodiments, determining whether to vote in favor of a candidate node based on its node priority includes: when the node priority of the candidate node is negative, rejecting the vote for the candidate node; when the node priority of the candidate node is positive, comparing the node priority of the candidate node with the node priority of the follower node itself; when the node priority of the candidate node is greater than or equal to the node priority of the follower node itself, voting in favor of the candidate node; when the node priority of the candidate node is less than the node priority of the follower node itself, rejecting the vote for the candidate node; wherein the node priority of the follower node is determined based on a tolerance parameter determined by the performance index of the follower node.

[0179] In this embodiment, follower nodes determine whether to vote in favor of a candidate node based on node priority. First, the sign of the candidate node's node priority is determined. If the sign of the candidate node's node priority It is a negative value, that is, in expression (7) A value of -1 indicates that one or more performance metrics of the candidate node are poor, and the candidate node is rejected from voting in favor. If the candidate node's node priority sign... It is a positive value, that is, in expression (7) If the value is 1, the follower node compares the node priority of the candidate node with its own node priority. If the node priority of the candidate node is greater than or equal to the node priority of the follower node, it indicates that the overall performance of the candidate node is better than that of the follower node, and the follower node is voted in favor of the candidate node. If the node priority of the candidate node is less than the node priority of the follower node, it indicates that the overall performance of the follower node is better than that of the candidate node, and the follower node is rejected from voting in favor of the candidate node.

[0180] In this embodiment, if a follower node is determined to vote in favor of the candidate node, an election response corresponding to the election request can be sent to the candidate node to send the vote.

[0181] In this embodiment, the follower node receives a heartbeat message sent by the leader node and determines whether to vote against the leader node based on the first comprehensive priority information carried in the heartbeat message; wherein, the vote against the leader node indicates opposition to the leader node continuing to be the leader node.

[0182] In some optional embodiments, the step of determining whether to vote against the leader node based at least on the first comprehensive priority includes: determining to vote against the leader node when the first comprehensive priority is negative; comparing network latency with a corresponding threshold when the first comprehensive priority is positive, and determining to vote against the leader node when the network latency is greater than the corresponding threshold; determining a second comprehensive priority based on the first comprehensive priority and a tolerance parameter corresponding to the network latency when the network latency is less than or equal to the corresponding threshold, and determining whether the second comprehensive priority is less than the overall system tolerance; wherein the tolerance parameter corresponding to the network latency is determined by the follower node based on the network latency obtained by receiving the heartbeat message and the corresponding threshold; determining to vote against the leader node when the second comprehensive priority is less than the overall system tolerance; and determining to vote against the leader node when the second comprehensive priority is less than the minimum second comprehensive priority when the follower node was the leader node, in cases where the follower node was previously the leader node.

[0183] In this embodiment, the follower node first determines when the first comprehensive priority is negative, i.e., in expression (13) If the value is -1, it indicates that the overall performance of the leader node is limited and / or the network environment is poor, and it is determined that the leader node should be voted against; when the first overall priority is determined to be positive, that is, in expression (13) If the value is 1, the follower node calculates the network latency by calculating the time when the heartbeat message is received and the time when the heartbeat message is sent, and compares the network latency with the corresponding threshold. If the network latency is greater than the corresponding threshold, it indicates that the network latency is large, and the follower node determines whether to vote against the leader node. If the network latency is less than or equal to the corresponding threshold, it indicates that the network latency is small, and the follower node further calculates a second comprehensive priority based on the first comprehensive priority combined with the tolerance parameter corresponding to the network latency, and determines whether to vote against the leader node based on the second comprehensive priority. Specifically, the follower node can pre-set the overall system tolerance F according to performance requirements; if the second comprehensive priority is less than the overall system tolerance F, it determines whether to vote against the leader node; if the second comprehensive priority is greater than or equal to the overall system tolerance F, it determines whether to vote against the leader node. Furthermore, if a follower node was previously a leader node, then the follower node stores the second comprehensive priority when it was a leader node. When the second comprehensive priority corresponding to the leader node is less than the smallest second comprehensive priority among the second comprehensive priorities of the follower node when it was a leader node, that is, when expression (14) is satisfied, it can be determined that the leader node votes against it.

[0184] (14)

[0185] in, This indicates the second overall priority of the leader node; This indicates the second overall priority of each follower node when it acts as a leader node. This represents the minimum value among the second overall priorities when a follower node acts as the leader node.

[0186] In some alternative embodiments, the second comprehensive priority satisfies:

[0187] (15)

[0188] Wherein, CP2 represents the second synthesis priority, and CP1 represents the first synthesis priority. This represents the tolerance parameter corresponding to network latency. Indicates network latency (e.g., T) net The corresponding weight.

[0189] Among them, the network latency (e.g., T) net The corresponding tolerance parameter satisfies

[0190] (16)

[0191] in, Indicates network latency. This represents the threshold corresponding to network latency. This represents the tolerance parameter for network latency.

[0192] In this embodiment, the heartbeat message sent by the leader node carries a timestamp, which indicates the time the heartbeat message was sent. Follower nodes determine the network latency (e.g., T) based on the heartbeat message reception time and the timestamp. net ), and then based on network latency (such as T) net The tolerance parameters for network latency are determined by the corresponding threshold.

[0193] Figure 3 This is a schematic diagram of the distributed system architecture and process used in the consensus-reaching method of this invention; such as... Figure 3 As shown, the consensus-reaching method of this invention may include a leader election phase and a log replication phase; wherein:

[0194] During the leader election phase: Each node can calculate its corresponding node priority based on performance metrics. Given that performance metrics include CPU utilization, memory, disk I / O, and average load, each node can determine the tolerance parameter corresponding to each performance metric based on the respective performance metric and its corresponding threshold, and then determine its node priority based on the tolerance parameter. The tolerance parameter can be determined based on expressions (1) to (5), and the node priority can be determined based on expression (6). Candidate nodes send voting requests (or election requests) to each follower node. The voting request (or election request) includes the candidate node's node priority. Each follower node can decide whether to vote or not based on its node priority, and the voting result is carried through the voting response (or election response). A candidate can determine whether to become the leader node based on the number of votes received (the number of affirmative votes).

[0195] After the leader election is completed, the log replication phase begins. During the log replication phase: the leader node sends a heartbeat message to each follower node, which carries the first comprehensive priority calculated by the leader node; wherein, the first comprehensive priority is calculated based on the leader node's performance indicators and network environment information; wherein, the first comprehensive priority can be determined based on expression (12). Specifically, the leader node determines the corresponding tolerance parameters based on each performance indicator and network environment information, and the tolerance parameters corresponding to the performance indicators and network environment information can be determined based on expressions (1) to (5) and expressions (8) to (11), respectively; and then determines the first comprehensive priority based on the corresponding tolerance parameters determined by each performance indicator and network environment information. After receiving the heartbeat message, the follower node can determine whether to vote against it based on the first comprehensive priority, and carry the voting result through the heartbeat response. The leader node can determine whether to change the leader node based on the number of votes obtained (number of votes against).

[0196] The consensus-reaching method of the present invention will be described below with reference to specific embodiments.

[0197] Figure 4 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 3 ;like Figure 4 As shown, the method includes:

[0198] Step 400: The distributed system starts up, and each server node is in a follower state.

[0199] Step 401: The election process begins.

[0200] Step 402: When a follower node's timeout period ends, it becomes a candidate node and its term is incremented by one.

[0201] Here, nodes are initialized with a random election timeout. When a node's election timeout expires, the node becomes a candidate node, triggering an election process.

[0202] Step 403: Calculate the node priority of the candidate nodes.

[0203] The method for calculating node priority can be found in the detailed description of the above embodiments, and will not be repeated here.

[0204] Here, while the candidate nodes calculate their node priorities, each follower node also calculates its corresponding node priority.

[0205] Step 404: The candidate node sends a voting request to the follower node, the voting request including the node priority.

[0206] This example applies when the system has just started up, all nodes have a term value of zero, and none of the nodes have started processing client requests or have logs. Therefore, in this example, the voting request (or election request) includes the node priority of the candidate node, but not the term value or log index.

[0207] Step 405: The follower node checks whether the node priority is a positive number (or whether the sign is 1). If the result is yes, proceed to step 406; if the result is no, proceed to step 408.

[0208] Step 406: The follower node determines whether the node priority of the candidate node is greater than its own node priority. If the result is yes, proceed to step 407; if the result is no, proceed to step 408.

[0209] Here, follower nodes determine whether to vote in favor of a candidate node based on its node priority. First, they determine the sign of the candidate node's node priority. If the sign of the candidate node's node priority Negative value (or sign) If the value is -1, it indicates that one or more performance metrics of the candidate node are poor, and the candidate node will be rejected. Positive value (or sign) If the priority is 1), the follower node compares the node priority of the candidate node with its own node priority. If the node priority of the candidate node is greater than or equal to the node priority of the follower node, it indicates that the overall performance of the candidate node is better than that of the follower node, and the follower node is voted in favor of the candidate node. If the node priority of the candidate node is less than the node priority of the follower node, it indicates that the overall performance of the follower node is better than that of the candidate node, and the follower node is rejected from voting in favor of the candidate node.

[0210] Step 407: Follower nodes vote for candidate nodes.

[0211] Step 408: Follower nodes do not vote.

[0212] Step 409: The candidate node determines whether it has obtained the votes of a majority of the tracker nodes. If the result is yes, proceed to step 410: the candidate node is elected as the leader node, and the election ends; if the result is no, repeat step 401.

[0213] Here, a candidate node can determine if the ratio of the number of votes it receives to the total number of nodes is greater than or equal to a preset threshold. For example, if the preset threshold is 50%, that is, if a candidate node receives a majority of votes (or votes), then the candidate node can successfully become the current leader node.

[0214] Figure 5 This is a flowchart illustrating the consensus-reaching method according to an embodiment of the present invention. Figure 4 ;like Figure 5 As shown, the method includes:

[0215] Step 501: The election process begins.

[0216] Step 502: When the follower node's timeout period ends, it becomes a candidate node and its term is incremented by one.

[0217] Here, nodes are initialized with a random election timeout. When a node's election timeout expires, the node becomes a candidate node, triggering an election process.

[0218] Step 503: Calculate the node priority of the candidate nodes.

[0219] The method for calculating node priority can be found in the detailed description of the above embodiments, and will not be repeated here.

[0220] Here, while the candidate nodes calculate their node priorities, each follower node also calculates its corresponding node priority.

[0221] Step 504: The candidate node sends a voting request to the follower node, the voting request including the node priority, term value and log index.

[0222] This example applies to the log replication phase. During normal system operation, the term value gradually accumulates from zero. The elected leader node begins processing client requests and log replication, and logs begin to exist within the node. Therefore, during system operation, the election request includes not only the node priority of the candidate node but also the term value and log index.

[0223] Step 505: The follower node determines whether the term value and / or log index of the candidate node is less than its own term value and / or log index. If the result is yes, proceed to step 506; if the result is no, proceed to step 509.

[0224] Step 506: The follower node checks whether the node priority is a positive number (or whether the sign is 1). If the result is yes, proceed to step 507; if the result is no, proceed to step 509.

[0225] Step 507: The follower node determines whether the node priority of the candidate node is greater than its own node priority. If the result is yes, proceed to step 508; if the result is no, proceed to step 509.

[0226] Here, follower nodes are restricted to using the Raft algorithm to determine whether to refuse to vote in favor of the candidate node. Specifically, they compare the term values ​​of the candidate node and the follower node, as well as the log indexes of the candidate node and the follower node. If the term value of the candidate node is less than the term value of the follower node itself, and / or the log index of the candidate node is less than the log index of the follower node, then the follower node determines to refuse to vote in favor of the candidate node, or it can also be called refusing to vote. If the term value of the candidate node is greater than or equal to the term value of the follower node itself, and the log index of the candidate node is greater than or equal to the log index of the follower node itself, then a further determination is made based on node priority to determine whether to vote in favor of the candidate.

[0227] Furthermore, follower nodes determine whether to vote in favor of a candidate node based on its node priority, first by checking the sign of the candidate node's node priority. If the sign of the candidate node's node priority Negative value (or sign) If the value is -1, it indicates that one or more performance metrics of the candidate node are poor, and the candidate node will be rejected. Positive value (or sign) If the priority is 1), the follower node compares the node priority of the candidate node with its own node priority. If the node priority of the candidate node is greater than or equal to the node priority of the follower node, it indicates that the overall performance of the candidate node is better than that of the follower node, and the follower node is voted in favor of the candidate node. If the node priority of the candidate node is less than the node priority of the follower node, it indicates that the overall performance of the follower node is better than that of the candidate node, and the follower node is rejected from voting in favor of the candidate node.

[0228] Step 508: Follower nodes vote for candidate nodes.

[0229] Step 509: Follower nodes do not vote.

[0230] Step 510: The candidate node determines whether it has obtained the votes of a majority of the follower nodes. If the result is yes, proceed to step 511: the candidate node is elected as the leader node, and the election ends; if the result is no, repeat step 501.

[0231] Here, a candidate node can determine if the ratio of the number of votes it receives to the total number of nodes is greater than or equal to a preset threshold. For example, if the preset threshold is 50%, that is, if a candidate node receives a majority of votes (or votes), then the candidate node can successfully become the current leader node.

[0232] Figure 6 This is a schematic diagram of the interaction flow of the consensus-reaching method according to an embodiment of the present invention. Figure 5 ;like Figure 6 As shown, the method includes:

[0233] Step 601: During the log replication phase, the leader node calculates the first overall priority.

[0234] Here, the method for determining the first comprehensive priority can be referred to the detailed description in the foregoing embodiments, and will not be repeated here.

[0235] Step 602: The leader node sends a heartbeat message to the follower nodes. The heartbeat message includes the first overall priority and a timestamp.

[0236] Here, after a candidate node becomes the leader node, during the log replication phase, the leader periodically sends heartbeat messages to its followers to maintain its leadership position. At least some of these heartbeat messages may include a first overall priority and a timestamp.

[0237] Step 603: The follower node determines whether the first comprehensive priority is positive (or whether the sign is 1). If the result is yes, proceed to step 604; if the result is no, proceed to step 608.

[0238] Step 604: The follower node determines whether the network latency is less than or equal to the corresponding threshold. If the result is yes, proceed to step 605; if the result is no, proceed to step 608.

[0239] Here, follower nodes can calculate network latency based on the timestamp carried in the heartbeat message and the time the heartbeat message was received.

[0240] Step 605: The follower node calculates the second comprehensive priority based on the tolerance parameter corresponding to the first comprehensive priority and network latency, and determines whether the second comprehensive priority is less than the overall system tolerance; if the result is yes, then proceed to step 606; if the result is no, then proceed to step 608.

[0241] Step 606: The follower node determines whether its second overall priority is greater than or equal to the lowest second overall priority when the follower node was once the leader node; if the result is yes, proceed to step 607; if the result is no, proceed to step 608.

[0242] Here, the follower node first determines the sign of the first overall priority when it is negative. A value of -1 indicates that the overall performance of the leader node is limited and / or the network environment is poor, thus determining that a dissenting vote will be cast for the leader node; when the first overall priority is positive, i.e., the sign of the first overall priority is... If the value is 1, the follower node calculates the network latency by calculating the time when the heartbeat message is received and the time when the heartbeat message is sent, and compares the network latency with the corresponding threshold. If the network latency is greater than the corresponding threshold, it indicates that the network latency is large, and the follower node determines whether to vote against the leader node. If the network latency is less than or equal to the corresponding threshold, it indicates that the network latency is small, and the follower node further calculates the second comprehensive priority based on the first comprehensive priority combined with the tolerance parameter corresponding to the network latency, and determines whether to vote against the leader node based on the second comprehensive priority.

[0243] Specifically, follower nodes can pre-set the overall system tolerance F based on performance requirements. If the second comprehensive priority is less than the overall system tolerance F, it is determined to vote against the leader node. If the second comprehensive priority is greater than or equal to the overall system tolerance F, and the follower node previously served as a leader node, then the follower node stores its second comprehensive priority when it was a leader node. If the second comprehensive priority of the leader node is less than the smallest second comprehensive priority among the follower's second comprehensive priorities when it was a leader node, it is determined to vote against the leader node. In other optional embodiments, if a follower node has previously served as a leader node, then if its second comprehensive priority is determined to be greater than or equal to the overall system tolerance F, it can be determined not to vote against the leader node.

[0244] Step 607: Follower nodes do not vote and respond to heartbeat messages.

[0245] Step 608: Follower nodes vote against the action and respond with a heartbeat message.

[0246] Step 609: The leader node determines whether it has obtained three dissenting votes from a majority of the follower nodes; if the result is yes, proceed to step 610; if the result is no, proceed to step 611.

[0247] Here, if the current leader node receives three consecutive dissenting votes from a majority of its followers, it is considered to have severely impacted the overall system performance, and is thus eliminated and replaced, triggering a new election. Otherwise, the leader node will continue to hold its position. Setting three votes as the condition for replacing the current leader is to avoid frequent elections triggered by momentary performance fluctuations, thereby improving system stability.

[0248] Step 610: The leader node triggers an election, initiating an election process based on node priority.

[0249] Step 611: The leader node remains in office, and the system operates normally.

[0250] The technical solution of this invention utilizes multi-dimensional performance indicators to construct node priority and comprehensive priority models, respectively, addressing the two-stage characteristics of leader election and log replication. Simultaneously, it customizes system performance tolerance according to user needs and monitors the real-time status information of the current leader to promptly replace leaders with lower performance. This effectively addresses the impact of time-varying network environments and leader performance degradation on system performance, significantly enhancing the stability and reliability of distributed systems for large-scale AI training.

[0251] Specifically, in the first aspect, this invention, based on the current critical performance of nodes, designs a two-stage dynamic leader election system during leader election and heartbeat sending. This design effectively avoids the shortcomings of the original Raft method in not considering performance-based leader election, while also preventing performance bottlenecks caused by continuously maintaining a poorly performing incumbent leader.

[0252] Secondly, a node priority model is established based on four key performance indicators: node workload, disk I / O, CPU computing power, and memory capacity. This model accurately measures the distance between a node's current performance and a threshold, and uses this distance as an additional criterion for leader election based on the original term and log index size, thus ensuring that the leader with the best current performance is elected. By comprehensively considering the multi-dimensional performance indicators of nodes, the best-performing leader in the current environment can be identified more accurately. This leader election criterion not only improves the fairness of the election but also effectively avoids misjudgments caused by a single performance indicator. Furthermore, real-time evaluation of the distance between node performance and the set threshold can promptly identify potential performance problems, ensuring that the system maintains efficient operation in dynamic environments. Simultaneously, with the introduction of this node priority model, the system can more flexibly respond to different load conditions, optimize resource allocation, and improve overall performance. Therefore, this method will significantly enhance the stability and reliability of the system, providing strong support for the efficient operation of large-scale distributed systems.

[0253] Thirdly, during normal system operation, the heartbeat protocol of the log replication phase is improved by introducing factors such as throughput, write request count, consistency latency, and network latency into the node's own performance metrics. A comprehensive priority model is constructed to fully evaluate the leader's performance under different conditions, ensuring it can efficiently meet system requirements. Based on this comprehensive priority model, a dynamic leader replacement mechanism with a reverse voting strategy is designed. When the current leader's performance fails to meet the standards, the system automatically initiates a reverse voting process, quickly selecting a better-performing node to replace the leader, thereby ensuring the stability and efficiency of log replication.

[0254] Compared to existing methods that blindly maintain the current leader, the advantages of this invention lie in its ability to more effectively cope with various operating environments and improve the leader's performance monitoring and dynamic adjustment capabilities by comprehensively considering multiple performance indicators and combining them with an anti-voting strategy. This design not only enhances the system's reliability under high load and complex network conditions but also significantly reduces system risks that may arise from poor leader performance, ensuring data consistency and efficient log replication. Furthermore, the leader election method based on a comprehensive priority model allows for a more comprehensive comparison of node performance, optimizes resource utilization, and improves overall system efficiency.

[0255] Based on the above embodiments, this invention also provides a consensus-reaching device. Figure 7 This is a schematic diagram of the composition structure of the consensus-reaching device according to an embodiment of the present invention. Figure 1 ;like Figure 7 As shown, the device includes: a first processing unit 11 and a first communication unit 12; wherein,

[0256] The first processing unit 11 is used to determine node priority based on its own performance indicators;

[0257] The first communication unit 12 is configured to send an election request to a follower node, the election request including at least the node priority; and to receive votes from one or more follower nodes in response to the election request.

[0258] The first processing unit 11 is further configured to determine whether to become a leader node based on the number of votes received; and to determine a first comprehensive priority based on its own performance indicators and network environment information if it is determined to become a leader node.

[0259] The first communication unit 12 is further configured to send a heartbeat message to a follower node, the heartbeat message including the first comprehensive priority; and to receive a heartbeat response sent by one or more follower nodes in response to the heartbeat message;

[0260] The first processing unit 11 is further configured to determine whether to replace the leader node based on the number of opposing votes in the heartbeat response.

[0261] In some optional embodiments of the present invention, the first processing unit 11 is configured to determine the tolerance parameter corresponding to each performance indicator based on its own performance indicator and the corresponding threshold, wherein the tolerance parameter represents the performance of the candidate node; and determine the node priority based on the tolerance parameter corresponding to each performance indicator.

[0262] In some optional embodiments of the present invention, the first processing unit 11 is configured to determine a first tolerance parameter corresponding to each performance indicator based on its own performance indicators and corresponding thresholds, and to determine a second tolerance parameter corresponding to each network environment information based on network environment information and corresponding thresholds; and to determine the first comprehensive priority based on the first tolerance parameter and the second tolerance parameter; wherein the network environment information includes one or more of the following: throughput, number of write requests, and consistency latency.

[0263] In some optional embodiments of the present invention, the performance indicators include node resource usage information and load information, wherein the resource usage information includes one or more of the following indicators: central processing unit (CPU) utilization, memory occupancy, and disk I / O.

[0264] The tolerance parameter corresponding to the performance index satisfies:

[0265]

[0266] Where L1 represents the tolerance parameter corresponding to the performance index; x1 represents the threshold corresponding to the performance index; and X1 represents the performance index.

[0267] In some optional embodiments of the present invention, the tolerance parameters corresponding to the number of write requests and / or the consistency delay satisfy:

[0268]

[0269] Where L2 represents the tolerance parameter corresponding to the number of write requests or consistency latency, x2 represents the threshold corresponding to the number of write requests or consistency latency, and X2 represents the number of write requests or consistency latency;

[0270] The tolerance parameter corresponding to the throughput satisfies:

[0271]

[0272] Where L5 represents the tolerance parameter corresponding to throughput, x5 represents the threshold corresponding to throughput, and X5 represents throughput.

[0273] In some optional embodiments of the present invention, the node priority satisfies:

[0274]

[0275] Wherein, NP represents node priority; The sign of the node priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and N is the total number of performance indicators.

[0276] In some optional embodiments of the present invention, the first comprehensive priority satisfies:

[0277]

[0278] Wherein, CP1 represents the first synthesis priority. The sign of the first overall priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and M is the total number of network environment information and performance indicators.

[0279] In this embodiment of the invention, the device is applied to a node, which is a candidate node or a leader node. The first processing unit 11 in the device can be implemented in practical applications by a central processing unit (CPU), a digital signal processor (DSP), a microcontroller unit (MCU), or a field-programmable gate array (FPGA); the first communication unit 12 in the device can be implemented in practical applications by a communication module (including: basic communication kit, operating system, communication module, standardized interface, and protocol, etc.).

[0280] This invention also provides a consensus-reaching device, which is applied to follower nodes. Figure 8 This is a schematic diagram of the composition structure of the consensus-reaching device according to an embodiment of the present invention. Figure 2 ;like Figure 8 As shown, the device includes: a second communication unit 21 and a second processing unit 22; wherein,

[0281] The second communication unit 21 is used to receive an election request sent by a candidate node, the election request including at least a node priority, the node priority being determined based on a tolerance parameter determined by the performance index of the candidate node;

[0282] The second processing unit 22 is used to determine whether to vote in favor of the candidate node based on the node priority of the candidate node;

[0283] The second communication unit 21 is further configured to send a vote to the candidate node based on the judgment result obtained by the second processing unit 22; wherein the number of votes in favor is used to determine whether the candidate node becomes the leader node; and is further configured to receive a heartbeat message sent by the leader node, wherein the heartbeat message includes a first comprehensive priority, the first comprehensive priority being determined based on the performance indicators and network environment information of the leader node;

[0284] The second processing unit 22 is further configured to determine, at least based on the first comprehensive priority, whether to vote against the leader node;

[0285] The second communication unit 21 is further configured to send a heartbeat response to the leader node based on the judgment result obtained by the second processing unit 22, wherein, in the case of determining that a vote against the leader node is cast, the heartbeat response includes a vote against the leader node; the number of votes against the leader node is used to determine whether the leader node should be replaced.

[0286] In some optional embodiments of the present invention, the election request further includes a term value and a log index; the second processing unit 22 is configured to determine whether to refuse to vote for the candidate node when it is determined that the term value of the candidate node is less than the term value of the follower node itself and / or the log index of the candidate node is less than the log index of the follower node itself; and to determine whether to vote for the candidate node based on the node priority of the candidate node when it is determined that the term value of the candidate node is greater than or equal to the term value of the follower node itself and the log index of the candidate node is greater than or equal to the log index of the follower node itself.

[0287] In some optional embodiments of the present invention, the second processing unit 22 is configured to: determine if the node priority of the candidate node is negative, refuse to vote for the candidate node; determine if the node priority of the candidate node is positive, compare the node priority of the candidate node with the priority information of the follower node itself; determine if the node priority of the candidate node is greater than or equal to the priority information of the follower node itself, vote for the candidate node; and determine if the node priority of the candidate node is less than the priority information of the follower node itself, refuse to vote for the candidate node; wherein the priority information of the follower node is determined based on a tolerance parameter determined by the performance index of the follower node.

[0288] In some optional embodiments of the present invention, the second processing unit 22 is configured to: determine if the first comprehensive priority is negative, and vote against the leader node; determine if the first comprehensive priority is positive, and compare the network latency with the corresponding threshold, and if the network latency is greater than the corresponding threshold, and vote against the leader node; determine if the network latency is less than or equal to the corresponding threshold, and determine a second comprehensive priority based on the first comprehensive priority and the tolerance parameter corresponding to the network latency, and determine whether the second comprehensive priority is less than the overall system tolerance; wherein, the tolerance parameter corresponding to the network latency is determined by the follower node based on the network latency obtained by receiving the heartbeat message and the corresponding threshold; determine if the second comprehensive priority is less than the overall system tolerance, and if, in the case that the follower node has previously been a leader node, the second comprehensive priority is less than the minimum second comprehensive priority when the follower node was a leader node, and vote against the leader node.

[0289] In some optional embodiments of the present invention, the second comprehensive priority satisfies:

[0290]

[0291] Wherein, CP2 represents the second synthesis priority, and CP1 represents the first synthesis priority. This represents the tolerance parameter corresponding to network latency. This represents the weight corresponding to network latency.

[0292] In this embodiment of the invention, the second processing unit 22 in the device can be implemented by a CPU, DSP, MCU or FPGA in practical applications; the second communication unit 21 in the device can be implemented by a communication module (including: basic communication kit, operating system, communication module, standardized interface and protocol, etc.) in practical applications.

[0293] It should be noted that the consensus-reaching device provided in the above embodiments is only illustrated by the division of the above-described program modules. In practical applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device can be divided into different program modules to complete all or part of the processing described above. In addition, the consensus-reaching device and the consensus-reaching method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0294] This invention also provides a node. Figure 9 This is a schematic diagram of the hardware structure of a node according to an embodiment of the present invention, as shown below. Figure 9 As shown, the node includes a memory 32, a processor 31, and a computer program stored in the memory 32 and executable on the processor 31. When the processor 31 executes the program, it implements the steps of the consensus-reaching method of the present invention.

[0295] Optionally, a node may also include at least one network interface 33. The various components within the node are coupled together via a bus system 34. It is understood that the bus system 34 is used to implement communication between these components. In addition to a data bus, the bus system 34 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 9 The general labeled all buses as Bus System 34.

[0296] It is understood that memory 32 can be volatile memory or non-volatile memory, or both. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disc, or compact disc read-only memory (CD-ROM); magnetic surface memory can be disk storage or magnetic tape storage. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), SyncLink Dynamic Random Access Memory (SLDRAM), and Direct Rambus Random Access Memory (DRRAM).The memory 32 described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memory.

[0297] The methods disclosed in the above embodiments of the present invention can be applied to or implemented by processor 31. Processor 31 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 31 or by instructions in software form. The processor 31 may be a general-purpose processor, DSP, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 31 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of the present invention can be directly manifested as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium, which is located in memory 32. Processor 31 reads the information in memory 32 and completes the steps of the aforementioned method in combination with its hardware.

[0298] In an exemplary embodiment, a node may be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), FPGAs, general-purpose processors, controllers, MCUs, microprocessors, or other electronic components to perform the aforementioned method.

[0299] In an exemplary embodiment, the present invention also provides a computer-readable storage medium, such as a memory 32 including a computer program, which can be executed by a node's processor 31 to perform the steps described in the foregoing method. The computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disc, or CD-ROM; or it may be various devices including one or any combination of the above-mentioned memories.

[0300] The computer-readable storage medium provided in the embodiments of the present invention stores a computer program thereon, which, when executed by a processor, implements the steps of the consensus reaching method of the embodiments of the present invention.

[0301] This application also provides a computer program product, including a computer program that can be executed by a node (such as the node's processor 31) to complete the steps of any of the aforementioned consensus-reaching methods.

[0302] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.

[0303] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0304] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0305] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0306] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

[0307] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

[0308] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.

Claims

1. A consensus-reaching method, characterized in that, The method includes: Candidate nodes determine their node priorities based on their own performance metrics and send election requests to follower nodes, wherein the election requests include at least the node priorities. Receive votes from one or more follower nodes in response to the election request, and determine whether to become the leader node based on the number of affirmative votes received; Once determined to become the leader node, it determines a first comprehensive priority based on its own performance indicators and network environment information, and sends a heartbeat message to the follower nodes, wherein the heartbeat message includes the first comprehensive priority. Receive heartbeat responses from one or more follower nodes in response to the heartbeat message, and determine whether to change the leader node based on the number of dissenting votes in the heartbeat response; The step of determining the first comprehensive priority based on its own performance indicators and network environment information includes: The first tolerance parameter for each performance indicator is determined based on its own performance indicators and corresponding thresholds, and the second tolerance parameter for each network environment information is determined based on network environment information and corresponding thresholds. The first comprehensive priority is determined based on the first tolerance parameter and the second tolerance parameter; the first comprehensive priority is obtained by weighted summation of the first tolerance parameter and the second tolerance parameter, and the sign of the first comprehensive priority is determined by the positive or negative sign of the first tolerance parameter and the second tolerance parameter. The network environment information includes one or more of the following: throughput, number of write requests, and consistency latency.

2. The method according to claim 1, characterized in that, The candidate nodes determine their priority based on their own performance metrics, including: The candidate node determines the tolerance parameter corresponding to each performance indicator based on its own performance indicators and the corresponding threshold. The tolerance parameter represents the performance of the candidate node. Node priorities are determined based on the tolerance parameters corresponding to each performance indicator.

3. The method according to claim 1 or 2, characterized in that, The performance metrics include node resource usage information and load information. The resource usage information includes one or more of the following metrics: central processing unit (CPU) utilization, memory usage, and disk input / output (I / O). The tolerance parameter corresponding to the performance index satisfies: Where L1 represents the tolerance parameter corresponding to the performance index; x1 represents the threshold corresponding to the performance index; and X1 represents the performance index.

4. The method according to claim 1, characterized in that, The tolerance parameter corresponding to the number of write requests and / or the consistency delay satisfies: Where L2 represents the tolerance parameter corresponding to the number of write requests or consistency latency, x2 represents the threshold corresponding to the number of write requests or consistency latency, and X2 represents the number of write requests or consistency latency; The tolerance parameter corresponding to the throughput satisfies: Where L5 represents the tolerance parameter corresponding to throughput, x5 represents the threshold corresponding to throughput, and X5 represents throughput.

5. The method according to claim 2, characterized in that, The node priority satisfies: Wherein, NP represents node priority; The sign of the node priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and N is the total number of performance indicators.

6. The method according to claim 1, characterized in that, The first overall priority satisfies: Wherein, CP1 represents the first synthesis priority. The sign of the first overall priority is negative when any tolerance parameter is negative. This represents the i-th tolerance parameter. This represents the weight corresponding to the i-th tolerance parameter, and M is the total number of network environment information and performance indicators.

7. A consensus-reaching method, characterized in that, The method is applied to follower nodes, and the method includes: The follower node receives an election request sent by the candidate node, the election request including at least a node priority, the node priority being determined based on the performance metrics of the candidate node; Based on the node priority of the candidate node, it is determined whether to vote in favor of the candidate node, and a vote is sent to the candidate node based on the determination result; wherein, the number of votes in favor is used to determine whether the candidate node becomes the leader node; The system receives a heartbeat message from the leader node. The heartbeat message includes a first overall priority, which is obtained by a weighted sum of a first tolerance parameter and a second tolerance parameter. The sign of the first overall priority is determined by the positive or negative sign of the first tolerance parameter and the second tolerance parameter. The first tolerance parameter is determined based on the leader node's performance metrics and corresponding thresholds, and the second tolerance parameter is determined based on the leader node's network environment information and corresponding thresholds. The network environment information includes one or more of the following: throughput, number of write requests, and consistency latency. At least based on the first comprehensive priority, it is determined whether to vote against the leader node, and a heartbeat response is sent to the leader node based on the determination result. In the case that it is determined to vote against the leader node, the heartbeat response includes the voting against the leader node. The number of voting against the leader node is used to determine whether the leader node should be replaced.

8. The method according to claim 7, characterized in that, The election request also includes a term value and a log index; the determination of whether to vote in favor of the candidate node based on its node priority includes: If it is determined that the term value of the candidate node is less than the term value of the follower node itself and / or the log index of the candidate node is less than the log index of the follower node itself, then it is determined to refuse to vote for the candidate node. When it is determined that the term value of the candidate node is greater than or equal to the term value of the follower node itself, and the log index of the candidate node is greater than or equal to the log index of the follower node itself, it is determined whether to vote for the candidate node based on the node priority of the candidate node.

9. The method according to claim 7 or 8, characterized in that, The step of determining whether to vote in favor of a candidate node based on its node priority includes: If the node priority of the candidate node is determined to be negative, it is determined to refuse to vote for the candidate node. When the node priority of the candidate node is determined to be positive, the node priority of the candidate node is compared with the node priority of the follower node itself. When the node priority of a candidate node is greater than or equal to the node priority of the follower node itself, it is determined that the candidate node is voted in favor. If the node priority of a candidate node is lower than the node priority of the follower node itself, it is determined to refuse to vote for the candidate node. The node priority of the follower node is determined based on a tolerance parameter determined by the performance index of the follower node.

10. The method according to claim 7, characterized in that, The determination of whether to vote against the leader node based at least on the first comprehensive priority includes: When the first overall priority is determined to be negative, it is determined that the leader node will vote against it; When the first comprehensive priority is determined to be positive, the network latency is compared with the corresponding threshold. When the network latency is greater than the corresponding threshold, it is determined that the leader node votes against it. When the network latency is less than or equal to the corresponding threshold, a second comprehensive priority is determined based on the first comprehensive priority and the tolerance parameter corresponding to the network latency, and it is determined whether the second comprehensive priority is less than the overall system tolerance; wherein, the tolerance parameter corresponding to the network latency is determined by the follower node based on the network latency obtained by receiving the heartbeat message and the corresponding threshold; If the second comprehensive priority is determined to be less than the overall system tolerance, it is determined that the leader node will vote against it. If a follower node was previously a leader node, and the second overall priority is less than the lowest second overall priority when the follower node was a leader node, then the leader node is voted against.

11. The method according to claim 10, characterized in that, The second overall priority satisfies: Wherein, CP2 represents the second synthesis priority, and CP1 represents the first synthesis priority. This represents the tolerance parameter corresponding to network latency. This represents the weight corresponding to network latency.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method according to any one of claims 1 to 11.

13. A node comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 11.

14. A computer program product, characterized in that, It includes computer program instructions that cause a computer to perform the steps of the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Consensus method based on node state information and distributed system

    CN115277718A

  • Improved Raft-based centerless distributed convergence network node migration consistency method

    CN119743488A