CN111865468B - Precise time synchronization method - Google Patents
Precise time synchronization method Download PDFInfo
- Publication number
- CN111865468B CN111865468B CN202010703333.6A CN202010703333A CN111865468B CN 111865468 B CN111865468 B CN 111865468B CN 202010703333 A CN202010703333 A CN 202010703333A CN 111865468 B CN111865468 B CN 111865468B
- Authority
- CN
- China
- Prior art keywords
- time
- server
- value
- client
- correction
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Synchronisation In Digital Transmission Systems (AREA)
- Electric Clocks (AREA)
Abstract
The invention relates to the time synchronization field, and particularly provides an accurate time synchronization method, wherein a server is selected as a time server in a local area network or a wide area network, and a server module is arranged on the time server; the method comprises the steps that a client module is installed on a server needing time synchronization in a local area network or a wide area network, the client module obtains time from the server module according to a specific protocol and synchronizes the time to the server needing time synchronization, and the server needing time synchronization and the time server obtain consistent time through two times of time correction. Compared with the prior art, the method can obtain 0.01 millisecond-level accurate time synchronization under the condition of low cost, and has good popularization value.
Description
Technical Field
The invention relates to the field of time synchronization, and particularly provides an accurate time synchronization method.
Background
In network environments such as cloud computer rooms and data centers, time synchronization is needed for each computer in a local area network, but the commonly used time synchronization modes such as NTP and SNTP can only provide accuracy of 1ms to 1 second level, generally, tens of milliseconds are provided in most cases, and the requirements cannot be met for occasions with high time accuracy requirements. The use of more accurate GPS time service or atomic clock time service is influenced by factors such as environment and cost, and cannot be widely used in a local area network environment.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a precise time synchronization method with strong practicability.
The technical scheme adopted by the invention for solving the technical problem is as follows:
a precise time synchronization method selects a server in a local area network or a wide area network as a time server, and a server module is arranged on the time server;
the method comprises the steps that a client module is installed on a server needing time synchronization in a local area network or a wide area network, the client module obtains time from the server module according to a specific protocol and synchronizes the time to the server needing time synchronization, and the server needing time synchronization and the time server obtain consistent time through two times of time correction.
Preferably, the time server performs accurate time service, and an atomic clock with high accuracy, a GPS time service, or the like can be selected.
Further, the specific protocol is:
the method comprises the steps that a T1 time point on a client sends a first time obtaining request to a server, the time value T2 of the server is immediately sent back to the corresponding client after the first time request is obtained at the T2 time point of the server, and the client records the time point T3 after receiving the time value T2.
Further, if the difference between T3 and T1 is d, d is the time taken by the operation, and d includes the time d1 taken from time point T1 to T2 and the time d2 taken from time points T2 and T3, that is, d is d1+ d 2.
Further, the difference d further includes round-trip network delay and time of sending and receiving processing of the two end networks;
in general, the network delays of round trips are approximately equal, i.e., d 1-d 2-d/2,
the value of T2 plus d2 may be considered to be the time value of the time point T3 client server.
Further, the first time correction is:
continuously operating the requests of the client and the server for a plurality of times, recording the values of T1, T2, T3 and d each time, calculating the arithmetic mean value d0 of d, and calculating the deviation absolute value P1 of the d value and d0 each time;
calculating the percentage P2 of P1 and d0, and if the value of each P2 is smaller than the set first value, considering that the group of values can be subjected to the next time correction through the first time correction;
the process of calculating the offset is time consuming, recording the value of time it takes j, and synchronizing with the value of T2 of the last operation plus d0/2 plus j as the client server's time value, i.e. the offset in time is d0/2 x 5%.
Further, if the values of each P2 cannot all be less than the set first value, a new calibration is required.
Further, the second time correction is:
continuously operating the requests of the client and the server for a plurality of times, recording the values of T1, T2 and T3 each time, theoretically, T2+ d2 is equal to T3 because once correction is performed, but the actual operation still has errors, calculating the arithmetic mean value d3 of d2, calculating the absolute value P3 of the deviation of d2 and d3 each time, then calculating the percentage P4 of P3 and d3, and if the value of P4 is smaller than the preset value each time, considering that the preset value is smaller than the set first value through second time correction;
the above procedure of calculating the deviation is also time-consuming, the time value j taken is recorded, and the T2 value of the last operation is added to d0 and added to j as the time value of the client server for synchronization, and the deviation of the time precision is d0 × 1%.
Further, if the values of each P4 cannot all be smaller than the re-set value, the second correction needs to be performed again.
Furthermore, the client module records the time difference of each correction, calculates the deviation rule, and can calculate the relative accurate time of the current server by adding the time value of the last correction to the deviation value of the deviation rule when the server where the client is located and the time server network are occasionally disconnected.
Compared with the prior art, the accurate time synchronization method has the following outstanding beneficial effects:
the scheme of the invention also needs to set a time server, install a time synchronization server module on the time server, install a time synchronization client module on other servers, and synchronize according to a specific protocol, so that the accurate time synchronization of 0.01 millisecond level can be obtained under the condition of low cost, and the method has good popularization value.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic diagram of a precise time synchronization method.
Detailed Description
The present invention will be described in further detail with reference to specific embodiments in order to better understand the technical solutions of the present invention. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
A preferred embodiment is given below:
as shown in fig. 1, an accurate time synchronization method in this embodiment takes a local area network as an example.
A server is selected from a local area network as a time server, an atomic clock is selected as the server for accurate time service, and a server module is arranged on the time server.
The client module is installed on the server which needs time synchronization in the local area network, the client installs the specific protocol designed by the invention to acquire time from the server module and synchronize the time to the server which needs time synchronization, and the server which needs time synchronization can acquire time consistent with the time server through two times of time correction, and the synchronization precision can reach 0.01 millisecond.
The specific protocol designed by the invention is as follows:
the method comprises the steps that a clock of a server where a client is located is used for timing, and a first time obtaining request is sent to a server at the time point T1 on the client;
after the time point T2 of the server (clocked by the clock of the server where the server is located) obtains the request, the time value T2 (accurate to microseconds) of the server is immediately sent back to the corresponding client, and the client records the time point T3 (clocked by the clock of the server where the client is located) after receiving the time value.
The difference between the operations T3 and T1 is the time d spent in the operation, which includes the time d1 spent from time T1 to T2 and the time d2 spent from time T2 to T3, i.e., d1+ d 2.
Since the value of T2 is not recorded by the same clock as the values of T1 and T3, the values of d1 and d2 in a single operation cannot be calculated, but the values of T1 and T3 are from the same clock, and the difference d is accurate.
The difference d further includes the round-trip network delay and the time of the sending and receiving processes of the two networks. In general, the network delays of round trips are approximately equal, and can be regarded as d1, d2, d/2, so that the value of T2 plus d2 can be regarded as the time value of the client server at the time point T3, and since the value of d changes every time, the time precision of synchronization is not high, and the deviation is equal to d 2.
In order to improve the accuracy of synchronization, a first time of time correction is carried out:
the above operations are performed 10 times without interruption, and the corresponding values of T1, T2, and T3 are recorded each time, and the difference d between T3 and T1 is calculated.
The arithmetic mean d0 of d is calculated 10 times, the absolute value P1 of the deviation of the d value from d0 is calculated each time, then the percentage P2 of P1 and d0 is calculated, if the value of P2 is less than 5% of the first value set in 10 consecutive times, the group of values is considered to pass the first time correction, and the next time correction can be carried out.
If the values of P2 in 10 consecutive times cannot all be less than 5%, the first time correction needs to be performed again.
The process of calculating the deviation is time-consuming, the time value j spent on the calculation is recorded, the T2 value of the last operation is added with d0/2 and j to be used as the time value of the client server for synchronization, the deviation of the time precision is d0/2 x 5%, and the precision is improved by at least 10 times compared with the one operation. The synchronization is the first time synchronization, and after the first time synchronization, in high-speed network environments such as gigabit local area networks and the like, the time synchronization deviation is generally less than 0.01 millisecond.
In order to further improve the synchronization precision, a second time of time correction is performed.
The time obtaining operation from the server is continuously executed several times, in this embodiment, 5 times are taken as an example, corresponding values of T1, T2 and T3 are recorded each time, and since the first time of time correction is performed, theoretically T2+ d2 is T3, but actually there is a different value of d2 each time.
The arithmetic mean d3 of d2 was calculated 5 times, and the absolute value P3 of the deviation of d2 from d3 was calculated each time, then the percentage P4 of P3 from d3 was calculated. If the value of P4 in 5 consecutive passes is less than the reset value of 1%, the second time correction is passed.
If the values of P2 cannot all be less than 1% in 5 consecutive times, the second time correction needs to be performed again.
The above procedure of calculating the deviation is also time-consuming, the time value j taken is recorded, and the T2 value of the last operation plus d3 plus j can be used as the time value of the client server to perform synchronization, the deviation of the time precision is d3 x 1%, in high-speed network environments such as gigabit local area networks, the value of d3 is generally less than 100 microseconds, and the deviation of the time synchronization is about 1 microsecond.
After two time correction synchronizations, the time of the server where the client is located can be considered to be consistent with the time of the server, but may be affected by the fluctuation of the crystal oscillator frequency, and after one time, the time deviation between the two servers is gradually increased, so the time correction process needs to be executed once every other time.
When the server where the client is located is occasionally disconnected from the time server network, the time correction process is affected. The client module can record the time difference (which can be positive or negative) of each correction, calculate the deviation rule, and when the server where the client is located and the time server network are occasionally disconnected, the time value of the last correction and the deviation value of the deviation rule can be used for calculating the relative accurate time of the current server.
The server module in the scheme can provide more than 10 thousands of concurrent access capabilities and can provide accurate time synchronization service for tens of thousands of servers simultaneously.
When the method is used in a wide area network environment, the relative deviation parameters need to be adjusted to be large, and better time synchronization accuracy can be obtained.
The above embodiments are only specific ones of the present invention, and the scope of the present invention includes but is not limited to the above embodiments, and any suitable changes or substitutions that are consistent with the claims of a precise time synchronization method of the present invention and are made by those skilled in the art shall fall within the scope of the present invention.
Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that changes, modifications, substitutions and alterations can be made in these embodiments without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.
Claims (3)
1. A precise time synchronization method is characterized in that a server is selected from a local area network or a wide area network as a time server, the time server carries out precise time service, and a server module is arranged on the time server;
installing a client module on a server needing time synchronization in a local area network or a wide area network, acquiring time from the server module by the client module according to a specific protocol, synchronizing the time to the server needing time synchronization, and acquiring consistent time from the server needing time synchronization and the time server through two times of time correction;
the specific protocol is as follows:
a time point T1 on a client sends a first time acquisition request to a server, the time value T2 of the server is immediately sent back to the corresponding client after the first time acquisition request is obtained at the time point T2 of the server, and the client records the time point T3 after receiving the time value T2;
if the difference between T3 and T1 is d, d is the time taken for the client to send the first time acquisition request to the server at the time point T1, and d includes the time d1 taken from time point T1 to time point T2 and the time d2 taken at time points T2 and T3, that is, d is d1+ d 2;
the difference d further comprises the round-trip network delay and the time of sending and receiving processing of the two end networks;
in general, the network delays of round trips are approximately equal, i.e., d 1-d 2-d/2,
the value of T2 plus d2 may be considered to be the time value of the time point T3 client server;
the first time correction is:
continuously operating the requests of the client and the server for a plurality of times, recording the values of T1, T2, T3 and d each time, calculating the arithmetic mean value d0 of d, and calculating the deviation absolute value P1 of the d value and d0 each time;
then calculating the percentage P2 of P1 and d0, if the value of each P2 is less than the set first value, and the first value is 5%, considering that the values of T1, T2, T3 and d pass the first time correction, and performing the next time correction;
the process of calculating the deviation is time-consuming, the time value j0 spent on the process is recorded, and the T2 value of the last operation is added with d0/2 and added with j0 to be used as the time value of the client server for synchronization, namely the deviation of the time is d0/2 x 5%;
if all the values of P2 cannot be smaller than the set first value, the correction needs to be carried out again;
the second time correction is:
continuously operating the requests of the client and the server for a plurality of times, recording the values of T1, T2 and T3 each time, theoretically, T2+ d2 is T3 as one correction is already carried out, but the actual operation still has errors, calculating the arithmetic mean value d3 of d2, calculating the absolute value P3 of the deviation of d2 and d3 each time, then calculating the percentage P4 of P3 and d3, and if the value of P4 is smaller than the preset value each time, and the preset value is 1%, then considering that the correction is carried out for the second time;
the process of calculating the deviation for the second time is also time-consuming, the time value j spent is recorded, and the T2 value of the last operation is added with d3 and j to be used as the time value of the client server for synchronization, and the deviation of the time precision is d3 x 1%.
2. The method of claim 1, wherein if the values of P4 are not all smaller than the preset value, the second correction is needed.
3. The method of claim 2, wherein the client module records the time difference between each calibration and calculates the deviation rule, and when the server at the client and the time server network are occasionally disconnected, the accurate time of the current server can be calculated by adding the deviation value of the deviation rule to the last time value calibrated.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010703333.6A CN111865468B (en) | 2020-07-21 | 2020-07-21 | Precise time synchronization method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010703333.6A CN111865468B (en) | 2020-07-21 | 2020-07-21 | Precise time synchronization method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111865468A CN111865468A (en) | 2020-10-30 |
CN111865468B true CN111865468B (en) | 2022-09-20 |
Family
ID=73001362
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010703333.6A Active CN111865468B (en) | 2020-07-21 | 2020-07-21 | Precise time synchronization method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111865468B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113037418B (en) * | 2021-03-17 | 2023-06-20 | 广州虎牙科技有限公司 | Error correction method and related device for network time service |
CN115001615B (en) * | 2022-05-25 | 2024-07-26 | 中国第一汽车股份有限公司 | Synchronous control method, device, system and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101296048A (en) * | 2008-06-17 | 2008-10-29 | 杭州华三通信技术有限公司 | Time synchronization method and apparatus |
CN111224733A (en) * | 2020-01-09 | 2020-06-02 | 珠海格力电器股份有限公司 | Time calibration method, device, computer equipment and storage medium |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
NO20006684D0 (en) * | 2000-12-28 | 2000-12-28 | Abb Research Ltd | Time Synchronization |
CN105187148B (en) * | 2015-08-17 | 2017-12-08 | 武汉理工大学 | A kind of network clock synchronization system and method based on ARM |
-
2020
- 2020-07-21 CN CN202010703333.6A patent/CN111865468B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101296048A (en) * | 2008-06-17 | 2008-10-29 | 杭州华三通信技术有限公司 | Time synchronization method and apparatus |
CN111224733A (en) * | 2020-01-09 | 2020-06-02 | 珠海格力电器股份有限公司 | Time calibration method, device, computer equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111865468A (en) | 2020-10-30 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20220182164A1 (en) | Method of remotely monitoring the timing performance of a ptp slave | |
EP3009897B1 (en) | Distribution device, distribution system, and distribution method | |
US9813226B2 (en) | Modeling a clock | |
CN111865468B (en) | Precise time synchronization method | |
Derviškadić et al. | The white rabbit time synchronization protocol for synchrophasor networks | |
CN112332941A (en) | Time error correction method based on distributed system | |
US9846062B2 (en) | Timestamping in wind turbines | |
EP2627040A1 (en) | Method for eliminating systematical error components in a set of one-way delay measurement results for communications between two or more computing systems in a communication network, apparatus for performing the method and computer program product | |
CN116131984A (en) | Reference time determining method and device, electronic equipment and storage medium | |
CN114035740B (en) | Method, device and system for synchronizing clock crystal oscillator | |
CN113589675B (en) | Network time synchronization method and system with traceability | |
CN112019288B (en) | Time synchronization method, service single board and network equipment | |
CN111614427A (en) | High-accuracy time transfer device, method and system based on hospital time plate | |
Han et al. | Time consistency technique of multi-aircrafts simulation system for cooperative mission | |
CN114070762B (en) | Network monitoring probe assembly, synchronization method and data acquisition and analysis device | |
CN111953443B (en) | Resource processing method, device, electronic equipment, storage medium and system | |
CN113114450B (en) | Whole network clock feedback method and system | |
US11853114B1 (en) | Virtualized hardware clocks for providing highly accurate time information in hosted machine instances | |
US11855757B1 (en) | Highly accurate time information in hosted machine instances using dedicated timing network | |
Shukui et al. | FPGA-based high-precision network time synchronization research and implementation | |
JP2018189592A (en) | Time synchronizing device, time synchronization method, and time synchronizing program | |
JP6969150B2 (en) | Time synchronization device, time synchronization method and time synchronization program | |
CN118677563A (en) | Time synchronization method, device, equipment and medium | |
CN118631376A (en) | Virtual power plant time service method, device, equipment and storage medium | |
Ma et al. | Precision Time Synchronization Using IEEE 1588 for Distributed Acoustic Measurement |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |