[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

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

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

Info

Publication number
CN113037418B
CN113037418B CN202110287784.0A CN202110287784A CN113037418B CN 113037418 B CN113037418 B CN 113037418B CN 202110287784 A CN202110287784 A CN 202110287784A CN 113037418 B CN113037418 B CN 113037418B
Authority
CN
China
Prior art keywords
time
server
local client
client
network
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
Application number
CN202110287784.0A
Other languages
Chinese (zh)
Other versions
CN113037418A (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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)
  • Electric Clocks (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)

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: the NTP time setting algorithm is utilized to time with the server, and the local client time is obtained through calculation; transmitting an error correction request to a server, and recording the starting time of a local client, wherein the starting time is calculated by the time of the local client; obtaining the server time returned by the 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 synchronization error interval by utilizing the server time; and correcting the local client time by using the upper limit value and the lower limit value of the time setting 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 and related device for network time service
Technical Field
The present invention relates to the field of network time application, and in particular, to a method and an apparatus for correcting errors in network time service.
Background
The distributed system composed of computer network system has a great deal of operation to be coordinated, and the accurate time synchronization is one of important foundation to achieve the coordination of operation, but because each network element in the computer system obtains own time mode differently, it is difficult to ensure the time synchronization of the two in the operation process without the active time service/time synchronization strategy.
Some network time service technologies are provided in the development process of computer network technology, and the existing computer network time synchronization technologies include NTP (network time protocol) technology, PTP technology, syncE synchronous Ethernet technology and the like, but the technologies all have the problems of realizing the dependence on specific hardware support and the strong dependence on the stability of the network of time service precision, and cannot meet the requirements of universality and general high precision in practical engineering application.
The existing Ethernet time-setting method mainly comprises NTP and IEEE1588 protocols, the former provides a low-cost network time-setting method, and because the time mark is obtained in the application layer, the time-setting precision is lower, generally about 10ms, and the engineering requirement cannot be met; the latter obtains time mark at the bottom layer of the protocol, uses the communication link of the network to realize clock synchronization, has higher precision and can reach 100ns at most. But both are clocked by means of a packet bi-directional transmission delay by adding a time-clocked packet (time stamp) in the data stream. The method needs to occupy the data transmission bandwidth, can be influenced by the bidirectional transmission load of the network, and can seriously influence the timing precision when the transmission load of the network in any direction is heavier.
Disclosure of Invention
The technical problem that this application mainly solves is to provide a method and device for correcting the error of network time service to solve the time service error that the uncertainty of network time delay leads to in the prior art.
In order to solve the above problems, the present application provides an error correction method for network time service, including: the NTP time setting algorithm is utilized to time with the server, and the local client time is obtained through calculation; transmitting 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; obtaining the server time returned by the 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 setting error interval by utilizing the server time; and correcting the local client time by using the upper limit value and the lower limit value of the time synchronization error interval.
The step of calculating the local client time by utilizing the NTP time synchronization algorithm and the server time synchronization comprises the following steps: sending a time setting request to a server; acquiring initial server time returned by a server; calculating the time of the local client by using the time of the initial server and the time consumed by the network back and forth between the local client and the server; a step of recording an end time of the local client based on the start time, comprising: the end time is determined using the round-trip network time consumption and the start time.
Wherein the step of obtaining the time synchronization error interval by 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 of the time tick error interval; and time consuming to acquire the upper limit value of the time-lapse error interval by using the round-trip network.
Wherein the step of obtaining the time synchronization error interval by 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 faster than the end time, determining a time difference between the end time and the server time as an upper limit of the time synchronization error interval; and the time consumption of the round-trip network is utilized to obtain the lower limit value of the time-setting error interval.
The step of correcting the local client time by using the upper limit value and the lower limit value of the time synchronization error interval comprises the following steps: 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 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 corrected local client time by using the average value of the upper limit difference value and the lower limit difference value and the sum of time consumption of the network of the local client and the network of the server.
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 synchronization error interval by using the server time further comprises: calculating a time difference that 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 that 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 consumption of network restoration; if not, recalculating according to the NTP time setting algorithm to obtain the local client time; if the time difference is smaller than the preset time difference, the time difference interval is acquired by utilizing the time difference.
Wherein, the step of sending an error correction request to the server and recording the start time of the local client comprises: transmitting an error correction request to a server according to a set frequency; the start time is obtained 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 setting request to the server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving the 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 to the time period that the server time does not belong to the starting time and the ending time; the correction module is used for correcting the time synchronization error interval and correcting the local client time by using the time synchronization error interval.
In order to solve the above-mentioned problem, the present application further provides a terminal, where the terminal includes a processor and a memory coupled to each other, the memory is configured to store program instructions, and the processor is configured to execute the program instructions stored in the memory to implement the error correction method of any one of the above-mentioned embodiments.
In order to solve the above-mentioned problems, 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 according to any one of the above-mentioned embodiments.
The beneficial effects of this application are: the NTP is utilized to obtain the server time and calculate the local client time, then an error correction request is sent to the server, the time setting error interval is corrected based on the server time, and the time setting error interval is utilized to correct the local client time, so that the time service error between the local client time and the server time caused by network delay is shortened, and the client time is more accurate.
Drawings
FIG. 1 is a flow chart of an embodiment of an error correction method for network timing according to the present application;
fig. 2 is a schematic structural diagram of an embodiment of the present application of the client and the server;
FIG. 3 is a flowchart illustrating the step S11 of FIG. 1 according to an embodiment;
FIG. 4 is a flowchart illustrating the step S12 of FIG. 1 according to an embodiment;
FIG. 5 is a schematic structural diagram of a first embodiment of an error correction method for asymmetric network timing according to the present application;
FIG. 6 is a schematic structural diagram of a second embodiment of an error correction method for asymmetric network timing according to the present application;
FIG. 7 is a schematic structural diagram of a third embodiment of an error correction method for asymmetric network timing according to the present application;
FIG. 8 is a schematic structural diagram of an embodiment of an error correction device for network timing according to the present application;
FIG. 9 is a schematic structural diagram of an embodiment of a terminal of the present application;
fig. 10 is a schematic structural diagram of an embodiment of a computer-readable storage medium of the present application.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a flow chart of an embodiment of a method for correcting errors in network time service of the present application, as shown in fig. 1, the method includes the following steps:
step S11: and (5) utilizing an NTP time synchronization algorithm to time with the server, and calculating to obtain the local client time.
NTP network timing is a network protocol that synchronizes the clocks of two computers with a switched packet.
In this embodiment, the network time service scheme uses network time service of a server and a client as a framework, and the client uses time of the server as a time service time source, provided that: the server-side is time service with accurate time source. And determining master-slave time errors through message exchange between the client and the server, and describing the time of the short calibration local client to finish time synchronization.
Referring to fig. 2, fig. 2 is a schematic structural diagram of an embodiment of the present application for a client and a server. As shown in fig. 2, the time when the client sends the time synchronization request to the server is t0; the server receives a time setting request sent by the client and sends the current server time t12 to the client according to the time setting request; the time of the client receiving the server time t12 sent by the server is t3. In this embodiment, the time for the server to receive the time synchronization request sent by the client is t1, the server sends the time of the server to the client according to the time setting request to be t2, and the time difference between t1 and t2 is small and can be ignored. When the client performs pairing with the server, the time delay of the back-and-forth network link is sigma=t3-t 0, the time error of the client after the completion of the pairing is delta=t12-t 0-sigma/2 according to the initial time t12 of the server, if the time delay is equal when the client transmits the pairing request to the server to the back-and-forth network link symmetry in the process of receiving the server time returned by the server, the time consumption t12-t0 for the client to transmit the pairing request to the server is equal to the time consumption t3-t12 for the server to return the pairing request to the client, and at the moment, the time error delta=0 after the completion of the pairing by the client. However, in practical application, due to network instability, the network links are asymmetric and the transmission delay is unequal, so that the time of the local client of the client calculated by the NTP time alignment algorithm has errors, inaccurate time alignment and other problems. The accuracy of the time synchronization between the client and the server depends on the symmetry degree of the network link, and the maximum time delay asymmetry value of the round trip route does not exceed the network time delay, so that the maximum time delay error of the network time delay is + -sigma/2, and the minimum time delay error is 0. The client can adjust the local client time through Delta to complete the time synchronization with the server.
In this embodiment, step S11 further includes steps S21 to S23, please refer to fig. 3, and fig. 3 is a schematic flow chart of an implementation of step S11 in fig. 1:
step S21: and sending a time setting request to the server.
The method specifically comprises the following steps: the client sends a time setting request to the server by using the NTP network protocol, and the server sends the initial server time of the server to the client according to the time setting request.
Step S22: the initial server time returned by the server is obtained.
The client receives the initial server time sent by the server.
Step S23: and calculating the time of the local client by using the initial server time and the time consumed by the network back and forth between the local client and the server.
Specifically, the local client time is obtained by adding the acquired initial server time to one half of the time consumed by the network to be traversed.
Specifically, the NTP network pair is assumed to be peer-to-peer in terms of network time consumption of the network link back and forth, i.e., the corresponding pair error of the NTP pair is half of the network time consumption of the initial time taken by the client to send the pair request to the server to receive the server return. If the time spent by the client-side sending the time setting request to the server and the time spent by the server receiving the return of the server is T, the time spent by the network time setting error of the NTP protocol is T/2. And adding the time setting error T/2 caused by time consumption of the network to the initial time of the server to obtain the time of the local client. The method comprises the following specific steps: and adding the time setting error T/2 to the calculated initial time of the server to obtain the local client time of the client, and if the obtained initial time of the server is ts0, calculating the local client time of the client by using an NTP time setting algorithm to obtain the local client time of the client as ts0+T/2. If the time consumption of the network back and forth of the client and the server is the same as the NTP network protocol, the local client time and the server time obtained by adopting the NTP network time synchronization have no error, thereby realizing accurate time synchronization. However, in practical applications, due to instability of the network, network time consumed by the client for sending the time synchronization request to the server and network time consumed by the server for sending the server time to the client are often asymmetric, so that errors exist between local client time and server time calculated by the client by adopting the NTP time synchronization algorithm.
In this embodiment, an 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: an error correction request is sent to the server and the start time of the local client is recorded.
Wherein the start time is calculated by the local client time.
Referring further to fig. 4, fig. 4 is a flow chart illustrating an embodiment of step S12 in fig. 1, including:
step S31: the server transmits an error correction request according to the set frequency.
Step S32: the start time is obtained using the set frequency and the local client time.
The method specifically comprises the following steps: if the preset frequency is T ', the starting time of the local client is the client local client time tc plus the preset frequency T ', and the starting time of the local client is tc+t '.
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 acquiring 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 time consumption T of the network used by the time from the client to the server sending the error correction request to the server receiving the return of the server, and adding the starting time of the local client to the time consumption T of the network to obtain the ending time of the local client.
Step S15: and acquiring the time setting 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.
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 of the time tick error interval; and the upper limit value of the time-setting error interval is obtained by using the time consumption of the round-trip 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 of the time synchronization error interval; and the time consumption of the round-trip network is utilized to obtain the lower limit value of the time-setting error interval.
In step S11, the local client time and the server time obtained by completing the time setting by using the NTP network protocol have a maximum time setting error and a minimum time setting error, when the server time is slower than the start time of the local client, the maximum time setting error of 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 setting error of the local client time and the server time is-T/2. When the time consumption of the network used by the client to send the time setting request to the server is equal to the time consumption of the network used by the server to send the server time to the client, the time of the client is synchronous with the time of the server, namely the minimum time setting 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 synchronization 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, at which time the initial time tick error of the local client is in the [ -T/2,0] range.
Further, judging whether the time difference between the local client time and the server time is in a time synchronization error interval, if the time difference between the local client time and the server time is not in the time synchronization error interval, recalculating the local client time according to an NTP time synchronization algorithm; if the time difference between the local client time and the server time is within the time setting error interval, correcting the time setting 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 synchronization error interval.
In one embodiment, step S16 includes: 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 the average value of the upper limit difference value and the lower limit difference value. Specifically, the corrected local client time is determined using the average of the upper and lower limit values and the sum of the network time consumption of the local client and the server.
Assuming that the obtained time synchronization 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 synchronization error interval includes: calculating an upper limit difference value tc-t1 of the local client time tc and the upper limit value t2, and calculating a lower limit difference value tc-t2 of the local client time tc and the lower limit value t1, and correcting the local client time by using an average value of the upper limit difference value and the lower limit difference value includes: [ (tc-t 1) + (tc-t 2) ]/2 is calculated.
The following describes the above embodiment in detail using a time symbol expression:
specifically, in one embodiment, the time consumed from the time when the client sends the time setting request to the server to the time when the client receives the initial time of the server sent by the server is T, and meanwhile, the time when the client receives the initial time of the server returned by the server is T0, and the local client time tc is obtained by calculating the time setting error corresponding to the time setting error based on the initial time of the server and the NTP time setting algorithm.
Further, the client transmits an error correction request to the server, specifically, the error correction request includes a start time tc0 at which the client transmits the error correction request. The server returns the server current server time ts 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 setting error. Specifically, the end time tc1=tc0+t of the client is calculated based on the network time T taken by the client to send an error correction request to the server to receive the server time returned by the server.
In response to the server time ts not belonging to the period of the start time tc0 and the end time tc1 of the local client, and further in response to the server time being slower than the start time tc0 of the local client, or in response to the server time being faster than the end time tc1 of the local client.
If the server time is slower than the start time tc0 of the local client, a time difference of the server time slower than the start time is calculated as T, and the time difference T is used for correcting the time-setting error interval, specifically, the corrected time-setting error interval is [ T, T/2].
If the server time is faster than the end time tc1 of the client, calculating the time difference of the server time and the start time as T, correcting the time setting error interval according to the time difference, and setting the corrected time setting error interval as [ -T/2, -T ].
And correcting the local client time by using the upper limit value and the lower limit value of the time synchronization error interval. The method specifically comprises the following steps: if the server time is slower than the start time tc0 of the client, calculating an average value of a sum of differences between the end time tc1 of the current local client and the upper and lower limit values of the time tick error interval, or calculating an average value of a sum of differences between the start time tc0 of the current local client and the upper and lower limit values of the time tick error interval and a sum of network time consuming back and forth of the local client and the server, expressed by a formula:
Figure BDA0002981197620000091
Figure BDA0002981197620000092
Or->
Figure BDA0002981197620000093
If the server time is faster than the end time tc1 of the client, calculating an average value of the sum of the differences between the end time tc of the current local client and the lower and upper limits of the time tick error interval, or calculating an average value of the sum of the differences between the start time tc0 of the current local client and the upper and lower limits of the time tick error interval, and the local clientThe sum of the network time consumption of the end and the server is expressed as: />
Figure BDA0002981197620000094
Figure BDA0002981197620000095
Or->
Figure BDA0002981197620000096
The beneficial effects of the embodiment are as follows: the server time is obtained by using NTP, the local client time is obtained by calculation, then an error correction request is sent to the server, the time setting error interval is corrected based on the server time, and the local client time is corrected by using the time setting error interval, so that the time service error between the local client time and the server time caused by network delay and the time setting time of NTP is shortened, and the client time is more accurate. Compared with the existing network time service, the method does not need to rely on specific computer hardware equipment or modify the logic of a software framework layer of a computer server side, and can continuously optimize time service errors under the condition that the network is unstable, so that the network time service accuracy is not strongly dependent on the quality of network links, and the final time service errors are approximate to the current network optimal values.
An example of an error correction method for asymmetric network timing is provided, please refer to fig. 5, fig. 5 is a timing diagram of a first embodiment of an error correction method for asymmetric network timing. As shown in fig. 5:
assuming that the time taken from the client to the server to the initial time of the server to receive the server transmission is 100 ms, the time taken from the client to the server to the initial time of the server is 10 ms (downlink time taken) assuming that the time taken from the client to the server to the network to transmit the time request is 90 ms (uplink time taken). And calculating the local client time based on the server initial time and the time setting error corresponding to the NTP time setting algorithm to obtain the local client time which is the server initial time plus 50 milliseconds, and assuming that the server and the client start time setting from 0 seconds, calculating the local client time based on the server initial time and the time setting error corresponding to the NTP time setting algorithm by the client is 140 milliseconds. In the NTP time setting process, the time of a client after time setting is 40 milliseconds faster than the time of a server due to the asymmetry of the uplink time consumption and the downlink time consumption of the network, wherein the client can know that the maximum time setting error is +/-50 milliseconds.
The client sends an error correction request to the server at 10 ms intervals, recording the start time of the local client as 150 ms. Wherein the error correction request and the time synchronization request both include a request to acquire server time. It can be seen from the graph that, at this time, the uplink time consumption is smaller than the downlink time consumption, the network time consumption for the client to send the time synchronization error correction request to the server is 20ms (uplink time consumption), the network time consumption for the server to send the server time to the client is 80 ms (downlink time consumption), the end time of the local client is recorded to be 250 ms based on the start time, and the server time for receiving the server to send is 130 ms, wherein the server time is calculated based on the local client time of the server. Since the upstream time consuming for sending the error correction request is less than the maximum tick error, the server time when the tick error request arrives at the server will be slower than the local client time of the client at the start of the request.
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, further judging that the server time is slower than the starting time of the client, calculating the time difference of the server time slower than the starting time of the client to be 20 milliseconds, and acquiring the time setting error interval between the client and the server time to be +20 to +50 milliseconds. The obtaining of the time synchronization error interval comprises the following steps: the lower limit value and the upper limit value of the time setting error interval are acquired, and since the lower limit value of the initial time setting error interval of the NTP time setting is 0ms, the upper limit value is 50ms, the time difference of calculating the server time to be slower than the starting time is 20ms, the local client time of the client is at least 20ms faster than the server time (in practice, the client is 40 ms faster than the server), and the lower limit value of the time setting error interval is acquired to be 20 ms. The pair of time error sections is corrected, and a time error section of [ +20ms, +50ms ] (the client time is actually 40 ms faster than the server time, within this section) is obtained.
Correcting the local client time according to the server time and the updated time synchronization error interval, specifically: the median time of the client local client time in the time synchronization error interval is calculated, and the local client time ((250-20) + (250-50))/2=215 ms is calculated to be different from the time 210 ms of the end of the server time synchronization by 5 ms.
The beneficial effects of this embodiment are: the time synchronization error correction request is sent to obtain an error correction interval of the client time and the server time, and the local client time is corrected according to the error correction interval, so that the error of the corrected client local client time and the corrected server time is smaller than the error of the client time and the corrected server time, the time synchronization error is reduced, and the time synchronization of the client is more accurate.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a second embodiment of an error correction method for asymmetric network timing. As shown in fig. 6:
and taking the time spent from the time spent by the client to the time spent by the server sending the time spent by the server to the time spent by the client receiving the initial time spent by the server to be 100 milliseconds, wherein the time spent by the network spent by the client sending the time spent by the server to the time spent by the server is assumed to be 10 milliseconds (uplink time spent), the time spent by the network spent by the server sending the initial time spent by the server to the client is assumed to be 90 milliseconds (downlink time spent), the time spent by the server and the client are assumed to be counted from 0 second, and the local client time of the client is calculated to be 60 milliseconds based on the acquired server time and the time spent corresponding to the NTP time spent algorithm. The server time after the end of the time synchronization should be 100 ms, and in this embodiment, the local client time of the client after the time synchronization is 40 ms slower than the server time due to the asymmetry of the uplink time consumption and the downlink time consumption of the network. The maximum error of the time synchronization between the client and the server is +/-50 milliseconds, and the minimum error of the time synchronization is 0 millisecond. When the uplink time consumption and the downlink time consumption are symmetrical, the local client time obtained by calculation based on the initial time of the server and the corresponding time setting error of the NTP time setting algorithm is 100 milliseconds, the end time of the server is 100 milliseconds, and the error is 0.
The client sends an error correction request to the server at 10 ms intervals, recording the start time of the local client as 70 ms. In the process of obtaining the server time included in the error correction request, the network time consumed by the client to send the error correction request to the server is 80 milliseconds (uplink time), and the network time consumed by the server to send the server time to the client is 20 milliseconds (downlink time). The end time of the local client is 170 ms based on the start time record and the received server time is 190 ms. If the client time is accurate, the server time acquired by the client must be faster than the time when the client request starts and slower than the time when the client request ends.
Judging that the server time does not belong to the time period of the starting time and the ending time of the local client, wherein the server time is faster than the ending time of the client, the client time is slower than the server time after NTP time setting operation, and the downlink time consumption for sending the error correction request is less than the time setting error. Calculating the time difference that the server time is faster than the end time of the client is 20 milliseconds, which means that the client time is at least 20 milliseconds slower than the server time (actually 40 milliseconds slower), and the time setting error interval between the client and the server time after the NTP time setting is acquired is-20 to-50 milliseconds, namely the client time is slower than the server time by 20 milliseconds to 50 milliseconds. The corrected time setting error interval is obtained by correcting the time setting error interval by the server time and is [ -20ms, -50ms ].
Correcting the local client time according to the server time and the updated time synchronization error interval, specifically, calculating the average value of the local client time of the client in the time synchronization error interval to obtain the local client time ((170+20) + (170+50))/2=205 milliseconds, which is different from the 210 milliseconds of the end of the server time synchronization by 5 milliseconds.
The beneficial effects of this embodiment are: the time synchronization error correction request is sent to obtain an error correction interval of the client time and the server time, and the local client time is corrected according to the error correction interval, so that the error of the corrected client local client time and the corrected server time is smaller than the error of the client time and the corrected server time, the time synchronization error is reduced, and the time synchronization of the client is more accurate.
In another embodiment, if the obtained server time is not within the time period 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 time synchronization maximum error, it is indicated that the server may modify its own time due to a synchronization error or the like. Referring to fig. 7, fig. 7 is a schematic structural diagram of a third embodiment of an error correction method for asymmetric network timing according to the present application. As shown in fig. 7:
The time spent from the time when the client sends the time setting request to the server to the time when the initial time when the time setting request sent by the server is received is 100 milliseconds, wherein the time spent by the client for sending the time setting request to the server is assumed to be 10 milliseconds, the time spent by the client for sending the time setting request to the server is 90 milliseconds, the time spent by the client after time setting is 60 milliseconds, and the time spent by the server is 100 milliseconds.
The client sends a time setting error correction request to the server at intervals of 10 milliseconds, the uplink time consumption of the client sending the time setting error correction request to the server is 80 milliseconds, the downlink time consumption is 20 milliseconds, the starting time of the client is recorded to be 70 milliseconds, and the ending time of the client is recorded to be 170 milliseconds. Because the server dials 40 ms backwards for self reasons, the acquired server time is 230 ms, and the client time is at least 60 ms slower than the server after the client calculates the time setting in error correction, and exceeds the time setting maximum error interval of-50 to +50 ms, so that the server time is judged to be modified after the time setting is finished, and the client can trigger the time setting request again to ensure that the client time and the server time are synchronously adjusted.
Referring to fig. 8, fig. 8 is a schematic structural diagram of an embodiment of the error correction device for network timing according to the present application. As shown in fig. 8, the error correction device includes: request transmitting module 81: the method comprises the steps of sending a time setting request to a server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving the server time returned by the server. A calculation module 82, configured to calculate a local client time using the initial server time, and record a start time and an end time of the local client using the local client time; specifically, the initial server time and the time spent by the local client and the network to and fro of the server are used for calculating to obtain the local client time, the starting time of the local client for sending the error correction request to the server is recorded by using the local client time, 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 spent by the local client and the network to and fro of the server. A judging module 83, configured to respond to a period of time when the server time does not belong to the start time and the end time; if the server time is within the time period of the start time and the end time, the client does not respond, i.e. 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 synchronization error interval and correct the local client time by using the time synchronization error interval; the method specifically comprises the following steps: the judging module 83 determines the time difference between the start time and the server time as a lower limit value of the time-lapse error interval and acquires an upper limit value of the time-lapse error interval by using the time-lapse network in response to the server time being slower than the start time; the correction module 84 is further configured to obtain 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 correct the local client time by using an average value of the upper limit difference value and the lower limit difference value. If the judging module 83 responds to the server time being faster than the end time, the correcting module 84 determines the time difference between the end time and the server time as the upper limit value of the time-lapse error interval, and obtains the lower limit value of the time-lapse error interval by using the time-lapse network; and obtaining 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 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 the terminal of the present application, and as shown in fig. 9, the terminal 90 includes a processor 901 and a memory 902 coupled to each other, where the processor 901 is configured to execute program instructions stored in the memory 902 to implement steps in any of the above method embodiments or steps correspondingly executed by a client in any of the above method embodiments. The terminal may include, in addition to the above-described processor 901 and memory 902, a touch screen, a printing component, a communication circuit, etc., as required, without limitation.
In particular, the processor 901 is arranged to control itself and the memory 902 to implement the steps in any of the method embodiments described above. The processor 901 may also be referred to as a CPU (Central Processing Unit ). Processor 901 may be an integrated circuit chip with signal processing capabilities. Processor 901 may also be a general purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a Field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. 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, and 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 comprises a computer program 1001 stored on the computer readable storage medium 100, which computer program 1001, when executed by the above-mentioned processor, implements the steps of any of the above-mentioned method embodiments or the steps of the error correction method of network timing in the above-mentioned method embodiments, which are correspondingly performed.
In particular, the integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium 100. Based on such understanding, the technical solution of the present application, or a part or all or part of the technical solution contributing to the prior art, may be embodied in the form of a software product stored in a computer-readable storage medium 100, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods 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, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In the several embodiments provided in the present application, it should be understood that the disclosed methods and apparatus may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of modules or units is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical, or other forms.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied essentially or in part or all or part of the technical solution contributing to the prior art or in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods of 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, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is only the embodiments of the present application, and not the patent scope of the present application is limited by the foregoing description, but all equivalent structures or equivalent processes using the contents of the present application and the accompanying drawings, or directly or indirectly applied to other related technical fields, which are included in the patent protection scope of the present application.

Claims (8)

1. The error correction method for the network time service is characterized by comprising the following steps of:
the NTP time setting algorithm is utilized to time with the server, and the local client time is obtained through calculation; the step of calculating the local client time by utilizing the NTP time synchronization algorithm and the server time synchronization comprises the following steps: sending a time setting request to the server; acquiring initial server time returned by the server; calculating the time of the local client by using the initial server time and the time consumed by the network back and forth between the local client and the server;
transmitting an error correction request to a server, and recording the starting time of a local client, wherein the starting time is calculated by the time of the local client;
obtaining the server time returned by the server; and
recording the end time of the local client based on the start time; wherein the step of recording the end time of the local client based on the start time includes: determining the end time using the round-trip network time consuming and the start time;
acquiring a time synchronization 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; the method specifically comprises the following steps: determining a time difference value between the starting time and the server time as a lower limit value of the time setting error interval in response to the server time being slower than the starting time, and acquiring an upper limit value of the time setting error interval by using the time consumption of the round-trip network; responding to the server time being faster than the ending time, determining a time difference value between the ending time and the server time as an upper limit value of the time setting error interval, and acquiring a lower limit value of the time setting error interval by using the time consumption of the round-trip network;
And correcting the local client time by using the upper limit value and the lower limit value of the time setting error interval.
2. The error correction method according to claim 1, wherein the step of correcting the local client time using an upper limit value and a lower limit value of the time-lapse error interval includes:
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.
3. The error correction method according to claim 2, wherein the step of correcting the local client time using an average of the upper limit value and the lower limit value includes:
and determining corrected local client time by using the average value of the upper limit difference value and the lower limit difference value and the sum of the network time consumption of the local client and the server.
4. The error correction method of claim 1, wherein the step of obtaining a time-lapse error interval using the server time in response to the server time not belonging to the period of time of the start time and the end time, further comprises:
Calculating a time difference that 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 that 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 value is less than the time consumption of the network to be traversed;
if not, recalculating according to the NTP time setting algorithm to obtain the local client time;
and if the time difference is smaller than the preset time difference, acquiring the time difference interval by utilizing the time difference.
5. The error correction method according to claim 1, wherein the step of transmitting an error correction request to the server and recording a start time of the local client comprises:
transmitting 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.
6. An error correction device for network time service, characterized in that the error correction device comprises:
the request sending module is used for sending a time setting request to a server and receiving initial server time returned by the server, and sending an error correction request to the server and receiving the server time returned by the server;
The calculation module is used for calculating local client time by using the initial server time and recording the starting time and the ending time of the local client by using the local client time; the method specifically comprises the following steps: calculating to obtain local client time by using initial server time and network time consumption of the local client and the server, recording the starting time of the local client for sending an error correction request to the server by using the local client time, and determining the ending time of the server time sent by the server by the local client by using the starting time of the local client and the network time consumption of the local client and the server;
the judging module is used for responding to the time period that the server time does not belong to the starting time and the ending time;
the correction module is used for correcting the time setting error interval and correcting the time of the local client by using the time setting error interval; wherein correcting the time tick error interval comprises: determining a time difference value between the starting time and the server time as a lower limit value of the time setting error interval in response to the server time being slower than the starting time, and acquiring an upper limit value of the time setting error interval by using the time consumption of the round-trip network; and in response to the server time being faster than the end time, determining a time difference value between the end time and the server time as an upper limit value of the time setting error interval, and acquiring a lower limit value of the time setting error interval by using the time consumption of the round-trip network.
7. A terminal comprising a processor and a memory coupled to each other, the memory for storing program instructions, the processor for executing the program instructions stored by the memory to implement the error correction method of any of claims 1-5.
8. A computer readable storage medium comprising a processor and a memory, the memory storing computer program instructions, the processor configured to execute the program instructions to implement the error correction method of any one of claims 1-5.
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 CN113037418A (en) 2021-06-25
CN113037418B true 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)

Families Citing this family (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 (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107919933A (en) * 2017-11-17 2018-04-17 深圳市泉眼网络科技有限公司 A kind of method, apparatus, mobile terminal and the storage medium of time renewal
CN111447030A (en) * 2020-03-31 2020-07-24 中国科学院地质与地球物理研究所 Network time service precision control method and system of earthquake collector and terminal equipment

Family Cites Families (9)

* 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
US8473638B2 (en) * 2008-05-02 2013-06-25 James Aweya Method and apparatus for time and frequency transfer in communication networks
CN103929293B (en) * 2013-01-15 2017-02-22 电子科技大学 Asymmetrically-delayed time synchronization method and system
EP3089386A1 (en) * 2015-04-29 2016-11-02 ABB Technology AG Method, system and device for clock synchronization over time-varying and lossy networks
CN105187148B (en) * 2015-08-17 2017-12-08 武汉理工大学 A kind of network clock synchronization system and method based on ARM
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 南方电网科学研究院有限责任公司 Method and system for timing based on GPRS network and electric energy meter
CN110518998A (en) * 2019-07-19 2019-11-29 浪潮思科网络科技有限公司 A kind of method for synchronizing time in asynchronous communication networks
CN111865468B (en) * 2020-07-21 2022-09-20 浪潮云信息技术股份公司 Precise time synchronization method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107919933A (en) * 2017-11-17 2018-04-17 深圳市泉眼网络科技有限公司 A kind of method, apparatus, mobile terminal and the storage medium of time renewal
CN111447030A (en) * 2020-03-31 2020-07-24 中国科学院地质与地球物理研究所 Network time service precision control method and system of earthquake collector and terminal equipment

Also Published As

Publication number Publication date
CN113037418A (en) 2021-06-25

Similar Documents

Publication Publication Date Title
EP3284217B1 (en) Methods, systems, and computer readable medium for synchronizing timing among network interface cards (nics) in a network equipment test device
EP3491753B1 (en) System and methods for network synchronization
US7916758B2 (en) Method and system for precise-clock synchronization, and device for precise-clock frequency/time synchronization
EP1280024B1 (en) Clock synchronization in a distributed system
CN102546071B (en) Clock synchronization method and system
EP1961186B1 (en) Using travel-time as means for improving the accuracy of simple network time protocol
CN113259038B (en) Time synchronization method, node, device and storage medium
WO2017101528A1 (en) Method and device for clock link switching and base station
US20070147435A1 (en) Removing delay fluctuation in network time synchronization
EP2749968A1 (en) Time control device, time control method, and program
KR20050025582A (en) A system and method for correcting the clock drift and maintaining the synchronization in wireless networks
KR101550552B1 (en) Apparatus for adjusting time synchronization period and method for determinating time synchronization period
CN109392074A (en) Clock correcting method and device
US20220007321A1 (en) Network Entities and Methods for a Wireless Network System for Determining Time Information
CN114157377B (en) Power distribution terminal real-time clock synchronization method, synchronization system and power distribution terminal
EP3001589A1 (en) Time correction method and apparatus for slave clock device
EP3010168B1 (en) Frequency calibration method
JP6834642B2 (en) Time correction method
US6647026B1 (en) Frame phase synchronous system and a method thereof
CN113037418B (en) Error correction method and related device for network time service
US7630383B2 (en) Synchronization of time stamps of peer devices in a communication node
US20220083095A1 (en) Time synchronization method, service board, and network device
CN112867132B (en) Multi-link time delay jitter optimization method and device based on PTP
CN102647243B (en) Method, website and the system of inserting under a kind of message
JP7435281B2 (en) Network device detection method, communication control method, time synchronization method

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