CN113037418A - Error correction method for network time service and related device - Google Patents

Error correction method for network time service and related device Download PDF

Info

Publication number
CN113037418A
CN113037418A CN202110287784.0A CN202110287784A CN113037418A CN 113037418 A CN113037418 A CN 113037418A CN 202110287784 A CN202110287784 A CN 202110287784A CN 113037418 A CN113037418 A CN 113037418A
Authority
CN
China
Prior art keywords
time
server
local client
error correction
client
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.)
Granted
Application number
CN202110287784.0A
Other languages
Chinese (zh)
Other versions
CN113037418B (en
Inventor
贺凯
刘超群
郑悄
陈伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Huya Technology Co Ltd
Original Assignee
Guangzhou Huya Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Guangzhou Huya Technology Co Ltd filed Critical Guangzhou Huya Technology Co Ltd
Priority to CN202110287784.0A priority Critical patent/CN113037418B/en
Publication of CN113037418A publication Critical patent/CN113037418A/en
Application granted granted Critical
Publication of CN113037418B publication Critical patent/CN113037418B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0682Clock or time synchronisation in a network by delay compensation, e.g. by compensation of propagation delay or variations thereof, by ranging

Abstract

The application discloses an error correction method and a related device for network time service, wherein the error correction method comprises the following steps: calculating to obtain local client time by utilizing an NTP (network time protocol) time synchronization algorithm and a server; sending an error correction request to a server, and recording the starting time of a local client, wherein the starting time is obtained by calculating the time of the local client; acquiring server time returned by a server; and recording an end time of the local client based on the start time; responding to the server time not belonging to the time period of the starting time and the ending time, and acquiring a time alignment error interval by using the server time; and correcting the local client time by using the upper limit value and the lower limit value of the time alignment error interval. By the method, the network time service is corrected, the time service error of the local client is reduced, and the time of the local client is more accurate.

Description

Error correction method for network time service and related device
Technical Field
The present invention relates to the field of network time application, and in particular, to an error correction method and related apparatus for network time service.
Background
In a distributed system composed of a computer network system, a lot of operations need to be performed in a coordinated and consistent manner, and the operation coordination and consistency are achieved, and accurate time synchronization is one of important bases.
Some network time service technologies are provided in the process of computer network technology development, and the existing computer network time synchronization technologies include an NTP (network time protocol) technology, a PTP technology, a SyncE synchronous Ethernet technology and the like, but the technologies all have the problems that the realization depends on specific hardware support, the time service precision is strong, and the network stability is depended on, and the requirements of universality and high precision cannot be met in practical engineering application.
The existing Ethernet time synchronization method mainly comprises NTP and IEEE1588 protocols, wherein the NTP provides a low-cost network time synchronization method, and the time mark is acquired by an application layer, so that the time synchronization precision is low and generally about 10ms, and the engineering requirement cannot be met; the latter method obtains time mark at protocol bottom layer, and realizes clock synchronization by using communication link of network, with high precision up to 100 ns. Both are time-aligned by means of a bi-directional transmission delay of data packets by adding time-aligned data packets (time stamps) to the data stream. The method needs to occupy data transmission bandwidth, is influenced by the bidirectional transmission load of the network, and seriously influences the timing precision when the transmission load of any direction of the network is heavy.
Disclosure of Invention
The technical problem mainly solved by the application is to provide a method and a device for correcting errors of network time service, so as to solve time service errors caused by uncertainty of network time delay in the prior art.
In order to solve the above problem, the present application provides an error correction method for network time service, including: calculating to obtain local client time by utilizing an NTP (network time protocol) time synchronization algorithm and a server; sending an error correction request to a server, and recording the starting time of a local client, wherein the starting time is obtained by calculating the time of the local client; acquiring server time returned by a server; recording the end time of the local client based on the start time; responding to the time period that the server time does not belong to the starting time and the ending time, and acquiring a time alignment error interval by using the server time; and correcting the local client time by using the upper limit value and the lower limit value of the time error interval.
The method comprises the following steps of calculating the time of a local client by utilizing an NTP time synchronization algorithm and a server, wherein the steps comprise: sending a time synchronization request to a server; acquiring initial server time returned by a server; calculating to obtain the time of the local client by utilizing the initial server time and the time consumed by the local client and the server to and fro network; the step of recording the end time of the local client based on the start time includes: the end time is determined using the round-trip network elapsed time and the start time.
The step of obtaining the time alignment error interval by using the server time in response to the server time not belonging to the time period of the starting time and the ending time comprises the following steps: in response to the server time being slower than the start time, determining a time difference between the start time and the server time as a lower limit value of the time alignment error interval; and acquiring an upper limit value of the time error interval by utilizing the time consumption of the round-trip network.
The step of obtaining the time alignment error interval by using the server time in response to the server time not belonging to the time period of the starting time and the ending time comprises the following steps: in response to the server time being faster than the end time, determining a time difference between the end time and the server time as an upper limit value of the time alignment error interval; and acquiring a lower limit value of a time error interval by utilizing the time consumed by the back-and-forth network.
The step of correcting the local client time by using the upper limit value and the lower limit value of the time error interval comprises the following steps: acquiring an upper limit difference value between local client time and an upper limit value and a lower limit difference value between the local client time and a lower limit value; and correcting the local client time by using the average value of the upper limit difference value and the lower limit difference value.
The step of correcting the local client time by using the average value of the upper limit difference value and the lower limit difference value comprises the following steps: and determining the corrected local client time by using the average value of the upper limit difference and the lower limit difference and the sum of the time consumed by the local client and the server for network back and forth.
Wherein, in response to the server time not belonging to the time period of the start time and the end time, the step of obtaining the time alignment error interval by using the server time further comprises: calculating a time difference value for which the server time is slower than the start time in response to the server time being slower than the start time, or calculating a time difference value for which the server time is faster than the end time in response to the server time being faster than the end time; judging whether the time difference is less than the time consumed by the network back and forth; if not, recalculating according to the NTP time synchronization algorithm to obtain the local client time; if the time difference is smaller than the preset time difference, acquiring a time error interval by using the time difference.
The method for sending the error correction request to the server and recording the starting time of the local client comprises the following steps: sending an error correction request to a server according to a set frequency; and obtaining the starting time by using the set frequency and the local client time.
In order to solve the above problem, the present application further provides an error correction device for network time service, including: the request sending module is used for sending a time synchronization request to the server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving server time returned by the server; the computing module is used for computing to obtain the local client time by utilizing the initial server time and recording the starting time and the ending time of the local client by utilizing the local client time; the judging module is used for responding that the server time does not belong to the time period of the starting time and the ending time; and the correction module is used for correcting the time error interval and correcting the local client time by using the time error interval.
In order to solve the above problem, the present application further provides a terminal, where the terminal includes a processor and a memory coupled to each other, the memory is used for storing program instructions, and the processor is used for executing the program instructions stored in the memory to implement the error correction method of any of the above embodiments.
In order to solve the above problem, the present application further provides a computer-readable storage medium including a processor and a memory, the memory storing computer program instructions, the processor being configured to execute the program instructions to implement the error correction method of any of the above embodiments.
The beneficial effect of this application is: the method comprises the steps of acquiring server time by using NTP, calculating to obtain local client time, sending an error correction request to a server, correcting a time error interval based on the server time, correcting the local client time by using the time error interval, shortening time service errors of the local client time and the server time caused by network delay, and enabling the client time to be more accurate.
Drawings
FIG. 1 is a schematic flow chart illustrating an embodiment of an error correction method for network time service according to the present disclosure;
FIG. 2 is a schematic structural diagram of an embodiment of a client-server pairing process according to the present application;
FIG. 3 is a flowchart illustrating an embodiment of step S11 in FIG. 1;
FIG. 4 is a schematic flow chart illustrating an embodiment of step S12 in FIG. 1;
FIG. 5 is a schematic structural diagram illustrating a first embodiment of an error correction method for asymmetric network time service according to the present application;
FIG. 6 is a schematic structural diagram illustrating a second embodiment of an error correction method for asymmetric network time service according to the present application;
FIG. 7 is a schematic structural diagram illustrating a third embodiment of an error correction method for asymmetric network time service according to the present application;
FIG. 8 is a schematic structural diagram illustrating an embodiment of an error correction apparatus for network time service according to the present application;
FIG. 9 is a schematic structural diagram of an embodiment of a terminal according to the present application;
FIG. 10 is a schematic structural diagram of an embodiment of a computer-readable storage medium according to the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. 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.
Referring to fig. 1, fig. 1 is a schematic flow chart of an embodiment of an error correction method for network time service, as shown in fig. 1, the method includes the following steps:
step S11: and carrying out time synchronization with the server by utilizing an NTP time synchronization algorithm, and calculating to obtain the local client time.
NTP network timing is a network protocol that synchronizes the clocks of two computers with exchange packets.
In this embodiment, the network time service scheme is configured by using network time service between a server and a client as a framework, and the client uses time of the server as a time service source, provided that: the server is used for accurate time source time service. The client and the server determine the master-slave time error through message exchange, describe the time of calibrating the local client, and complete time synchronization.
Referring to fig. 2, fig. 2 is a schematic structural diagram of an embodiment of the present application when a client and a server are synchronized. As shown in fig. 2, the time when the client sends the time-to-time request to the server is t 0; the server receives a time synchronization request sent by the client, and sends the current server time t12 to the client according to the time synchronization request; the time when the client receives the server time t12 sent by the server is t 3. It should be noted that, in this embodiment, the time when the server receives the time tick request sent by the client is t1, the time when the server sends the server to the client according to the time tick request is t2, and the time difference between t1 and t2 is small and can be ignored. When the client and the server perform time alignment, the round-trip network link delay is t3-t0, the time error after the client completes time alignment according to the initial time t12 of the server is Delta t12-t0-sigma/2, and assuming that the round-trip network link is symmetrical in the process from the time alignment request sent by the client to the time alignment request sent by the server to the time alignment request returned by the server, the transmission delays are equal, the time consumption t12-t0 used by the client to send the time alignment request to the server is equal to the time consumption t3-t12 used by the server to return the time alignment request to the client, and at the moment, the time error Delta after the time alignment completed by the client is 0. However, in practical application, due to network instability, the back-and-forth network link is asymmetric, and transmission delay is unequal, so that the client calculates the client local client time through the NTP time-setting algorithm, and the problems of error, inaccurate time-setting and the like exist. The time synchronization precision of the client and the server depends on the symmetry degree of the round-trip network link, and the delay asymmetry value of the round-trip route does not exceed the network delay to the maximum extent, so the maximum time synchronization error of the network delay is +/-sigma/2, and the minimum time synchronization error is 0. The client can adjust the local client time through Delta to complete the time synchronization with the server.
In the present embodiment, the step S11 further includes steps S21 to S23, please refer to fig. 3, where fig. 3 is a flowchart illustrating an embodiment of the step S11 in fig. 1:
step S21: and sending a time synchronization request to the server.
The method specifically comprises the following steps: the client sends a time synchronization request to the server by utilizing the NTP network protocol, and the server sends the initial server time of the server to the client according to the time synchronization request.
Step S22: and acquiring initial server time returned by the server.
The client receives the initial server time sent by the server.
Step S23: and calculating the time of the local client by utilizing the initial server time and the time consumed by the local client and the server to go back and forth.
Specifically, the local client time is obtained by adding the obtained initial server time to one half of the time consumed by the network back and forth.
Specifically, the NTP network time synchronization assumes that the network time consumption of the back-and-forth network link is equal, that is, the time synchronization error corresponding to the NTP time synchronization is half of the network time consumption from the time when the client sends the time synchronization request to the server to the time when the server receives the initial time returned by the server. And if the network consumed time from the time synchronization request sent by the client to the server to the time of the server returned by the server is received is T, the network consumed time error during time synchronization by using the NTP protocol is T/2. And adding time setting error T/2 caused by network time consumption to the initial time of the server to obtain the time of the local client. The method comprises the following specific steps: and if the obtained initial time of the server is ts0, the local client time of the client calculated by utilizing the NTP time synchronization algorithm is ts0+ T/2. If the time consumed by the back-and-forth network of the client and the server is the same as that of the NTP network protocol, the error between the local client time obtained by adopting the NTP network time synchronization and the server time is avoided, and therefore accurate time synchronization is achieved. However, in practical applications, often, due to network instability, network consumed time for the client to send the time synchronization request to the server and network consumed time for the server to send the server time to the client are asymmetric, so that an error exists between the local client time calculated by the client through the NTP time synchronization algorithm and the server time.
In this embodiment, the error correction request is continuously sent to the server, and the local client time is corrected based on the request, so that the local client time gradually approaches the server time, thereby reducing the time synchronization error between the local client time and the server time.
Step S12: and sending an error correction request to the server, and recording the starting time of the local client.
Wherein the start time is calculated from the local client time.
Referring to fig. 4, fig. 4 is a schematic flowchart illustrating an embodiment of step S12 in fig. 1, including:
step S31: and sending an error correction request according to the set frequency by the phase server.
Step S32: and obtaining the starting time by using the set frequency and the local client time.
The method specifically comprises the following steps: if the preset frequency is T ', the start time of the local client is the sum of the time tc of the local client of the client and the preset frequency T ', and the start time of the local client is tc + T '.
And the server receives the error correction request sent by the client and sends the server time to the client according to the error correction request.
Step S13: and obtaining the server time returned by the server.
Step S14: the end time of the local client is recorded based on the start time.
Specifically, the step of recording the end time of the local client based on the start time includes: and recording the network consumed time T from the time when the client sends the error correction request to the server to the time when the server returned by the server is received, and adding the network consumed time T back and forth to the start time of the local client to obtain the end time of the local client.
Step S15: and responding to the server time not belonging to the time period of the starting time and the ending time, and acquiring a time alignment error interval by using the server time.
The method specifically comprises the following steps: in response to the server time being slower than the start time, determining a time difference between the start time and the server time as a lower limit value of the time alignment error interval; and acquiring an upper limit value of a time error interval by utilizing the time consumed by the back-and-forth network. In response to the server time being faster than the end time, determining a time difference between the end time and the server time as an upper limit value of the time alignment error interval; and acquiring a lower limit value of a time error interval by utilizing the time consumed by the back-and-forth network.
In step S11, the maximum time synchronization error and the minimum time synchronization error exist between the local client time and the server time obtained by completing time synchronization using the NTP network protocol, when the server time is slower than the start time of the local client, the maximum time synchronization error between the local client time and the server time is T/2, and when the server time is faster than the end time of the local client, the maximum time synchronization error between the local client time and the server time is-T/2. When the time consumed by the network for the client to send the time synchronization request to the server is equal to the time consumed by the network for the server to send the server time to the client, the client time is synchronized with the server time, that is, the minimum time synchronization error is 0.
In this embodiment, if the response server time is slower than the start time, the local client time of the client is faster than the server time, and the initial time setting error of the local client time is in the range of [0, T/2 ]. If the response server time is faster than the end time, the local client time of the client is slower than the server time, and the initial time setting error of the local client is in the range of [ -T/2, 0 ].
Further, whether the time difference between the local client time and the server time is within the time alignment error interval or not is judged, and if the time difference between the local client time and the server time is not within the time alignment error interval, the local client time is recalculated according to the NTP time alignment algorithm; and if the time difference between the local client time and the server time is within the time alignment error interval, correcting the time alignment error interval by using the time difference between the local client time and the server time.
Step S16: and correcting the local client time by using the upper limit value and the lower limit value of the time error interval.
In one embodiment, step S16 includes: acquiring an upper limit difference value between local client time and an upper limit value and a lower limit difference value between the local client time and a lower limit value; and correcting the local client time by using the average value of the upper limit difference value and the lower limit difference value. Specifically, the corrected local client time is determined by using the average of the upper limit difference and the lower limit difference, and the sum of the round-trip network time consumption of the local client and the server.
Assuming that the obtained time-alignment error interval is [ t1, t2], the step of correcting the local client time by using the upper limit value and the lower limit value of the time-alignment error interval includes: calculating an upper limit difference tc-t1 between the local client time tc and an upper limit value t2, and calculating a lower limit difference tc-t2 between the local client time tc and a lower limit value t1, wherein the correcting the local client time by using the average of the upper limit difference and the lower limit difference comprises: the [ (tc-t1) + (tc-t2) ]/2 was calculated.
The above embodiment is specifically described below using a time notation expression:
specifically, in an embodiment, the time consumed by the client to send the time synchronization request to the server until the server initial time sent by the server is received is T, the server initial time returned by the client to receive the server is T0, and the local client time tc is calculated based on the server initial time and the time synchronization error corresponding to the NTP time synchronization algorithm.
Further, the client sends an error correction request to the server, specifically, the error correction request includes a start time tc0 when the client sends the error correction request. The server returns the current server time ts of the server according to the error correction request. The client receives the server time ts returned by the server and calculates the end time tc1 of the local client based on the start time and the time-alignment error. Specifically, based on the network time T taken by the client to send the error correction request to the server until the server time returned by the server is received, the end time tc1 of the client is calculated to be tc0+ T.
In response to the server time ts not belonging to the local client's time period of the start time tc0 and end time tc1, and further in response to the server time being slower than the local client's start time tc0, or in response to the server time being faster than the local client's end time tc 1.
If the response server time is slower than the start time tc0 of the local client, the time difference that the server time is slower than the start time is calculated as T, and the time error interval is corrected according to the time difference T, specifically, the corrected time error interval is [ T, T/2 ].
If the response server time is faster than the end time tc1 of the client, the time difference of the server time faster than the start time is calculated as T, and the time error interval is corrected according to the time difference, and the corrected time error interval is [ -T/2, -T ].
And correcting the local client time by using the upper limit value and the lower limit value of the time error interval. The method specifically comprises the following steps: if the response time of the server is slower than the start time tc0 of the client, calculating the average value of the sum of the end time tc1 of the current local client and the difference value of the upper limit value and the lower limit value of the time error interval, orThe average value of the sum of the start time tc0 of the current local client and the difference value between the upper limit value and the lower limit value of the time error interval and the sum of the time consumed by the local client and the back-and-forth network of the server are calculated, and the formula is as follows:
Figure BDA0002981197620000091
Figure BDA0002981197620000092
or
Figure BDA0002981197620000093
If the response time of the server is faster than the end time tc1 of the client, calculating the average value of the sum of the end time tc of the current local client and the difference value between the lower limit value and the upper limit value of the time-to-time error interval, or calculating the average value of the sum of the start time tc0 of the current local client and the difference value between the upper limit value and the lower limit value of the time-to-time error interval and the sum of the network time consumed by the local client and the server, and expressing the sum as follows:
Figure BDA0002981197620000094
Figure BDA0002981197620000095
or
Figure BDA0002981197620000096
The beneficial effects of the embodiment are: the method comprises the steps of obtaining server time by using NTP, calculating to obtain local client time, sending an error correction request to a server, correcting a time error interval based on the server time, correcting the local client time by using the time error interval, shortening time service errors of the local client time and the server time in real time by adopting NTP due to network delay, and enabling the client time to be more accurate. Compared with the existing network time service, the method does not need to rely on specific computer hardware equipment, does not need to modify the software framework layer logic of the computer server, can continuously optimize the time service error under the condition of unstable network, ensures that the network time service precision does not strongly depend on the quality of network links, and finally approaches the current network optimal value.
Please refer to fig. 5, wherein fig. 5 is a timing diagram illustrating a first embodiment of an error correction method for asymmetric network time service according to the present application. As shown in fig. 5:
the time consumed by the client to send the time synchronization request to the server and receive the initial time of the server sent by the server is 100 milliseconds, wherein it is assumed that the time consumed by the network used by the client to send the time synchronization request to the server is 90 milliseconds (uplink time consumption), and the time consumed by the network used by the server to send the initial time of the server to the client is 10 milliseconds (downlink time consumption). The local client time calculated based on the initial time of the server and the time setting error corresponding to the NTP time setting algorithm is the initial time of the server plus 50 milliseconds, and if the server and the client start time setting from 0 second, the local client time calculated based on the initial time of the server and the time setting error corresponding to the NTP time setting algorithm by the client is 140 milliseconds. In the NTP time setting process, due to asymmetry between uplink time consumption and downlink time consumption of a network, time of a client after time setting is 40 milliseconds faster than that of a server, wherein the client knows that the maximum error of time setting is ± 50 milliseconds.
The client sends an error correction request to the server at an interval of 10 milliseconds, and the starting time of the local client is recorded as 150 milliseconds. Wherein the error correction request and the time synchronization request both comprise a request for obtaining the server time. As can be seen from the figure, at this time, the uplink consumed time is less than the downlink consumed time, the network consumed time for the client to send the time synchronization error correction request to the server is 20 milliseconds (uplink consumed time), the network consumed time for the server to send the server time to the client is 80 milliseconds (downlink consumed time), the end time of the local client is recorded based on the start time as 250 milliseconds, and the server time sent by the server is received as 130 milliseconds, where the server time is calculated based on the server local client time. Since the uplink time consumption for sending the error correction request is less than the maximum time setting error, the time setting error request reaches the server and the server time is slower than the local client time of the client when the request starts.
Judging that the server time does not belong to the time period of the starting time and the ending time of the local client, further judging that the server time is slower than the starting time of the client, calculating the time difference that the server time is slower than the starting time of the client to be 20 milliseconds, and acquiring the time alignment error interval between the client and the server to be +20 to +50 milliseconds. Wherein, the acquisition of the time error interval comprises: the lower limit value and the upper limit value of the time alignment error interval are obtained, because the lower limit value of the initial time alignment error interval of the NTP time alignment is 0 millisecond, the upper limit value of the initial time alignment error interval of the NTP time alignment is 50 milliseconds, the time difference that the time of the server is slower than the starting time is calculated to be 20 milliseconds, the local client time of the client is at least 20 milliseconds faster than the server time (in practice, the client is 40 milliseconds faster than the server), and then the lower limit value of the time alignment error interval is obtained to be 20 milliseconds. The time-to-time error interval is corrected, and the time-to-time error interval is acquired to be [ +20ms, +50ms ] (the client time is actually 40 milliseconds faster than the server time, and is in the interval).
Correcting the local client time according to the server time and the updated time synchronization error interval, specifically: and calculating the median time of the client local client time in the time alignment error interval, wherein the calculated local client time ((250-20) + (250-50))/2 is 215 milliseconds, and is 5 milliseconds different from the time 210 milliseconds of the end of the server time alignment.
The beneficial effect of this embodiment is: the error correction interval of the client time and the server time is obtained by sending the time synchronization error correction request, and the local client time is corrected according to the error correction interval, so that the error between the corrected client local client time and the server time is smaller than the error between the client time and the server time before correction, the time synchronization error is reduced, and the time synchronization of the client is more accurate.
Please refer to fig. 6, wherein fig. 6 is a schematic structural diagram of a second embodiment of an error correction method for asymmetric network time service according to the present application. As shown in fig. 6:
the time consumption from the time synchronization request sent by the client to the server to the initial time of the server sent by the server is 100 milliseconds, wherein the time consumption of a network used by the client to send the time synchronization request to the server is 10 milliseconds (uplink time consumption), the time consumption of the network used by the server to send the initial time of the server to the client is 90 milliseconds (downlink time consumption), the server and the client are assumed to start timing from 0 second, and the local client time of the client is 60 milliseconds calculated based on the acquired server time and the time synchronization error corresponding to the NTP time synchronization algorithm. The server time after the time synchronization is finished should be 100 milliseconds, and in this embodiment, the local client time of the client after the time synchronization is 40 milliseconds slower than the server time due to asymmetry between uplink time consumption and downlink time consumption of the network. The maximum error of time synchronization between the client and the server is +/-50 milliseconds, and the minimum error of time synchronization is 0 millisecond. When the uplink consumed time and the downlink consumed time are symmetrical, the local client time calculated based on the initial time of the server and the time setting error corresponding to the NTP time setting algorithm is 100 milliseconds, the end time of the server is also 100 milliseconds, and the error is 0 at this time.
The client sends an error correction request to the server at an interval of 10 milliseconds, and records the starting time of the local client as 70 milliseconds. In the process of obtaining the server time included in the error correction request transmission and reception, the network time taken for the client to transmit the error correction request to the server is 80 milliseconds (uplink time taken), and the network time taken for the server to transmit the server time to the client is 20 milliseconds (downlink time taken). The end time of the local client is recorded as 170 milliseconds based on the start time, and the received server time is 190 milliseconds. If the time of the client is accurate, the time of the server acquired by the client is certainly faster than the time of the client for requesting to start and slower than the time of the client for requesting to end.
And judging that the server time does not belong to the time period of the starting time and the ending time of the local client, and the server time is faster than the ending time of the client, which indicates that the client time is slower than the server time after the NTP time setting operation, and the downlink time consumption for sending the error correction request is less than the time setting error. The time difference that the server time is faster than the end time of the client is calculated to be 20 milliseconds, which indicates that the client time is at least 20 milliseconds slower than the server time (actually 40 milliseconds slower), and the time alignment error interval between the client and the server time after acquiring the NTP time is-20 to-50 milliseconds, that is, the client time is 20 milliseconds slower than the server time and is 50 milliseconds different from the server time. And correcting the time setting error interval by using the server time to obtain the corrected time setting error interval of [ -20ms, -50ms ].
The local client time is corrected according to the server time and the updated time synchronization error interval, specifically, an average value of the client local client time in the time synchronization error interval is calculated, and the local client time is obtained as ((170+20) + (170+50))/2 which is 205 milliseconds, and is 5 milliseconds different from the time 210 milliseconds of the end of the server time synchronization.
The beneficial effect of this embodiment is: the error correction interval of the client time and the server time is obtained by sending the time synchronization error correction request, and the local client time is corrected according to the error correction interval, so that the error between the corrected client local client time and the server time is smaller than the error between the client time and the server time before correction, the time synchronization error is reduced, and the time synchronization of the client is more accurate.
In another embodiment, if the acquired server time is not within the time periods of the start time and the end time of the client, and the time difference between the server time and the start time or the time difference between the server time and the end time is greater than the maximum time setting error, it indicates that the server may modify its own time due to synchronization error and other problems. Referring to fig. 7, fig. 7 is a schematic structural diagram illustrating a third embodiment of an error correction method for asymmetric network time service according to the present application. As shown in fig. 7:
the time consumed by the client to send the time synchronization request to the server and receive the initial time of the server sent by the server is 100 milliseconds, wherein the uplink time consumed by the client to send the time synchronization request to the server is 10 milliseconds, the downlink time consumed by the client is 90 milliseconds, the client time after time synchronization is 60 milliseconds, and the server time is 100 milliseconds.
The client sends a time synchronization error correction request to the server at an interval of 10 milliseconds, the uplink time consumption of the time synchronization error correction request sent by the client to the server is 80 milliseconds, the downlink time consumption is 20 milliseconds, the starting time of the client is recorded as 70 milliseconds, and the ending time is recorded as 170 milliseconds. Because the server dials back 40 milliseconds due to self reasons, the acquired server time is 230 milliseconds, the error correction is that the time of the client is at least 60 milliseconds slower than that of the server after the time setting is calculated by the client, and exceeds the maximum time setting error interval of-50 to +50 milliseconds, therefore, the time of the server is judged to be modified after the time setting is finished, and the client triggers the time setting request again to ensure the synchronous adjustment of the time of the client and the time of the server.
Please refer to fig. 8, wherein fig. 8 is a schematic structural diagram of an embodiment of the error correction apparatus for network time service according to the present application. As shown in fig. 8, the error correction apparatus includes: the request sending module 81: the system comprises a time synchronization module, a time synchronization module and a time synchronization module, wherein the time synchronization module is used for sending a time synchronization request to a server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving server time returned by the server. The calculating module 82 is used for calculating the local client time by using the initial server time, and recording the start time and the end time of the local client by using the local client time; specifically, the time of the local client is obtained by calculating the time of the initial server and the time consumed by the local client and the server to make a network round trip, the time of the local client is used for recording the starting time of the error correction request sent by the local client to the server, and the ending time of the server time sent by the server is determined by using the starting time of the local client and the time consumed by the local client and the server to make a network round trip. The judging module 83 is configured to respond that the server time does not belong to the time period of the start time and the end time; if the server time belongs to the time period of the starting time and the ending time, no response is made, namely the client does not correct the local client time. The judging module 83 further includes: the response server time is slower than the start time, or the server time is faster than the end time. A correction module 84, configured to correct the time error interval and correct the local client time by using the time error interval; the method specifically comprises the following steps: in response to that the server time is slower than the start time, the determining module 83 determines the time difference between the start time and the server time as a lower limit value of the time alignment error interval, and obtains an upper limit value of the time alignment error interval by using the time consumed by the round-trip network; the correcting module 84 is further configured to obtain an upper limit difference between the local client time and the upper limit value and a lower limit difference between the local client time and the lower limit value, and correct the local client time by using an average of the upper limit difference and the lower limit difference. If the judging module 83 responds that the server time is faster than the end time, the correcting module 84 determines the time difference between the end time and the server time as an upper limit value of a time alignment error interval, and acquires the lower limit value of the time alignment error interval by utilizing the time consumed by the network back and forth; and acquiring an upper limit difference value between the local client time and an upper limit value and a lower limit difference value between the local client time and a lower limit value, and correcting the local client time by using an average value of the upper limit difference value and the lower limit difference value.
Referring to fig. 9, fig. 9 is a schematic structural diagram of an embodiment of a terminal of the present application, and as shown in fig. 9, the terminal 90 includes a processor 901 and a memory 902, which are coupled to each other, where the processor 901 is configured to execute program instructions stored in the memory 902 to implement steps in any one of the method embodiments or steps correspondingly executed by a client in any one of the method embodiments. The terminal may include a touch screen, a printing component, a communication circuit, etc. according to requirements, in addition to the processor 901 and the memory 902, which is not limited herein.
In particular, the processor 901 is adapted to control itself and the memory 902 to implement the steps in any of the above-described method embodiments. Processor 901 may also be referred to as a CPU (Central Processing Unit). The processor 901 may be an integrated circuit chip having signal processing capabilities. The Processor 901 may also be a general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. In addition, the processor 901 may be commonly implemented by a plurality of integrated circuit chips.
The present application further provides a computer-readable storage medium, as shown in fig. 10, fig. 10 is a schematic structural diagram of an embodiment of the computer-readable storage medium of the present application.
The computer-readable storage medium 100 includes a computer program 1001 stored on the computer-readable storage medium 100, and when the computer program 1001 is executed by the processor, the steps in any of the method embodiments described above or the steps executed by the error correction method for network time service in the method embodiments described above are implemented correspondingly.
In particular, the integrated unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium 100. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a computer-readable storage medium 100 and includes several instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method of the embodiments of the present application. And the aforementioned computer-readable storage medium 100 includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a module or a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some interfaces, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above embodiments are merely examples and are not intended to limit the scope of the present disclosure, and all modifications, equivalents, and flow charts using the contents of the specification and drawings of the present disclosure or those directly or indirectly applied to other related technical fields are intended to be included in the scope of the present disclosure.

Claims (11)

1. An error correction method for network time service is characterized in that the error correction method comprises the following steps:
calculating to obtain local client time by utilizing an NTP (network time protocol) time synchronization algorithm and a server;
sending an error correction request to a server, and recording the starting time of a local client, wherein the starting time is obtained by calculating the time of the local client;
acquiring server time returned by a server; and
recording an end time of the local client based on the start time;
responding to the time period that the server time does not belong to the starting time and the ending time, and acquiring a time alignment error interval by using the server time;
and correcting the local client time by using the upper limit value and the lower limit value of the time alignment error interval.
2. The error correction method of claim 1, wherein said step of calculating a local client time when paired with the server using the NTP time-tick algorithm comprises:
sending a time setting request to the server;
acquiring initial server time returned by the server;
calculating to obtain the local client time by utilizing the initial server time and the time consumed by the local client and the server for network back and forth;
the step of recording the end time of the local client based on the start time includes:
and determining the end time by utilizing the round-trip network elapsed time and the start time.
3. The error correction method of claim 2, wherein the step of obtaining a time alignment error interval using the server time in response to the server time not belonging to the time period of the start time and the end time comprises:
in response to the server time being slower than the start time, determining a time difference between the start time and the server time as a lower limit value of the time alignment error interval;
and acquiring the upper limit value of the time alignment error interval by utilizing the time consumed by the back-and-forth network.
4. The error correction method of claim 2 or 3, wherein the step of obtaining a time alignment error interval using the server time in response to the server time not belonging to a time period of the start time and the end time comprises:
in response to the server time being faster than the end time, determining a time difference between the end time and the server time as an upper limit value of the time alignment error interval;
and acquiring the lower limit value of the time alignment error interval by utilizing the time consumed by the network to and fro.
5. The error correction method of claim 1, wherein the step of correcting the local client time by using the upper limit value and the lower limit value of the time-to-time error interval comprises:
acquiring an upper limit difference value between the local client time and the upper limit value and a lower limit difference value between the local client time and the lower limit value;
and correcting the local client time by using the average value of the upper limit difference value and the lower limit difference value.
6. The error correction method of claim 5, wherein the step of correcting the local client time using the average of the upper bound difference and the lower bound difference comprises:
and determining the corrected local client time by using the average value of the upper limit difference and the lower limit difference and the sum of the time consumed by the local client and the server for network back and forth.
7. The error correction method of claim 3 or 4, wherein the step of obtaining a time alignment error interval using the server time in response to the server time not belonging to a time period of a start time and an end time further comprises:
calculating a time difference value for the server time being slower than the start time in response to the server time being slower than the start time, or calculating a time difference value for the server time being faster than the end time in response to the server time being faster than the end time;
judging whether the time difference is smaller than the time consumed by the back-and-forth network;
if not, recalculating according to the NTP time synchronization algorithm to obtain the local client time;
and if the time difference is smaller than the preset time difference, acquiring the time alignment error interval by using the time difference.
8. The error correction method of claim 1, wherein the step of sending an error correction request to the server and recording a start time of the local client comprises:
sending an error correction request to the server according to a set frequency;
and obtaining the starting time by using the set frequency and the local client time.
9. An error correction device for network time service, the error correction device comprising:
the request sending module is used for sending a time synchronization request to a server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving server time returned by the server;
the computing module is used for computing to obtain local client time by utilizing the initial server time and recording the starting time and the ending time of the local client by utilizing the local client time;
the judging module is used for responding that the server time does not belong to the time period of the starting time and the ending time;
and the correction module is used for correcting the time alignment error interval and correcting the local client time by using the time alignment error interval.
10. A terminal, characterized in that the terminal comprises a processor and a memory coupled to each other, the memory being configured to store program instructions, and the processor being configured to execute the program instructions stored in the memory to implement the error correction method according to any of the preceding claims 1 to 8.
11. A computer-readable storage medium comprising a processor and a memory, the memory storing computer program instructions, the processor being configured to execute the program instructions to implement the error correction method of any of claims 1-8.
CN202110287784.0A 2021-03-17 2021-03-17 Error correction method and related device for network time service Active CN113037418B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110287784.0A CN113037418B (en) 2021-03-17 2021-03-17 Error correction method and related device for network time service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110287784.0A CN113037418B (en) 2021-03-17 2021-03-17 Error correction method and related device for network time service

Publications (2)

Publication Number Publication Date
CN113037418A true CN113037418A (en) 2021-06-25
CN113037418B CN113037418B (en) 2023-06-20

Family

ID=76471776

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110287784.0A Active CN113037418B (en) 2021-03-17 2021-03-17 Error correction method and related device for network time service

Country Status (1)

Country Link
CN (1) CN113037418B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113556200A (en) * 2021-07-30 2021-10-26 平安资产管理有限责任公司 Clock calibration method, and network security protection method and device based on clock synchronization

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007214670A (en) * 2006-02-07 2007-08-23 Seiko Epson Corp Client device and program
US20090276542A1 (en) * 2008-05-02 2009-11-05 Nortel Networks Limited Method and apparatus for time and frequency transfer in communication networks
CN103929293A (en) * 2013-01-15 2014-07-16 电子科技大学 Asymmetrically-delayed time synchronization method and system
CN105187148A (en) * 2015-08-17 2015-12-23 武汉理工大学 ARM-based network clock synchronization system and method
US20180048457A1 (en) * 2015-04-29 2018-02-15 Abb Schweiz Ag Method, system and device for clock synchronization over time-varying and lossy networks
CN107919933A (en) * 2017-11-17 2018-04-17 深圳市泉眼网络科技有限公司 A kind of method, apparatus, mobile terminal and the storage medium of time renewal
CN108075853A (en) * 2017-12-03 2018-05-25 中国直升机设计研究所 A kind of method for synchronizing network time between Helicopter Simulator development system
CN110166159A (en) * 2019-05-24 2019-08-23 南方电网科学研究院有限责任公司 One kind being based on GPRS network clock synchronization, electric energy meter time synchronization method and system
CN110518998A (en) * 2019-07-19 2019-11-29 浪潮思科网络科技有限公司 A kind of method for synchronizing time in asynchronous communication networks
CN111447030A (en) * 2020-03-31 2020-07-24 中国科学院地质与地球物理研究所 Network time service precision control method and system of earthquake collector and terminal equipment
CN111865468A (en) * 2020-07-21 2020-10-30 浪潮云信息技术股份公司 Precise time synchronization method

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007214670A (en) * 2006-02-07 2007-08-23 Seiko Epson Corp Client device and program
US20090276542A1 (en) * 2008-05-02 2009-11-05 Nortel Networks Limited Method and apparatus for time and frequency transfer in communication networks
CN103929293A (en) * 2013-01-15 2014-07-16 电子科技大学 Asymmetrically-delayed time synchronization method and system
US20180048457A1 (en) * 2015-04-29 2018-02-15 Abb Schweiz Ag Method, system and device for clock synchronization over time-varying and lossy networks
CN105187148A (en) * 2015-08-17 2015-12-23 武汉理工大学 ARM-based network clock synchronization system and method
CN107919933A (en) * 2017-11-17 2018-04-17 深圳市泉眼网络科技有限公司 A kind of method, apparatus, mobile terminal and the storage medium of time renewal
CN108075853A (en) * 2017-12-03 2018-05-25 中国直升机设计研究所 A kind of method for synchronizing network time between Helicopter Simulator development system
CN110166159A (en) * 2019-05-24 2019-08-23 南方电网科学研究院有限责任公司 One kind being based on GPRS network clock synchronization, electric energy meter time synchronization method and system
CN110518998A (en) * 2019-07-19 2019-11-29 浪潮思科网络科技有限公司 A kind of method for synchronizing time in asynchronous communication networks
CN111447030A (en) * 2020-03-31 2020-07-24 中国科学院地质与地球物理研究所 Network time service precision control method and system of earthquake collector and terminal equipment
CN111865468A (en) * 2020-07-21 2020-10-30 浪潮云信息技术股份公司 Precise time synchronization method

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113556200A (en) * 2021-07-30 2021-10-26 平安资产管理有限责任公司 Clock calibration method, and network security protection method and device based on clock synchronization

Also Published As

Publication number Publication date
CN113037418B (en) 2023-06-20

Similar Documents

Publication Publication Date Title
WO2017101528A1 (en) Method and device for clock link switching and base station
US11038608B2 (en) Frequency synchronization method and slave clock
CN102244603B (en) Method, equipment and system for transmitting message bearing time
EP3284217A1 (en) Methods, systems, and computer readable media for synchronizing timing among network interface cards (nics) in a network equipment test device
CN109392074B (en) Clock calibration method and device
CN113259038B (en) Time synchronization method, node, device and storage medium
CN101729180A (en) Method and system for synchronizing precision clocks, and precision clock frequency/time synchronizing device
US7630383B2 (en) Synchronization of time stamps of peer devices in a communication node
WO2017063450A1 (en) Timestamp filtering method and apparatus
WO2017054554A1 (en) Clock synchronization method, device, and communication apparatus
US20220007321A1 (en) Network Entities and Methods for a Wireless Network System for Determining Time Information
US11411848B2 (en) Flexible ethernet latency measurement method and related device
US20220248353A1 (en) Synchronization method and device
CN111953442A (en) Quick high-precision time synchronization system
WO2018099375A1 (en) Synchronization method, synchronization device, synchronization apparatus and communication system
CN113037418A (en) Error correction method for network time service and related device
CN101686093A (en) Transmission network clock synchronizing method, equipment and system
CN112787742A (en) Clock synchronization method and device, wireless earphone and readable storage medium
EP3010168B1 (en) Frequency calibration method
WO2020164100A1 (en) Clock synchronization method and device
CN112968748B (en) Software synchronization error compensation method, system, medium, and apparatus
CN102891747B (en) Clock synchronizing method and device in a kind of communication network
CN114157381A (en) Network delay jitter-oriented dynamic delay estimation period adjustment method
CN115865246A (en) Time synchronization device, system and method
WO2015087024A1 (en) Method and devices for synchronization using linear programming

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