Synchronization method and client
View Patent ↗In a synchronization method applied to a client, synchronization information between the client and a server is periodically acquired; a preset number of sample data is selected from the synchronization information; time T c required by a CPU to process the sample data is recorded; a time offset prediction value and a frequency offset prediction value at time T n are predicted by means of substituting the sample data into a preset formula; and a current frequency and time of the client is restored according to the time offset prediction value, the frequency offset prediction value and the time T c when a synchronization source is lost.
1 . A synchronization method, applied to a client, the method comprising:
periodically acquiring synchronization information between the client and a server;
selecting a preset number of sample data from the synchronization information;
recording time T c required by a CPU to process the sample data;
predicting a time offset prediction value and a frequency offset prediction value at time T n by means of substituting the sample data into a preset formula; and
restoring a current frequency and time of the client according to the time offset prediction value, the frequency offset prediction value and the time T c when a synchronization source is lost;
wherein predicting a time offset prediction value and a frequency offset prediction value at time T n by means of substituting the sample data into a preset formula comprises:
performing a first weighted average calculation on the sample data according to a formula S n =a*y n +(1−a)*S n-1 to obtain the time offset prediction value and the frequency offset prediction value at the time T n ; and
performing a second weighted average calculation according to a formula S n ′=a*S n +(1−a)*S n-1 ′ on the time offset prediction value and the frequency offset prediction value obtained by the first weighted average calculation, and regarding values obtained by the second weighted average calculation as a final time offset prediction value and a final frequency offset prediction value at the time T n ,
wherein, when the preset formula is calculated for the time offset prediction value, S 0 is an average value of time offset values in n sample data, S n is the time offset prediction value at the time T n obtained by the first weighted average calculation, in nanoseconds, a is a weighting coefficient value, which is a constant, y n is a time offset value in the sample data at the time T n , S n ′ is the time offset prediction value at the time T n obtained by the second weighted average calculation, in nanoseconds; and when the preset formula is calculated for the frequency offset prediction value, S0 is an average value of frequency offset values in n sample data, S n is the frequency offset prediction value at the time T n obtained by the first weighted average calculation, a is the weighting coefficient value, which is a constant, y n is a frequency offset value in the sample data at the time T n , S n ′ is the frequency offset prediction value at the time T n obtained by the second weighted average calculation, in nanoseconds.
2 . The synchronization method according to claim 1 , wherein the method further comprising:
calculating a speed of current frequency changes of the client by applying a linear regression algorithm according to the sample data.
3 . The synchronization method according to claim 2 , wherein the method further comprising:
selecting a size of the weighting coefficient value a according to the speed of the current frequency changes.
4 . The synchronization method according to claim 3 , wherein the client comprises a timer, and recording time T c required by the CPU to process the sample data comprises:
recording the time T c required by the CPU to process the sample data by means of the timer.
5 . The synchronization method according to claim 4 , wherein the method further comprising:
when the client does not receive synchronization information from the server, determining the synchronization source is lost.
6 . The synchronization method according to claim 4 , wherein selecting the preset number of sample data from the synchronization information comprises:
obtaining load information of a CPU of the client, and determining a load level of the CPU according to the load information; and
selecting a corresponding amount of sample data according to the load level, wherein different levels correspond to different amounts of sample data.
7 . A client, which includes a memory, a processor, and a synchronization program stored in the memory and operable on the processor, wherein the synchronization program is executed by the processor to implement the following functions:
periodically acquiring synchronization information between the client and a server;
selecting a preset number of sample data from the synchronization information;
recording time T c required by a CPU to process the sample data;
predicting a time offset prediction value and a frequency offset prediction value at time T n by means of substituting the sample data into a preset formula; and
restoring a current frequency and time of the client according to the time offset prediction value, the frequency offset prediction value and the time T c when a synchronization source is lost;
when predicting a time offset prediction value and a frequency offset prediction value at time T n by means of substituting the sample data into a preset formula, the synchronization program is further executed by the processor to implement the following functions:
performing a first weighted average calculation on the sample data according to a formula S n =a*y n +(1−a)*S n-1 to obtain the time offset prediction value and the frequency offset prediction value at the time T n ; and
performing a second weighted average calculation according to a formula S n ′=a*S n +(1−a)*S n-1 ′ on the time offset prediction value and the frequency offset prediction value obtained by the first weighted average calculation, and regarding values obtained by the second weighted average calculation as a final time offset prediction value and a final frequency offset prediction value at the time T n ,
wherein, when the preset formula is calculated for the time offset prediction value, S0 is an average value of time offset values in n sample data, S n is the time offset prediction value at the time T n obtained by the first weighted average calculation, in nanoseconds, a is a weighting coefficient value, which is a constant, y n is a time offset value in the sample data at the time T n , S n ′ is the time offset prediction value at the time T n obtained by the second weighted average calculation, in nanoseconds; and when the preset formula is calculated for the frequency offset prediction value, S 0 is an average value of frequency offset values in n sample data, S n is the frequency offset prediction value at the time T n obtained by the first weighted average calculation, a is the weighting coefficient value, which is a constant, y n is a frequency offset value in the sample data at the time T n , S n ′ is the frequency offset prediction value at the time T n obtained by the second weighted average calculation, in nanoseconds.
8 . The client according to claim 7 , wherein the synchronization program is further executed by the processor to implement the following functions:
calculating a speed of current frequency changes of the client by applying a linear regression algorithm according to the sample data.
9 . The client according to claim 8 , wherein the synchronization program is further executed by the processor to implement the following functions:
selecting a size of the weighting coefficient value a according to the speed of the current frequency changes.
10 . The client according to claim 9 , wherein the client further comprises a timer, and when recording time T c required by the CPU to process the sample data, the synchronization program is further executed by the processor to implement the following functions:
recording the time T c required by the CPU to process the sample data by means of the timer.
11 . The client according to claim 10 , wherein the synchronization program is further executed by the processor to implement the following functions:
when the client does not receive synchronization information from the server, determining the synchronization source is lost.
12 . The client according to claim 10 , wherein when selecting the preset number of sample data from the synchronization information, the synchronization program is further executed by the processor to implement the following functions:
obtaining load information of a CPU of the client, and determining a load level of the CPU according to the load information; and
selecting a corresponding amount of sample data according to the load level, wherein different levels correspond to different amounts of sample data.