Design method and system of logical clock synchronization algorithm for distributed system
By using a logical clock synchronization algorithm, the problems of clock asynchrony and global event ordering in distributed systems are solved, achieving efficient logical clock synchronization and global clock synchronization, reducing the synchronization burden and improving system performance.
Patent Information
- Application Number
- CN202211012163.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-23
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2042-08-23
AI Technical Summary
In distributed systems, clock asynchrony and global event ordering problems are difficult to solve effectively, and existing algorithms suffer from clock skew and inaccurate synchronization.
The algorithm employs a logical clock synchronization mechanism. By initializing the local logical clock service, starting the timing daemon thread, checking for timeouts and broadcasting time information at intervals, and unicasting the logical clock information with probability, the receiving node updates the clock as needed. Combined with the binary exponent automatic synchronization mechanism, the synchronization burden is reduced.
It achieves effective synchronization of logical clocks in distributed systems, solves the problems of clock asynchrony and global event ordering, reduces the synchronization burden, and improves system performance.
Smart Images

Figure CN115549836B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distributed system application, in particular, to a design method and system of a logical clock synchronization algorithm for a distributed system, and more particularly to a design and implementation of a logical clock synchronization algorithm for a distributed system. BACKGROUND
[0002] Data consistency is an important problem in the field of distributed systems. How to efficiently and correctly synchronize data is a problem that must be considered in distributed systems. In a single computer, time is clear, but considering the case of a distributed system, it cannot be guaranteed that the physical clocks of each device are consistent. It is even more difficult to ensure that the clocks of each computer in a distributed system are consistent, and considering the case of simultaneous events, it cannot be simply assumed that the global ordering problem can be solved. If a physical clock is used for sorting, clock drift will generally have some impact. To solve such problems, clock synchronization algorithms such as NTP (Network Time Protocol), Berkeley algorithm, etc. have emerged, but the above algorithms have various problems.
[0003] A time synchronization method of a distributed mine earthquake monitoring system is disclosed in the patent document with publication number CN107147464A, which relates to a time synchronization method. This method designs two time synchronization algorithms for intra-cluster nodes and inter-cluster cluster head nodes, namely an intra-cluster slope consistency time synchronization algorithm and an inter-cluster simplified clock phase offset frequency offset joint estimation algorithm. First, the intra-cluster nodes synchronize all the nodes' clocks to a unified virtual logical clock in the entire network through the STS synchronization algorithm, and then the cluster head nodes and the anchor nodes are synchronized through the SJMLE algorithm, thereby indirectly realizing the synchronization operation between the cluster head nodes.
[0004] Therefore, it is necessary to propose a new technical solution to improve the above technical problems. SUMMARY
[0005] In view of the defects in the prior art, the purpose of the present application is to provide a design method and system of a logical clock synchronization algorithm for a distributed system.
[0006] According to the design method of a logical clock synchronization algorithm for a distributed system provided by the present application, the method comprises the following steps:
[0007] Step S1: initialize the local logical clock service, configure the logical clock parameters and other node information of the distributed system;
[0008] Step S2: start the local timing daemon thread, check whether it is overdue at intervals, broadcast the local logical time information to all other nodes if it is overdue, and reset the remaining waiting time value;
[0009] Step S3: when the node communicates with other nodes in the system, the probability is calculated and the local logical clock information is unicast to the opposite communication node according to the probability;
[0010] Step S4: if the opposite logical clock information is received by the communication receiving end node, the local logical clock is checked, the clock is updated as needed, and the remaining waiting time value of the local daemon thread is halved.
[0011] Preferably, the step S1 initializes the local logical clock service by executing an initialization function, setting the initial value of the local logical clock, and completing the initialization of all local dependent modules, and configuring the logical clock parameters and other node information of the distributed system through a designed interface as needed; the logical clock parameters include the local timing thread checking interval, the waiting time limit, the synchronization probability of unicast communication, and the clock increment.
[0012] Preferably, the step S2 starts the local timing daemon thread, which is logically a background running subroutine acting as a timer, and the main thread directly ends the step S2 after the daemon thread is started; the daemon thread checks whether the waiting time has been less than zero at intervals, and the specific interval and the length of the waiting time limit are set in the step S1; if the time is out, the local logical clock information is broadcasted to all other nodes, the remaining waiting time value is reset, and the checking is rechecked after waiting for an interval; if the time is not out, the remaining waiting time value is reduced by one local timing thread checking interval, and the checking is rechecked after waiting for an interval.
[0013] Preferably, the step S3 automatically decides whether to unicast the local logical clock information to the opposite communication node according to the synchronization probability of unicast communication when the node communicates with other nodes in the system, and if needed, initiates point-to-point communication to transmit the local logical clock information to the opposite node.
[0014] Preferably, if the opposite logical clock information is received by the communication receiving end node in the step S4, the logical clock value saved locally is checked, and if the value of the opposite logical clock is greater than the value of the local logical clock, the value of the local logical clock is set to the sum of the value of the opposite logical clock and the clock increment, and the remaining waiting time value of the local daemon thread started in the step S2 is halved.
[0015] The application also provides a design system of a logical clock synchronization algorithm for a distributed system, which comprises the following modules:
[0016] Module M1: initialize the local logical clock service, configure the logical clock parameters and other node information of the distributed system;
[0017] Module M2: start the local timing daemon thread, check whether the time is out at intervals, broadcast the local logical time information to all other nodes if the time is out, and reset the remaining waiting time value.
[0018] Module M3: when a node communicates with other nodes in the system, the probability is calculated and the local logical clock information is unicast to the opposite communication node according to the probability;
[0019] Module M4: if the communication receiving end node receives the opposite logical clock information, the local logical clock is checked, the clock is updated as needed, and the remaining waiting time value of the local daemon thread is halved.
[0020] Preferably, the module M1 initializes the local logical clock service by performing an initialization function, setting the initial value of the local logical clock, completing the initialization work of all local dependent modules, and configuring the logical clock parameters and other node information of the distributed system through a designed interface as needed; the logical clock parameters include the local timing thread check interval, the waiting time limit, the synchronization probability of unicast communication, and the clock increment.
[0021] Preferably, the module M2 starts the local timing daemon thread, which is logically a background running subroutine acting as a timer, and the main thread directly ends the module M2 after the daemon thread is started. The daemon thread checks whether the waiting time has been less than zero at intervals, and the specific interval and the length of the waiting time limit are set in the module M1. If it is overdue, the local logical clock information is broadcasted to all other nodes, the remaining waiting time value is reset according to the waiting time limit, and the re-checking is performed after waiting for an interval. If it is not overdue, the remaining waiting time value is reduced by one local timing thread check interval, and the re-checking is performed after waiting for an interval.
[0022] Preferably, the module M3 automatically decides whether to unicast the local logical clock information to the opposite communication node according to the synchronization probability of unicast communication when the node communicates with other nodes in the system. If it is needed, the local logical clock information is transmitted to the opposite node through point-to-point communication.
[0023] Preferably, if the communication receiving end node in the module M4 receives the opposite logical clock information, the logical clock value saved locally is checked. If the value of the opposite logical clock is larger than the value of the local logical clock, the value of the local logical clock is set to the sum of the value of the opposite logical clock and the clock increment, and the remaining waiting time value of the local daemon thread started in the module M2 is halved.
[0024] Compared with the prior art, the present application has the following beneficial effects:
[0025] 1. The present application solves the problem of clock asynchronization in a distributed system;
[0026] 2. The present application solves the problem of global event ordering in a distributed system;
[0027] 3. The application realizes global event total order sorting for performance-limited distributed system by improving the classical Lamport timestamp;
[0028] 4. The application introduces the mechanism of synchronization by probability and the mechanism of binary exponential automatic synchronization, reduces the burden of timestamp synchronization, and solves the defect of inaccurate synchronization of the node of only receiving but not sending;
[0029] 5. The system can effectively synchronize the logical clock in the distributed system, realize a global clock, and adjust the parameters according to the communication flow in the system to reduce the load of maintaining the global clock, while maintaining certain performance while ensuring that the clock can be synchronized basically. BRIEF DESCRIPTION OF DRAWINGS
[0030] Other features, objects and advantages of the application will become more apparent from the following detailed description of non-limiting embodiments with reference to the attached drawings:
[0031] Figure 1 The initialization function algorithm flow chart of the application is shown in the figure;
[0032] Figure 2 The communication synchronization function algorithm flow chart of the application is shown in the figure;
[0033] Figure 3 The broadcast daemon function algorithm flow chart of the application is shown in the figure;
[0034] Figure 4 The synchronization processing function algorithm flow chart of the application is shown in the figure. DETAILED DESCRIPTION
[0035] The application will be described in detail below with specific embodiments. The following embodiments will help those skilled in the art to further understand the application, but do not limit the application in any form. It should be pointed out that for those skilled in the art, without departing from the concept of the application, a number of changes and improvements can be made. These all belong to the protection scope of the application.
[0036] Example 1:
[0037] According to the design method of the logical clock synchronization algorithm for the distributed system provided by the application, the method comprises the following steps:
[0038] Step S1: initializing local logical clock service, configuring logical clock parameters, other node information of distributed system; setting local logical clock initial value by executing initialization function, completing initialization of all local dependent modules to initialize local logical clock service, configuring logical clock parameters, other node information of distributed system through designed interface as needed; logical clock parameters include local timing thread checking interval, waiting time limit, communication unicast synchronization probability, clock increment.
[0039] Step S2: starting local timing daemon thread, checking whether timeout at intervals, broadcasting local logical time information to all other nodes when timeout, resetting remaining waiting time value; starting local timing daemon thread, which is logically a background running subroutine acting as a timer, the main thread ends step S2 after starting the daemon thread, the daemon thread checks whether the waiting time is less than zero at intervals, the specific interval and the waiting time limit length are set in step S1, when timeout, the local logical clock information is broadcasted to all other nodes, the remaining waiting time value is reset according to the waiting time limit, and the remaining waiting time value is checked again after waiting for an interval, if not timeout, the remaining waiting time value is reduced by a local timing thread checking interval, and the remaining waiting time value is checked again after waiting for an interval.
[0040] Step S3: when the node communicates with other nodes in the system, calculating the probability and unicasting the local logical clock information to the opposite communication node according to the probability; when the node communicates with other nodes in the system, the local node automatically decides whether to unicast the local logical clock information to the opposite communication node according to the communication unicast synchronization probability, if needed, the local logical clock information is transmitted to the opposite node through point-to-point communication.
[0041] Step S4: if the communication receiving end node receives the opposite logical clock information, checking the local logical clock, updating the clock as needed, and halving the remaining waiting time value of the daemon thread; if the communication receiving end node receives the opposite logical clock information, checking the local logical clock value saved in the local node, if the value of the opposite logical clock is larger than the value of the local logical clock, setting the value of the local logical clock as the sum of the value of the opposite logical clock and the clock increment, and halving the remaining waiting time value of the local daemon thread started in step S2.
[0042] Example 2:
[0043] Embodiment 2 is a preferred example of Embodiment 1, which more specifically illustrates the present application.
[0044] The present application also provides a design system of a logical clock synchronization algorithm for a distributed system, which comprises the following modules:
[0045] Module M1: initialize local logical clock service, configure logical clock parameters, other nodes information of distributed system; initialize local logical clock service by setting local logical clock initial value through executing initialization function, completing initialization of all local dependent modules, configure logical clock parameters, other nodes information of distributed system through designed interface as needed; logical clock parameters include local timing thread check interval, waiting time limit, communication unicast synchronization probability, clock increment.
[0046] Module M2: start local timing daemon thread, check whether to time out at intervals, broadcast local logical time information to all other nodes when timing out, reset remaining waiting time value; start local timing daemon thread, which is logically a background running subroutine acting as a timer, the main thread ends module M2 after starting the daemon thread, the daemon thread checks whether the waiting time has been less than zero at intervals, the specific interval and waiting time limit length are both set in module M1, when timing out, broadcast local logical clock information to all other nodes, reset the remaining waiting time value according to the waiting time limit, recheck after waiting for an interval, if not timing out, reduce the remaining waiting time value by one local timing thread check interval, and recheck after waiting for an interval.
[0047] Module M3: when the node communicates with other nodes in the system, calculate the probability and unicast local logical clock information to the opposite communication node according to the probability; when the node communicates with other nodes in the system, the local node automatically decides whether to unicast local logical clock information to the opposite communication node according to the communication unicast synchronization probability, if needed, initiates point-to-point communication to transmit local logical clock information to the opposite node.
[0048] Module M4: if the communication receiving end node receives opposite logical clock information, check the local logical clock, update the clock as needed, and halve the remaining waiting time value of the daemon thread; if the communication receiving end node receives opposite logical clock information, check the logical clock value saved locally, if the value of the opposite logical clock is larger than the value of the local logical clock, set the value of the local logical clock as the sum of the value of the opposite logical clock and the clock increment, and halve the remaining waiting time value of the local daemon thread started in module M2.
[0049] Example 3:
[0050] Embodiment 3 is a preferred example of Embodiment 1, which more specifically illustrates the present application.
[0051] Data consistency is an important problem in the field of distributed. How to efficiently and correctly synchronize data is a problem that must be considered in distributed systems. In a single computer, time is explicit, but considering the case of a distributed system, it cannot be guaranteed that the physical clock of each device is consistent; more difficult is that even if the clock of each computer in the distributed system is consistent, considering the case of simultaneous events, it cannot be simply considered that the global event ordering problem can be solved. If physical clock is used for sorting, clock offset problem generally causes certain influence, in order to solve such problem. Clock synchronization algorithms such as NTP (network time protocol), Berkeley algorithm and so on emerge as the times require, but the above algorithms have some various problems, in order to further reduce the difficulty of clock synchronization, logical clock is proposed. How to correctly and efficiently synchronize the logical clock is the simplest way to realize the global clock of the distributed system, which has great significance. The existing Lamport timestamp is the most classic design of logical clock, by setting a logical clock on each node to record the event order, and synchronizing the clock when necessary, the global event ordering in the distributed system is realized. Its clock synchronization is mainly completed by the way of communication between distributed system nodes, which is high in efficiency and good in effect, and has been widely used in the industry.
[0052] In view of the defects in the prior art, the technical problems to be solved by the present application are embodied in the following points:
[0053] 1) Clock is not synchronized in the distributed system;
[0054] 2) How to sort global events in the distributed system;
[0055] The present application mainly solves the problem of clock synchronization in the distributed system. By improving the classic Lamport timestamp, the global event total order sorting in the performance limited distributed system is realized. Compared with the background technology, the present application introduces the mechanism of synchronization according to probability and the mechanism of binary exponential automatic synchronization, reduces the burden brought by timestamp synchronization, and solves the defect of inaccurate synchronization of the node of only receiving.
[0056] The method comprises the following steps:
[0057] Step 1: all nodes initialize local logical clock service, configure logical clock parameters, other node information of the distributed system;
[0058] Step 2: all nodes start local timing daemon thread, check whether it is overtime according to interval, broadcast local logical time information to all other nodes, and reset the remaining waiting time value;
[0059] Step 3: when the node communicates with other nodes in the system, the probability is calculated and the local logical clock information is unicast to the opposite communication node according to the probability;
[0060] Step 4: If the communication receiving end node receives the opposite end logical clock information, the local logical clock is checked, and the clock is updated as needed, and the remaining waiting time value of the halving daemon thread is checked.
[0061] The system can effectively synchronize the logical clock in the distributed system, realize a global clock, and adjust the parameters according to the communication traffic in the system to reduce the load of maintaining the global clock, while maintaining a certain performance while ensuring that the clock can be synchronized.
[0062] Due to the adoption of the above technical solutions, the beneficial effects of the present application are:
[0063] 1) The problem of clock asynchronization in a distributed system is solved;
[0064] 2) The problem of global event ordering in a distributed system is solved;
[0065] The clock synchronization probability on node A is set to 20%, and the synchronization broadcast time limit is 64 seconds, and the timeout is checked every 5 seconds.
[0066] The clock synchronization probability on node B is set to 50%, and the synchronization broadcast time limit is 65536 seconds, and the timeout is checked every 20 seconds.
[0067] Node A and B are both started at 0 time, B node starts immediately after A communication, and B communicates with A once, and then restarts the communication, a total of 6 times, ignoring the communication and updating the logical clock time, set communication 1, 3, 5 Node B triggers synchronization, communication 2, 4, 6 does not trigger synchronization, then:
[0068] Communication 1: B sends the local logical clock to A with a probability of 50%, A receives the clock information, updates the local logical clock, and the local broadcast time limit of A node becomes 32, and the communication is completed.
[0069] Communication 2: B sends the local logical clock to A with a probability of 50%, and since synchronization is not triggered, the communication is completed.
[0070] Communication 3: B sends the local logical clock to A with a probability of 50%, A receives the clock information, updates the local logical clock, and the local broadcast time limit of A node becomes 16, and the communication is completed.
[0071] Communication 4: B sends the local logical clock to A with a probability of 50%, and since synchronization is not triggered, the communication is completed.
[0072] Communication 5: B sends the local logical clock to A with a probability of 50%, A receives the clock information, updates the local logical clock, and the local broadcast time limit of A node becomes 8, and the communication is completed.
[0073] Communication 6: B sends local logical clock to A with 50% probability. No synchronization is triggered and the communication is completed.
[0074] Time 5: A checks local broadcast time limit, which is 3, and no synchronization is triggered.
[0075] Time 10: A checks local broadcast time limit, which is -2, and synchronization is triggered. B receives the clock information, updates the local logical clock, and the local broadcast time limit of B becomes 32768. A resets the local broadcast time limit to 64.
[0076] Time 20: B checks local broadcast time limit, which is 32748, and no synchronization is triggered.
[0077] Those skilled in the art can understand the present embodiment as a more specific description of Embodiment 1 and Embodiment 2.
[0078] Those skilled in the art know that, in addition to implementing the system provided by the present application and each device, module, unit thereof in the form of pure computer readable program code, the system provided by the present application and each device, module, unit thereof can also be implemented in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers and embedded microcontrollers, etc. to achieve the same function by logically programming the method steps. Therefore, the system provided by the present application and each device, module, unit thereof can be considered as a hardware component, and the devices, modules, units included therein for achieving various functions can also be considered as structures within the hardware component; the devices, modules, units for achieving various functions can also be considered as both software modules for implementing methods and structures within hardware components.
[0079] The specific embodiments of the present application are described above. It should be understood that the present application is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essential content of the present application. In the case of no conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A design method of a logical clock synchronization algorithm for a distributed system, characterized by, The method comprises the following steps: Step S1: initializing local logical clock service, configuring logical clock parameters and other node information of distributed system; Step S2: starting local timing daemon thread, checking whether to time out at intervals, broadcasting local logical time information to all other nodes when timing out, and resetting remaining waiting time value; Step S3: when a node communicates with other nodes in the system, calculating probability and unicasting local logical clock information to the opposite communication node according to the probability; Step S4: if the communication receiving end node receives opposite logical clock information, checking local logical clock, updating clock as needed, and halving the remaining waiting time value of the daemon thread.
2. The method for designing logical clock synchronization algorithm for distributed systems as claimed in claim 1 wherein, The step S1 initializes the local logical clock service by executing an initialization function, setting the initial value of the local logical clock, and completing the initialization work of all local dependent modules, and configuring the logical clock parameters and other node information of the distributed system through a designed interface as needed; the logical clock parameters comprise local timing thread checking interval, waiting time limit, synchronization probability of unicast communication, and clock increment.
3. The method for designing logical clock synchronization algorithm for distributed systems as claimed in claim 1 wherein, The step S2 starts the local timing daemon thread, which is logically a background running subroutine acting as a timer; after the daemon thread is started, the main thread directly ends the step S2; the daemon thread checks whether the waiting time is less than zero at intervals; the specific interval and the length of the waiting time limit are set in the step S1; when timing out, the local logical clock information is broadcasted to all other nodes; the remaining waiting time value is reset according to the waiting time limit; after waiting for an interval, the checking is re-performed; if not timing out, the remaining waiting time value is reduced by one local timing thread checking interval; after waiting for an interval, the checking is re-performed.
4. The method for designing logical clock synchronization algorithm for distributed systems as claimed in claim 1 wherein, The step S3, when a node communicates with other nodes in the system, the local node automatically decides whether to unicast the local logical clock information to the opposite communication node according to the synchronization probability of unicast communication; if needed, the local logical clock information is transmitted to the opposite node through point-to-point communication.
5. The method for designing logical clock synchronization algorithm for distributed systems as claimed in claim 1 wherein, In the step S4, if the communication receiving end node receives opposite logical clock information, the logical clock value saved locally is checked; if the value of the opposite logical clock is relatively larger than the value of the local logical clock, the value of the local logical clock is set as the sum of the value of the opposite logical clock and the clock increment; the remaining waiting time value of the local daemon thread started in the step S2 is halved.
6. A design system of a logical clock synchronization algorithm for a distributed system, characterized by, The system comprises the following modules: Module M1: initializing local logical clock service, configuring logical clock parameters and other node information of distributed system; Module M2: starting local timing daemon thread, checking whether to time out at intervals, broadcasting local logical time information to all other nodes when timing out, and resetting remaining waiting time value; Module M3: when a node communicates with other nodes in the system, calculating probability and unicasting local logical clock information to the opposite communication node according to the probability; Module M4: if the communication receiving end node receives opposite logical clock information, checking local logical clock, updating clock as needed, and halving the remaining waiting time value of the daemon thread.
7. The design system of logical clock synchronization algorithm for distributed systems according to claim 6, characterized in that, The module M1 initializes the local logical clock service by executing an initialization function, setting a local logical clock initial value, and completing the initialization of all local dependent modules, and configures logical clock parameters and other node information of a distributed system through a designed interface according to needs; the logical clock parameters include a local timing thread check interval, a waiting time limit, a communication unicast synchronization probability, and a clock increment.
8. The system for designing logical clock synchronization algorithm for distributed systems as claimed in claim 6 wherein, The module M2 starts a local timing daemon thread, which is logically a background running subroutine acting as a timer; after the daemon thread is started, the main thread directly ends the module M2; the daemon thread checks whether the waiting time has been less than zero at intervals, and the specific interval and the waiting time limit length are both set in the module M1; if the waiting time is exceeded, the local logical clock information is broadcast to all other nodes, the remaining waiting time value is reset according to the waiting time limit, and the checking is re-performed after an interval; if the waiting time is not exceeded, the remaining waiting time value is reduced by one local timing thread check interval, and the checking is re-performed after an interval.
9. The system for designing logical clock synchronization algorithm for distributed systems as claimed in claim 6 wherein, The module M3 automatically determines whether to unicast the local logical clock information to a communication node at the other end according to the communication unicast synchronization probability when the node communicates with other nodes in the system; if yes, the local logical clock information is transmitted to the communication node at the other end through point-to-point communication.
10. The system for designing logical clock synchronization algorithm for distributed systems as claimed in claim 6 wherein, If the communication receiving end node in the module M4 receives the logical clock information of the other end, the logical clock value saved locally is checked; if the value of the logical clock of the other end is greater than the value of the local logical clock, the value of the local logical clock is set to the sum of the value of the logical clock of the other end and the clock increment, and the remaining waiting time value of the local daemon thread started in the module M2 is halved.
Citation Information
Patent Citations
Time synchronization method of distributed mine seismic monitoring system
CN107147464A