Time synchronization method, device and system
By receiving time synchronization instructions in the client, calculating the initial time offset information, obtaining historical synchronization time-consuming information, and correcting the time offset information, the time jump problem caused by poor client performance is solved, and the accuracy and accuracy of time synchronization are achieved. Continuity.
Patent Information
- Application Number
- CN202411130303.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-10-15
Smart Images

Figure CN118784138A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a time synchronization method, a time synchronization device and system, a computing device, a computer-readable storage medium, and a computer program product. Background Art
[0002] In the development of computer network technology, many operations need to be coordinated. If you want to achieve coordinated operations, you need to have an accurate time synchronization foundation. Network Time Protocol (NTP) is an application layer protocol in the TCP / IP protocol suite, which is used to synchronize the clocks between the client and the server and provide high-precision time correction.
[0003] Current NTP implementations focus on providing accurate time synchronization by calculating the round-trip delay and time deviation between the client and the server to calibrate the local clock. The working principle of the NTP protocol involves exchanging timestamps between the client and the server and calculating the precise time difference through a specific algorithm. However, in actual applications, when the client executes the time setting command, it will be delayed due to insufficient processing speed caused by differences in client performance, resulting in inconsistent fast and slow jumps in the time display, making it impossible to accurately and stably synchronize the time. Summary of the invention
[0004] In view of this, the embodiment of the present application provides a time synchronization method. The present application also relates to a time synchronization device and system, a computing device, a computer-readable storage medium and a computer program product to solve the above problems existing in the prior art.
[0005] According to a first aspect of an embodiment of the present application, a time synchronization method is provided, which is applied to a client and includes:
[0006] receiving a time synchronization instruction, and calculating initial time offset information between the server and the server based on the time synchronization instruction;
[0007] Acquire a historical synchronization time consumption information set, and determine target synchronization time consumption information based on the historical synchronization time consumption information set;
[0008] Determine target time offset information based on the initial time offset information and the target synchronization time consuming information;
[0009] A current client time of the client is updated based on the target time offset information.
[0010] According to a second aspect of an embodiment of the present application, a time synchronization system is provided, including a client and a server; wherein:
[0011] The client is configured to send a time synchronization message to the server based on a time synchronization instruction;
[0012] The server is configured to send a synchronization response message to the client in response to the time synchronization message;
[0013] The client is further configured to calculate the initial time offset information between the client and the server based on the time synchronization message and the synchronization response message; obtain a set of historical synchronization time information, and determine the target synchronization time information based on the set of historical synchronization time information; determine the target time offset information based on the initial time offset information and the target synchronization time information; and update the current client time of the client based on the target time offset information.
[0014] According to a third aspect of an embodiment of the present application, a time synchronization device is provided, which is applied to a client and includes:
[0015] A receiving module, configured to receive a time synchronization instruction, and calculate initial time offset information between the server and the receiving device based on the time synchronization instruction;
[0016] A determination module is configured to obtain a set of historical synchronization time consumption information, and determine target synchronization time consumption information based on the set of historical synchronization time consumption information;
[0017] A calculation module, configured to determine target time offset information based on the initial time offset information and the target synchronization time consuming information;
[0018] A synchronization module is configured to update a current client time of the client based on the target time offset information.
[0019] According to a fourth aspect of an embodiment of the present application, a computing device is provided, including:
[0020] Memory and processor;
[0021] The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the steps of the above-mentioned time synchronization method are implemented.
[0022] According to a fifth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program / instruction, and the computer program / instruction implements the steps of the above-mentioned time synchronization method when executed by a processor.
[0023] According to a sixth aspect of an embodiment of the present application, a computer program product is provided, comprising a computer program / instruction, which implements the steps of the above-mentioned time synchronization method when executed by a processor.
[0024] The time synchronization method provided in the present application is applied to a client, including receiving a time synchronization instruction, and calculating the initial time offset information between the client and the server based on the time synchronization instruction; obtaining a set of historical synchronization time information, and determining the target synchronization time information based on the set of historical synchronization time information; determining the target time offset information based on the initial time offset information and the target synchronization time information; and updating the current client time of the client based on the target time offset information.
[0025] The method provided in an embodiment of the present application, in addition to calculating the time offset information between the client and the server, also takes into account the poor performance of the client, the delay in executing the time synchronization setting command, and the client time jump, so as to count the time consumption information of the client in the process of executing the time synchronization operation, and correct the time offset information between the client and the server according to the time consumption information, and synchronize the client time according to the final corrected result, which can effectively reduce the time error, prevent the occurrence of time jumps, and ensure the accuracy and continuity of time synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 is a flow chart of a time synchronization method provided by an embodiment of the present application;
[0027] Figure 2 is a schematic diagram of a time synchronization method provided by an embodiment of the present application;
[0028] Figure 3 It is a structural diagram of a time synchronization device provided by an embodiment of the present application;
[0029] Figure 4 It is a structural diagram of a time synchronization system provided by an embodiment of the present application;
[0030] Figure 5 It is a structural block diagram of a computing device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0031] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0032] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0033] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0034] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards in the relevant regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0035] First, the terms involved in one or more embodiments of the present application are explained.
[0036] Network Time Protocol: (NTP) is an application layer protocol in the TCP / IP protocol suite that is used to synchronize the clocks between clients and servers and provide high-precision time correction. The NTP algorithm measures the time difference between the client and the server by sending and receiving timestamps, calculates the round-trip time, i.e., the network delay, and determines the time deviation between the two clocks. The client then uses this information to fine-tune its own clock to keep in sync with the server, and this process is repeated to adapt to changes in network conditions.
[0037] Current NTP implementations focus on providing accurate time synchronization by calculating the round-trip delay and time offset between the client and the server to calibrate the client's local clock. The working principle of the NTP protocol involves exchanging timestamps between the client and the server and calculating the precise time difference through a specific algorithm. The NTP protocol calibrates the client's clock by calculating the round-trip delay (Delay) and time offset information (Offset). When facing a low-performance client, the execution of the time setting command may be delayed due to insufficient processing speed, resulting in inconsistent fast and slow jumps in the time display.
[0038] Based on this, a time synchronization method is provided in the present application. The present application also relates to a time synchronization device and system, a computing device, a computer-readable storage medium and a computer program product, which are described in detail one by one in the following embodiments.
[0039] Figure 1 A flowchart of a time synchronization method provided according to an embodiment of the present application is shown. The time synchronization method is applied to a client and specifically includes the following steps:
[0040] Step 102: Receive a time synchronization instruction, and calculate initial time offset information between the server and the server based on the time synchronization instruction.
[0041] In the application scenario of time synchronization, two terminals are involved, one is a client (also called a calibrated terminal) and the other is a server (also called a master clock). The method provided in this application is applied to a client to adjust the time of the client to synchronize with the server.
[0042] The time synchronization instruction can be understood as an instruction for controlling the client to perform time synchronization. The time synchronization instruction can be automatically triggered based on a certain trigger condition, for example, triggered once every fixed time period, or triggered once when performing certain specific tasks. It can also be based on instructions sent by users or other clients. In the method provided in this application, there is no limitation on the method for obtaining the time synchronization instruction, which is subject to actual application.
[0043] The initial time offset information can be understood as the time offset between the client and the server calculated by the time synchronization algorithm.
[0044] The time synchronization method provided by the present application is that the client performs time interactive synchronization with the server based on the received time synchronization instruction, and calculates the initial time offset information between the client and the server. Specifically, in a specific implementation method provided by the present application, the initial time offset information between the client and the server is calculated based on the time synchronization instruction, including:
[0045] Sending a time synchronization message to a server in response to the time synchronization instruction, and recording a first timestamp of the time synchronization message;
[0046] Receive a synchronization response message returned by the server in response to the time synchronization message, and record a fourth timestamp of receiving the synchronization response message, wherein the synchronization response message records a second timestamp of the server receiving the time synchronization message and a third timestamp of sending the synchronization response message;
[0047] Initial time offset information between the client and the server is calculated according to the first timestamp, the second timestamp, the third timestamp and the fourth timestamp.
[0048] In the specific implementation manner provided by the present application, the initial time offset information between the client and the server is calculated based on the time synchronization instruction and is obtained by NTP (Network Time Protocol) algorithm. NTP is a protocol for synchronizing device clocks on a computer network. Its main purpose is to ensure that each device in the network can use the same time standard to coordinate various network activities. The core function of NTP is to enable network devices to obtain highly accurate and consistent time information to ensure the synchronization of various network operations.
[0049] The architecture of NTP uses a master-slave architecture, where one or more NTP servers serve as master clock sources and other devices serve as slave clock sources. The master server is usually connected to a high-precision clock source, such as an atomic clock, to provide accurate time information. Clock hierarchy involves forming a hierarchy in the network, where devices at each level provide time information to devices in the upper level through synchronous operation. This hierarchy helps ensure that devices throughout the network receive accurate time information.
[0050] In actual applications, the client sends an NTP message (time synchronization message) to the server. The time synchronization message carries a first timestamp T1 when the client sends the time synchronization message.
[0051] When the time synchronization message arrives at the server, a second timestamp T2 indicating when the server receives the time synchronization message will be added to the time synchronization message.
[0052] The server will give a corresponding response based on the time synchronization message, that is, send a synchronization response message based on the time synchronization message, and record the third timestamp T3 of the server sending the synchronization response message. The first timestamp T1, the second timestamp T2 and the third timestamp T3 are written into the synchronization response message.
[0053] The client receives the synchronization response message, and records a fourth timestamp T4 of receiving the synchronization response message.
[0054] At this point, the first timestamp T1, the second timestamp T2, the third timestamp T3 and the fourth timestamp T4 are obtained in the client. The initial time offset information (Offset) of the client relative to the server can be further calculated based on these four timestamps. Specifically, refer to the following formula 1, and the initial time offset information is calculated based on the following formula 1.
[0055] Offset = ((T2-T1)+(T3-T4)) / 2 Formula 1
[0056] As shown in the above formula 1, where Offset represents the initial time offset information of the client relative to the server, T1 is the first timestamp, T2 is the second timestamp, T3 is the third timestamp, and T4 is the fourth timestamp. Based on the above formula 1, the initial time offset information of the client relative to the server can be calculated.
[0057] Step 104: Acquire a set of historical synchronization time consumption information, and determine target synchronization time consumption information based on the set of historical synchronization time consumption information.
[0058] After the above steps are completed, the initial time offset information corresponding to the current time synchronization instruction can be calculated. However, in actual applications, different clients may experience delays in the process of executing time synchronization operations due to low performance and insufficient processing speed, resulting in incoherent fast and slow jumps in the time display.
[0059] To solve this problem, the method provided in this application proposes to further calibrate the initial time offset information by determining the target synchronization time information through the historical synchronization time information set. The target synchronization time information can be understood as the general time information for determining the client to perform the time synchronization operation.
[0060] The historical synchronization time information set records the synchronization time information corresponding to the previous time synchronization instructions. For example, before this time synchronization instruction, there were 10 time synchronization instructions, and each time synchronization instruction will calculate a corresponding synchronization time information, and the synchronization time information corresponding to each time synchronization will be saved in the historical synchronization time information set corresponding to the time synchronization instruction.
[0061] For example, taking the time synchronization instruction triggered once every 1 second as an example, the time synchronization instruction can be marked with the trigger time as an identifier, and each time synchronization instruction will record the synchronization time information corresponding to the time synchronization. The synchronization time information corresponding to multiple time synchronization instructions is recorded in the historical synchronization time information set.
[0062] The synchronization time-consuming information may be understood as the time-consuming information for updating the current client time of the client based on the time offset information at the client.
[0063] In practical applications, the historical synchronization time-consuming information set can be stored in the client or in other terminals outside the client. For ease of calculation, it is preferably stored in the client. The historical synchronization time-consuming information set can be stored in the form of a data table or in the form of a data group. In the method provided in this application, the storage form of the historical synchronization time-consuming information set is not limited.
[0064] In a specific implementation provided by the present application, determining the target synchronization time-consuming information based on the historical synchronization time-consuming information set includes S1042-S1044:
[0065] S1042: Determine at least one reference historical synchronization time consumption information in the historical synchronization time consumption information set.
[0066] Among them, the reference historical synchronization timing information can be understood as the historical synchronization timing information used to determine the target synchronization timing information. In actual applications, as time goes by, the number of historical synchronization timing information in the historical synchronization timing information set may be large. If too much historical synchronization timing information is used for calculation, it will cause a waste of client computing resources. Therefore, historical reference historical synchronization timing information can be selected from the historical synchronization timing information set for subsequent determination of the target synchronization timing information.
[0067] In practical applications, there are many ways to determine the reference historical synchronization time consumption information. Determining at least one reference historical synchronization time consumption information in the historical synchronization time consumption information set includes:
[0068] Determine the time interval for synchronization time filtering;
[0069] At least one reference historical synchronization time consumption information is determined in the historical synchronization time consumption information set based on the synchronization time consumption screening time interval.
[0070] Among them, the synchronization time consumption filtering time interval can be understood as the time interval used to determine the reference historical synchronization time consumption information. In actual applications, the synchronization time consumption filtering time interval can be a preset time interval past the current time point. For example, the past 30 minutes is the synchronization time consumption filtering time interval, then the historical synchronization time consumption information on the client within the past 30 minutes can be selected as the reference historical synchronization time consumption information.
[0071] In actual applications, the performance of the client may also be related to the load of each operation cycle. For example, the client has a higher load between 8:00 and 11:00 a.m. during the day, and the synchronization time information is longer; the client has a higher load between 2:00 and 5:00 p.m., and the synchronization time information is longer. Taking the time point of receiving the time synchronization instruction as 9:00 a.m. as an example, the historical synchronization time information between 8:30 a.m. and 9:30 a.m. every day in the past week or month can be selected as the reference historical synchronization time information.
[0072] In the method provided in the present application, there is no limitation on the specific manner of determining the reference historical synchronization time-consuming information, which shall be subject to actual application.
[0073] S1044. Determine target synchronization time consumption information according to each reference historical synchronization time consumption information.
[0074] After at least one reference historical synchronization time consumption information is determined, a target synchronization time consumption information may be further determined according to each reference historical synchronization time consumption information. The target synchronization time consumption information may be understood as representative information of each reference historical synchronization time consumption information.
[0075] Specifically, the target synchronization time consumption information is determined according to each reference historical synchronization time consumption information, including:
[0076] Determine the target synchronization time information according to the median of each reference historical synchronization time information; or
[0077] Determine the target synchronization time information according to the average value of each reference historical synchronization time information; or
[0078] The target synchronization time consumption information is determined according to the extreme values of each reference historical synchronization time consumption information.
[0079] There are many ways to refer to each historical synchronization time information. For example, each reference historical synchronization time information can be sorted from large to small, and the median is selected as the target synchronization time information in the sorting result. Furthermore, if the reference historical synchronization time information is an odd number, the median of the sorting result is selected as the target synchronization time information. If the reference historical synchronization time information is an even number, the middle two digits of the sorting result are selected and the average is taken as the target synchronization time information.
[0080] In practical applications, the target synchronization time information can also be calculated based on the average value of each reference historical synchronization time information. The target synchronization time information can also be determined based on the extreme value of each reference historical synchronization time information, which can be understood as the maximum or minimum value of each reference historical synchronization time information.
[0081] In the method provided in the present application, there are many ways to determine the target synchronization time consumption information. Preferably, the target synchronization time consumption information is determined using the median of each reference historical synchronization time consumption information.
[0082] Furthermore, the method of determining the target synchronization time-consuming information based on each reference historical synchronization time-consuming information can also be determined based on the method of determining the reference historical synchronization time-consuming information. That is, if the synchronization time-consuming screening time interval is a preset time length before the current moment, the target synchronization time-consuming information can be determined using the median of each reference historical synchronization time-consuming information; if the synchronization time-consuming screening time interval is a time period corresponding to the current moment within the preset number of days in the past, the target synchronization time-consuming information can be determined based on the average value of each reference historical synchronization time-consuming information.
[0083] Step 106: Determine target time offset information based on the initial time offset information and the target synchronization time consuming information.
[0084] After the target synchronization time consumption information is determined, the initial time offset information can be further revised according to the target synchronization time consumption information, so as to calculate and obtain the target time offset information, so that the initial time offset information is more accurate.
[0085] In the method provided in the present application, the initial time offset information and the target synchronization time information can be added together to calculate the target time offset information. See the following formula 2:
[0086] FinalOffset= Offset+△T Formula 2
[0087] Among them, FinalOffset is the target time offset information, Offset is the initial time offset information, and △T is the target synchronization time information. Through the above formula 2, the target time offset information between the client and the server can be calculated.
[0088] Step 108: Update the current client time of the client based on the target time offset information.
[0089] After the target time offset information is calculated, the calculated target time offset information is applied to the client's system time through the corresponding system instruction, and the current client time of the client is updated, thereby realizing the function of accurately calibrating the time.
[0090] In a specific implementation provided by the present application, updating the current client time of the client based on the target time offset information includes:
[0091] Obtaining an initial current client time of the client;
[0092] determining a current client time of the client based on the initial current client time and the target time offset information;
[0093] The initial current client time is updated according to the current client time.
[0094] In actual applications, the current client time of the client is updated based on the target time offset information. The initial current client time of the client is first obtained. The initial current client time can be understood as the time when the client has not yet been updated with the target time offset information.
[0095] When the initial current client time is obtained, the current client time of the client can be obtained by adding the initial current client time and the target time offset information. The current client time can be understood as the time updated based on the target time offset information.
[0096] Finally, the client time is updated based on the current client time, thereby achieving accurate calibration of the client time.
[0097] In another specific embodiment provided in the present application, the method further comprises:
[0098] Record the current synchronization time information corresponding to the time synchronization instruction;
[0099] The current synchronization time consumption information is added to the historical synchronization time consumption information set.
[0100] In the implementation mode provided by the present application, after the current client time of the client is updated based on the time synchronization instruction, in order to further improve the accuracy of time synchronization calibration, the current synchronization time information corresponding to the time synchronization instruction can be further recorded. The current synchronization time information can be understood as the time taken to complete time synchronization during this time synchronization process.
[0101] After the current synchronization time consumption information is determined, the current synchronization time consumption information is added to the historical synchronization time consumption information set, so as to facilitate the calculation of subsequent target time offset information when time synchronization is performed later.
[0102] Specifically, the current synchronization time information corresponding to the time synchronization instruction is recorded, including:
[0103] Recording a fifth timestamp of a current client time of updating the client;
[0104] The current synchronization time consumption information corresponding to the time synchronization instruction is calculated according to the fifth timestamp and the fourth timestamp.
[0105] In this embodiment, after the current client time of the client is updated according to the target time offset information, the fifth timestamp after the update is completed is recorded. The fifth timestamp can be understood as the timestamp when the client completes updating the current client time of the client based on the target time offset information.
[0106] After determining the fifth timestamp, based on the fifth timestamp and the process of calculating the initial time offset information, the fourth timestamp of the synchronization response message returned by the server is calculated to obtain the current synchronization time consumption information corresponding to the time synchronization instruction.
[0107] By adding the current synchronization time-consuming information to the historical synchronization time-consuming information set, it can further help the client to better process data in the subsequent processing process.
[0108] The time synchronization method provided in an embodiment of the present application is applied to a client, including receiving a time synchronization instruction, and calculating the initial time offset information between the client and the server based on the time synchronization instruction; obtaining a set of historical synchronization time information, and determining the target synchronization time information based on the set of historical synchronization time information; determining the target time offset information based on the initial time offset information and the target synchronization time information; and updating the current client time of the client based on the target time offset information.
[0109] Through the method provided in the embodiment of the present application, in addition to calculating the time offset information between the client and the server, it also takes into account the poor performance of the client, the delay in executing the time synchronization setting command, and the client time jump, so as to count the time consumption information of the client in the process of executing the time synchronization operation, and correct the time offset information between the client and the server according to the time consumption information, and synchronize the client time according to the final corrected result, which can effectively reduce the time error, prevent the occurrence of time jump, and ensure the accuracy and continuity of time synchronization.
[0110] The method provided by the present application ensures the accuracy of time synchronization between the client and the server. It also optimizes the time-consuming problem that may exist when the client executes the system time setting command. By accurately recording and analyzing the time consumption of each execution of the system time setting command, the target synchronization time consumption information is calculated using a statistical method, and the target synchronization time consumption information is combined with the initial time offset information to obtain the comprehensive target time offset information. It can effectively improve the accuracy of time synchronization and prevent the time jump phenomenon that occurs during the continuous synchronization process.
[0111] The following combination Figure 2 , the time synchronization method is further described. Figure 2 A schematic diagram of a time synchronization method provided by an embodiment of the present application is shown.
[0112] like Figure 2 As shown, the time synchronization method is applied to the client. The client receives a time synchronization instruction and sends a time synchronization message to the server based on the time synchronization execution, and adds the first timestamp T1 of the client to the time synchronization message.
[0113] The server receives the time synchronization message sent by the client, and records the second timestamp T2 of the server receiving the message in the time synchronization message. In response to the time synchronization message, the server sends a synchronization response message to the client, adds the first timestamp and the second timestamp to the synchronization response message, and also adds the third timestamp T3 of the server sending the synchronization response message to the synchronization response message. It should be noted that the second timestamp T2 and the third timestamp T3 are both server timestamps of the server.
[0114] After receiving the synchronization response message sent by the server, the client will record the fourth timestamp T4 when the client receives the message. So far, the client has collected the initial time offset information Offset used to calculate the client compared to the server.
[0115] Get the historical synchronization time information set saved to the client, and select the reference historical synchronization time information within the past 30 minutes from the historical synchronization time information.
[0116] The reference historical synchronization time information is sorted from large to small, and the median is selected as the target synchronization time information △T according to the final sorting result.
[0117] The target time offset information FinalOffset is obtained by calculating according to the above formula 2 based on the initial time offset information Offset and the target synchronization time consuming information ΔT.
[0118] The initial current client time of the client is obtained, and the initial current client time is updated according to the target time offset information FinalOffset, the current client time of the client is obtained, and the clock of the client is set based on the current client time.
[0119] Record the completion timestamp (i.e., the fifth timestamp T5) of setting the client's clock according to the current client time, and calculate the current synchronization time information corresponding to the current time synchronization instruction by using the fifth timestamp T4 and the fourth timestamp T4. Add the current synchronization time information to the historical synchronization time information set for reference in subsequent time synchronization.
[0120] Through the method provided in the embodiment of the present application, in addition to calculating the time offset information between the client and the server, it also takes into account the poor performance of the client, the delay in executing the time synchronization setting command, and the client time jump, so as to count the time consumption information of the client in the process of executing the time synchronization operation, and correct the time offset information between the client and the server according to the time consumption information, and synchronize the client time according to the final corrected result, which can effectively reduce the time error, prevent the occurrence of time jump, and ensure the accuracy and continuity of time synchronization.
[0121] Corresponding to the above method embodiment, the present application also provides a time synchronization device embodiment, Figure 3 FIG. 1 shows a schematic diagram of the structure of a time synchronization device provided by an embodiment of the present application. Figure 3 As shown, the device is applied to a client and includes:
[0122] The receiving module 302 is configured to receive a time synchronization instruction and calculate the initial time offset information between the server and the receiving module based on the time synchronization instruction;
[0123] The determination module 304 is configured to obtain a set of historical synchronization time consumption information, and determine target synchronization time consumption information based on the set of historical synchronization time consumption information;
[0124] A calculation module 306 is configured to determine target time offset information based on the initial time offset information and the target synchronization time consuming information;
[0125] The synchronization module 308 is configured to update the current client time of the client based on the target time offset information.
[0126] Optionally, the determining module 304 is further configured to:
[0127] Determine at least one reference historical synchronization time consuming information in the historical synchronization time consuming information set;
[0128] The target synchronization time consumption information is determined according to each reference historical synchronization time consumption information.
[0129] Optionally, the determining module 304 is further configured to:
[0130] Determine the time interval for synchronization time filtering;
[0131] At least one reference historical synchronization time consumption information is determined in the historical synchronization time consumption information set based on the synchronization time consumption screening time interval.
[0132] Optionally, the determining module 304 is further configured to:
[0133] Determine the target synchronization time information according to the median of each reference historical synchronization time information; or
[0134] Determine the target synchronization time information according to the average value of each reference historical synchronization time information; or
[0135] The target synchronization time consumption information is determined according to the extreme values of each reference historical synchronization time consumption information.
[0136] Optionally, the synchronization module 308 is further configured to:
[0137] Obtaining an initial current client time of the client;
[0138] determining a current client time of the client based on the initial current client time and the target time offset information;
[0139] The initial current client time is updated according to the current client time.
[0140] Optionally, the receiving module 302 is further configured to:
[0141] Sending a time synchronization message to a server in response to the time synchronization instruction, and recording a first timestamp of the time synchronization message;
[0142] Receive a synchronization response message returned by the server in response to the time synchronization message, and record a fourth timestamp of receiving the synchronization response message, wherein the synchronization response message records a second timestamp of the server receiving the time synchronization message and a third timestamp of sending the synchronization response message;
[0143] Initial time offset information between the client and the server is calculated according to the first timestamp, the second timestamp, the third timestamp and the fourth timestamp.
[0144] Optionally, the device further includes a current time consumption determination module configured to:
[0145] Record the current synchronization time information corresponding to the time synchronization instruction;
[0146] The current synchronization time consumption information is added to the historical synchronization time consumption information set.
[0147] Optionally, the current time consumption determination module is further configured to:
[0148] Recording a fifth timestamp of a current client time of updating the client;
[0149] The current synchronization time consumption information corresponding to the time synchronization instruction is calculated according to the fifth timestamp and the fourth timestamp.
[0150] Through the device provided in the embodiment of the present application, in addition to calculating the time offset information between the client and the server, it also takes into account the poor performance of the client, the delay in executing the time synchronization setting command, and the client time jump, so as to count the time consumption information of the client in the process of executing the time synchronization operation, and correct the time offset information between the client and the server through the time consumption information, and synchronize the client time according to the final corrected result, which can effectively reduce the time error, prevent the occurrence of time jump, and ensure the accuracy and continuity of time synchronization.
[0151] The above is a schematic scheme of a time synchronization device of this embodiment. It should be noted that the technical scheme of the time synchronization device and the technical scheme of the above time synchronization method belong to the same concept, and the details not described in detail in the technical scheme of the time synchronization device can be referred to the description of the technical scheme of the above time synchronization method.
[0152] Figure 4 A schematic diagram of the structure of a time synchronization system provided by an embodiment of the present application is shown. Figure 4 As shown, the time synchronization system includes a client 402 and a server 404 .
[0153] The client 402 is configured to send a time synchronization message to the server 404 based on the time synchronization instruction;
[0154] The server 404 is configured to send a synchronization response message to the client 402 in response to the time synchronization message;
[0155] The client 402 is further configured to calculate the initial time offset information between the client 402 and the server 404 based on the time synchronization message and the synchronization response message; obtain a set of historical synchronization timing information, and determine the target synchronization timing information based on the set of historical synchronization timing information; determine the target time offset information based on the initial time offset information and the target synchronization timing information; and update the current client time of the client 402 based on the target time offset information.
[0156] The time synchronization system provided by the embodiment of the present application, in addition to calculating the time offset information between the client and the server, also takes into account the poor performance of the client, the delay in executing the time synchronization setting command, and the client's time jump, so as to count the time consumed by the client in the process of executing the time synchronization operation, and correct the time offset information between the client and the server through the time consumed information, and synchronize the client time according to the final corrected result, which can effectively reduce the time error, prevent the occurrence of time jumps, and ensure the accuracy and continuity of time synchronization.
[0157] The time synchronization system provided by the present application ensures the accuracy of time synchronization between the client and the server. It also optimizes the time-consuming problem that may exist when the client executes the system time setting command. By accurately recording and analyzing the time consumed for each execution of the system time setting command, the target synchronization time-consuming information is calculated using a statistical method, and the target synchronization time-consuming information is combined with the initial time offset information to obtain the comprehensive target time offset information. It can effectively improve the accuracy of time synchronization and prevent the time jump phenomenon that occurs during the continuous synchronization process.
[0158] Figure 5 The block diagram of a computing device 500 provided according to an embodiment of the present application is shown. The components of the computing device 500 include but are not limited to a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and the database 550 is used to store data.
[0159] The computing device 500 also includes an access device 540 that enables the computing device 500 to communicate via one or more networks 560. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0160] In one embodiment of the present application, the above components of the computing device 500 and Figure 5 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 5 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0161] The computing device 500 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 500 may also be a mobile or stationary server.
[0162] The processor 520 is used to execute the following computer program / instruction, which implements the steps of the above-mentioned time synchronization method when executed by the processor.
[0163] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above time synchronization method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above time synchronization method.
[0164] An embodiment of the present specification further provides a computer-readable storage medium storing a computer program / instruction, which implements the steps of the above-mentioned time synchronization method when executed by a processor.
[0165] The above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the above time synchronization method belong to the same concept, and the details not described in detail in the technical solution of the storage medium can be referred to the description of the technical solution of the above time synchronization method.
[0166] An embodiment of the present specification further provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned time synchronization method when executed by a processor.
[0167] The above is a schematic solution of a computer program product of this embodiment. It should be noted that the technical solution of the computer program product and the technical solution of the above time synchronization method belong to the same concept, and the details not described in detail in the technical solution of the computer program product can be referred to the description of the technical solution of the above time synchronization method.
[0168] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0169] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0170] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0171] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0172] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A time synchronization method, characterized in that: Applied to the client, including: receiving a time synchronization instruction, and calculating initial time offset information between the server and the server based on the time synchronization instruction; Acquire a set of historical synchronization time consumption information, and determine target synchronization time consumption information based on the set of historical synchronization time consumption information; Determine target time offset information based on the initial time offset information and the target synchronization time consuming information; A current client time of the client is updated based on the target time offset information.
2. The method according to claim 1, characterized in that Determining target synchronization time consumption information based on the historical synchronization time consumption information set includes: Determine at least one reference historical synchronization time consuming information in the historical synchronization time consuming information set; The target synchronization time consumption information is determined according to each reference historical synchronization time consumption information.
3. The method according to claim 2, characterized in that Determining at least one reference historical synchronization time consuming information in the historical synchronization time consuming information set includes: Determine the time interval for synchronization time filtering; At least one reference historical synchronization time consumption information is determined in the historical synchronization time consumption information set based on the synchronization time consumption screening time interval.
4. The method according to claim 2, characterized in that Determine the target synchronization time information based on each reference history synchronization time information, including: Determine the target synchronization time information according to the median of each reference historical synchronization time information; or Determine the target synchronization time information according to the average value of each reference historical synchronization time information; or The target synchronization time consumption information is determined according to the extreme values of each reference historical synchronization time consumption information.
5. The method according to claim 1, characterized in that Updating the current client time of the client based on the target time offset information includes: Obtaining an initial current client time of the client; determining a current client time of the client based on the initial current client time and the target time offset information; The initial current client time is updated according to the current client time.
6. The method according to claim 1, characterized in that Calculating initial time offset information between the server and the time synchronization instruction includes: Sending a time synchronization message to a server in response to the time synchronization instruction, and recording a first timestamp of the time synchronization message; Receive a synchronization response message returned by the server in response to the time synchronization message, and record a fourth timestamp of receiving the synchronization response message, wherein the synchronization response message records a second timestamp of the server receiving the time synchronization message and a third timestamp of sending the synchronization response message; Initial time offset information between the client and the server is calculated according to the first timestamp, the second timestamp, the third timestamp and the fourth timestamp.
7. The method according to claim 6, characterized in that The method further comprises: Record the current synchronization time information corresponding to the time synchronization instruction; The current synchronization time consumption information is added to the historical synchronization time consumption information set.
8. The method according to claim 7, characterized in that Record the current synchronization time information corresponding to the time synchronization instruction, including: recording a fifth timestamp of a current client time of updating the client; The current synchronization time consumption information corresponding to the time synchronization instruction is calculated according to the fifth timestamp and the fourth timestamp.
9. A time synchronization system, characterized in that: Includes client and server; among them, The client is configured to send a time synchronization message to the server based on a time synchronization instruction; The server is configured to send a synchronization response message to the client in response to the time synchronization message; The client is further configured to calculate the initial time offset information between the client and the server based on the time synchronization message and the synchronization response message; obtain a set of historical synchronization time information, and determine the target synchronization time information based on the set of historical synchronization time information; determine the target time offset information based on the initial time offset information and the target synchronization time information; and update the current client time of the client based on the target time offset information.
10. A time synchronization device, characterized in that: Applied to the client, including: A receiving module, configured to receive a time synchronization instruction, and calculate initial time offset information between the server and the receiving device based on the time synchronization instruction; A determination module is configured to obtain a set of historical synchronization time consumption information, and determine target synchronization time consumption information based on the set of historical synchronization time consumption information; A calculation module, configured to determine target time offset information based on the initial time offset information and the target synchronization time consuming information; A synchronization module is configured to update a current client time of the client based on the target time offset information.
11. A computing device, characterized in that: include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer program / instructions are executed by the processor, the steps of the method according to any one of claims 1 to 8 are implemented.
12. A computer-readable storage medium storing a computer program / instruction, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
13. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
