Distributed node time synchronization method in local area network, electronic equipment and storage medium
By setting time weights and calculating network delays and time differences in the LAN, distributed node time synchronization is achieved, which solves the problem of node time inconsistency in the LAN and improves the accuracy of time synchronization and system fault tolerance.
Patent Information
- Application Number
- CN202410633687.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-09-10
AI Technical Summary
When the LAN cannot communicate with the external Internet, multiple nodes in the system have different times, making it impossible to achieve accurate and consistent time synchronization, affecting fault tracking and function recovery.
By setting the time weight before the node joins the LAN, the network delay and time difference between nodes are calculated, the unified time is calculated, and the time weight information is carried in the node discovery message, and time synchronization is performed in a distributed manner to ensure that the LAN The time consistency of all nodes in the network.
Without relying on the external Internet, it achieves the unification of node times within the LAN, improves the accuracy and reliability of time synchronization, reduces dependence on a single node, enhances system fault tolerance, and saves network resources. .
Smart Images

Figure CN118631374A
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer networks, and relates to a distributed node time synchronization method in a local area network, an electronic device and a storage medium. Background Art
[0002] In existing network systems, some applications and systems use timestamps as a sorting standard to determine the order in which events occur. In a system network, time consistency between different nodes is critical to the accuracy and reliability of completing transactions. In some critical applications, the impact of downtime of each module node on system functions needs to be considered. Therefore, during network failure and recovery, accurate and consistent time information is very helpful for tracking and locating failure problems and restoring functions.
[0003] Existing network time synchronization technology usually obtains the most accurate time from a unified standard server. However, when the local area network cannot communicate with the external Internet, multiple nodes in the system have different times. At this moment, it is very important to calculate the more authoritative node time in the system and synchronize this time to the entire system. Summary of the invention
[0004] The technical solution of the present invention is used to solve the problem of how to complete the time synchronization of each node inside the local area network system when the local area network cannot or does not need to communicate with the external Internet.
[0005] The present invention solves the above technical problems through the following technical solutions:
[0006] A distributed node time synchronization method in a local area network comprises the following steps:
[0007] Step 1: Before a node joins a local area network, set a time weight for each node;
[0008] Step 2: Calculate the network delay and time difference between each node;
[0009] Step 3: Calculate the unified time of each node to ensure that the time calculated by all nodes in the LAN is consistent;
[0010] Step 4: Based on the calculated unified time, for nodes that need to adjust the time, divide the unified time into multiple times to adjust the nodes.
[0011] Furthermore, the method of determining the network delay and time difference between the nodes is as follows:
[0012] When the network fails and recovers or a node initially joins the network, the current node sends a node discovery message to other nodes in a distributed manner, requests the time weight of other nodes and the current time of other nodes, and records the time when the current node sends the discovery message. The node discovery message carries the time weight information of the current node;
[0013] When other nodes receive the node discovery message, they add the time when other nodes received the message, the time when other nodes replied to the message, and the time weight of other nodes in the reply message; when the current node receives the reply message from other nodes, it records the time when the current node receives the reply message from other nodes;
[0014] Then, the network delay between the current node and other nodes is: the difference between the time difference between the current node sending and receiving messages and the time difference between the other nodes sending and receiving messages;
[0015] The time difference between the current node and other nodes is: the difference between the time when other nodes receive the message and the time when the current node sends the message and half of the network delay.
[0016] Furthermore, the method for calculating the unified time of each node is as follows: taking the current node as the benchmark, multiplying the time weights of other nodes by the time difference between the current node and other nodes and then adding them, and then adding the current time of the current node, finally obtaining the unified time within the local area network of the current node.
[0017] Furthermore, the node discovery message is periodically published to all nodes in the local area network.
[0018] Furthermore, the time weight is manually set by the user before the node is accessed.
[0019] An electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above-mentioned distributed node time synchronization method in a local area network, and the processor is configured to execute the program stored in the memory.
[0020] A storage medium stores a computer program, which executes the steps of the above-mentioned distributed node time synchronization method in a local area network when the computer program is run by a processor.
[0021] The advantages of the present invention are:
[0022] The technical solution of the present invention ensures that the node time in the same local area network is unified when the connection with the external Internet is disconnected, reduces the system's connection requirements for the Internet, and the synchronization message is attached to the node discovery message, saving network resources in the local area network. A distributed synchronization calculation method is adopted, and each node participates in the synchronization process; by comprehensively considering the time information of multiple nodes, the accuracy and reliability of the synchronization result can be improved; this distributed synchronization method reduces the dependence on a single node and enhances the fault tolerance of the system; there is no need to connect to the external Internet to achieve real-time time synchronization of nodes in the local area network. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a schematic diagram of network delay and time difference during the time synchronization between nodes;
[0024] Figure 2 This is a schematic diagram of the final unified time obtained by each node during the inter-node time synchronization process;
[0025] Figure 3 The figure is a flowchart of a distributed node time synchronization method.
[0026] Figure 4 This is the application of the method of the present invention in the industrial robot cloud management platform. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in combination with the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and specific embodiments:
[0029] Embodiment 1
[0030] like Figure 1 As shown, the distributed node time synchronization method in the local area network of this embodiment includes the following steps:
[0031] Step 1: Before a node joins a local area network, set a time weight for each node.
[0032] like Figure 2 As shown, this embodiment is described by taking five nodes, namely, node A, node B, node C, node D, and node E in a local area network as an example.
[0033] In the initial state, before nodes A, B, C, D, and E join the LAN, a time weight is set for each node according to its importance, which are: ω A ,ω B ,ω C ,ω D ,ω E ,The time weight of each node is used as the basis for determining the credibility of its time state. It should be noted that the time weight is manually set by the user before the node is connected and cannot be changed at will.
[0034] Step 2: Calculate the network delay and time difference between each node.
[0035] like Figure 3 As shown, the calculation of the network delay and time difference between node A and node B is taken as an example for explanation.
[0036] When the network fails and recovers or a node initially joins the network, node A sends a node discovery message to node B, and requests the time weight of node B and the current time t of node B. B , and records the time t1 when node A sends the discovery message, the node discovery message carries the time weight information of node A. The node discovery message is periodically published to all nodes in the local area network; the node discovery process adopts a distributed discovery process.
[0037] Node B receives the node discovery message and adds the time t2 when node B receives the message, the time t3 when node B replies to the message, and the time weight of node B in the reply message; when node A receives the reply message from node B, it records the time t4 when node A receives the reply message from node B, and then calculates the network delay ΔI between node A and node B AB and the time difference ΔT between node A and node B AB .
[0038] The network delay ΔI between node A and node B AB Refers to the time consumed by the message transmission process between node A and node B, and the calculation formula is: ΔI AB =(t4-t1)-(t3-t2); the time difference ΔT between node A and node B AB The calculation formula is:
[0039] Similarly, calculate:
[0040] The network delay ΔI between node A and node C AC and the time difference ΔT between node A and node C AC ;
[0041] The network delay ΔI between node A and node D AD and the time difference ΔT between node A and node D AD ;
[0042] The network delay ΔI between node A and node E AE and the time difference ΔT between node A and node E AE ;
[0043] The network delay ΔI between node B and node C BC and the time difference ΔT between node B and node C BC ;
[0044] The network delay ΔI between node B and node D BD and the time difference ΔT between node B and node D BD ;
[0045] The network delay ΔI between node B and node E BE and the time difference ΔT between node B and node E BE ;
[0046] The network delay ΔI between node C and node D CD and the time difference ΔT between node C and node D CD ;
[0047] The network delay ΔI between node C and node E CE and the time difference ΔT between node C and node E CE ;
[0048] The network delay ΔI between node D and node E DE and the time difference ΔT between node D and node E DE ;
[0049] Step 3: Calculate the unified time of each node to ensure that the time calculated by all nodes in the LAN is consistent.
[0050] According to the time weight ω of the node A ,ω B ,ω C ,ω D ,ω E , the current time t of the node A ,t B ,t C ,t D ,t E , and the time difference ΔT of the nodes AB , ΔT AC , ΔT AD , ΔT AE , ΔT BC , ΔTBD , ΔT BE , ΔT CD , ΔT CE , ΔT DE Calculate the unified time of each node. The calculation formula for the unified time of each node is as follows:
[0051] T A =t A +ω B ×ΔT AB +ω C ×ΔT AC +ω D ×ΔT AD +ω E ×ΔT AE
[0052] T B =t B +ω A ×ΔT AB +ω C ×ΔT BC +ω D ×ΔT BD +ω E ×ΔT BE
[0053] T C =t C +ω A ×ΔT AC +ω B ×ΔT BC +ω D ×ΔT CD +ω E ×ΔT CE
[0054] T D =t D +ω A ×ΔT AD +ω B ×ΔT BD +ω C ×ΔT CD +ω E ×ΔT DE
[0055] T E =t E +ω A ×ΔT AE +ω B ×ΔT BE +ω C ×ΔT CE +ω D ×ΔT DE
[0056] Among them, T A is the unified time of node A, T B is the unified time of node B, T C is the unified time of node C, T D is the unified time of node D, T E is the unified time of node E.
[0057] Step 4: According to the unified time calculated in step 3, for the nodes that need to adjust the time, the unified time is divided into multiple times to adjust the nodes. This prevents the time from flowing backwards and causing confusion in the business logic of the LAN system.
[0058] like Figure 4 As shown, the industrial robot cloud management platform manages multiple robot nodes at the same time. The platform adopts the method of the present invention to achieve unified time management of the managed industrial robot nodes, so that the transactions generated by the nodes in the system are executed in accurate time sequence.
[0059] Embodiment 2
[0060] An electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the distributed node time synchronization method in a local area network in embodiment 1, and the processor is configured to execute the program stored in the memory.
[0061] Embodiment 3
[0062] A storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the distributed node time synchronization method in a local area network in embodiment 1 are executed.
[0063] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed node time synchronization method in a local area network, characterized in that: The following steps are involved: Step 1: Before a node joins a local area network, set a time weight for each node; Step 2: Calculate the network delay and time difference between each node; Step 3: Calculate the unified time of each node to ensure that the time calculated by all nodes in the LAN is consistent; Step 4: Based on the calculated unified time, for nodes that need to adjust the time, divide the unified time into multiple times to adjust the nodes.
2. The distributed node time synchronization method in a local area network according to claim 1, characterized in that: The method of network delay and time difference between nodes is as follows: When the network fails and recovers or a node initially joins the network, the current node sends a node discovery message to other nodes in a distributed manner, requests the time weight of other nodes and the current time of other nodes, and records the time when the current node sends the discovery message. The node discovery message carries the time weight information of the current node; When other nodes receive the node discovery message, they add the time when other nodes received the message, the time when other nodes replied to the message, and the time weight of other nodes in the reply message; when the current node receives the reply message from other nodes, it records the time when the current node receives the reply message from other nodes; Then, the network delay between the current node and other nodes is: the difference between the time difference between the current node sending and receiving messages and the time difference between the other nodes sending and receiving messages; The time difference between the current node and other nodes is: the difference between the time when other nodes receive the message and the time when the current node sends the message and half of the network delay.
3. The distributed node time synchronization method in a local area network according to claim 2, characterized in that: The method for calculating the unified time of each node is as follows: taking the current node as the benchmark, multiplying the time weights of other nodes by the time difference between the current node and other nodes, then adding the current time of the current node, and finally obtaining the unified time within the local area network of the current node.
4. The distributed node time synchronization method in a local area network according to claim 1, characterized in that: The node discovery message is periodically published to all nodes in the local area network.
5. The distributed node time synchronization method in a local area network according to claim 1, characterized in that: The time weight is manually set by the user before the node is connected.
6. An electronic device, comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the distributed node time synchronization method in a local area network as described in any one of claims 1 to 5, and the processor is configured to execute the program stored in the memory.
7. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the distributed node time synchronization method in a local area network as claimed in any one of claims 1 to 5 are executed.
