CN118694464A - Time synchronization method, device and system - Google Patents
Time synchronization method, device and system Download PDFInfo
- Publication number
- CN118694464A CN118694464A CN202411162825.3A CN202411162825A CN118694464A CN 118694464 A CN118694464 A CN 118694464A CN 202411162825 A CN202411162825 A CN 202411162825A CN 118694464 A CN118694464 A CN 118694464A
- Authority
- CN
- China
- Prior art keywords
- time
- time offset
- network delay
- offset information
- interval
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 82
- 230000002159 abnormal effect Effects 0.000 claims abstract description 45
- 230000004044 response Effects 0.000 claims description 38
- 238000004590 computer program Methods 0.000 claims description 24
- 230000001934 delay Effects 0.000 claims description 10
- 230000001360 synchronised effect Effects 0.000 claims description 8
- 238000012163 sequencing technique Methods 0.000 claims 2
- 238000001914 filtration Methods 0.000 abstract 1
- 238000010586 diagram Methods 0.000 description 9
- 230000001174 ascending effect Effects 0.000 description 8
- 238000004422 calculation algorithm Methods 0.000 description 6
- 230000009471 action Effects 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 3
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 3
- 238000012544 monitoring process Methods 0.000 description 3
- 230000001960 triggered effect Effects 0.000 description 3
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 2
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 2
- 238000012937 correction Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000007405 data analysis Methods 0.000 description 1
- 230000003247 decreasing effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000002708 enhancing effect Effects 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000012216 screening Methods 0.000 description 1
- 239000004984 smart glass Substances 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0644—External master-clock
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0658—Clock or time synchronisation among packet nodes
- H04J3/0661—Clock or time synchronisation among packet nodes using timestamps
- H04J3/0667—Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0682—Clock 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)
- Synchronisation In Digital Transmission Systems (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
本申请提供时间同步方法、装置及系统,其中所述时间同步方法应用于客户端,包括:接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;根据所述历史时间偏移信息确定参考时间偏移区间;在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。通过本申请提供的方法,通过筛选异常的时间偏移信息,可以降低因网络波动造成的较大时间异常带来的时间跳动问题,有效增强了系统时间的连贯性和稳定性。
The present application provides a time synchronization method, device and system, wherein the time synchronization method is applied to a client, including: receiving a time synchronization instruction, and calculating the time offset information between the client and the server based on the time synchronization instruction; obtaining historical time offset information when the time offset information is determined to be abnormal information; determining a reference time offset interval based on the historical time offset information; and updating the current client time of the client based on the time offset information when the time offset information satisfies the reference time offset interval. Through the method provided by the present application, by filtering abnormal time offset information, the time jump problem caused by large time anomalies caused by network fluctuations can be reduced, and the consistency and stability of the system time can be effectively enhanced.
Description
技术领域Technical Field
本申请涉及计算机技术领域,特别涉及时间同步方法。本申请同时涉及时间同步装置及系统,一种计算设备,一种计算机可读存储介质以及计算机程序产品。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
在计算机网络技术的发展过程中,有很多操作需要协调一致,如果要做到操作协调一致,就需要有精确的时间同步基础。网络时间协议Network Time Protocol(NTP)是TCP/IP协议族里的一个应用层协议,用来使得客户端和服务器之间进行时钟同步,提供高精度的时间校正。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.
NTP算法通过发送和接收时间戳,在客户端和服务器间测量时间差,计算出往返旅行的网络延迟,及两个时钟之间的时间偏差。之后客户端利用网络延迟和时间差调整本地的时钟,保持与服务器的同步。在实际应用中,有可能会出现网络波动,当网络发生波动的情况下,会遭遇时间偏差获取不精确的问题,进而在微调时钟时影响同步的准确度,导致客户端时间显示发生跳跃,从而使得时间无法精确稳定同步。The NTP algorithm measures the time difference between the client and the server by sending and receiving timestamps, calculating the round-trip network delay and the time deviation between the two clocks. The client then uses the network delay and time difference to adjust the local clock to keep it synchronized with the server. In actual applications, network fluctuations may occur. When the network fluctuates, the time deviation acquisition may be inaccurate, which in turn affects the accuracy of synchronization when fine-tuning the clock, causing the client time display to jump, making it impossible to accurately and stably synchronize the time.
发明内容Summary of the invention
有鉴于此,本申请实施例提供了时间同步方法。本申请同时涉及时间同步装置及系统,一种计算设备,一种计算机可读存储介质以及计算机程序产品,以解决现有技术中存在的上述问题。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.
根据本申请实施例的第一方面,提供了一种时间同步方法,应用于客户端,包括: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:
接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;Receiving a time synchronization instruction, and calculating time offset information between the server and the server based on the time synchronization instruction;
在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;In the case where it is determined that the time offset information is abnormal information, obtaining historical time offset information;
根据所述历史时间偏移信息确定参考时间偏移区间;Determine a reference time offset interval according to the historical time offset information;
在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。In a case where the time offset information satisfies the reference time offset interval, the current client time of the client is updated based on the time offset information.
根据本申请实施例的第二方面,提供了一种时间同步系统,包括客户端和服务器,其中,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:
所述客户端,被配置为基于时间同步指令向所述服务器发送时间同步报文;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 time offset information between the client and the server based on the time synchronization message and the synchronization response message; when it is determined that the time offset information is abnormal information, obtain historical time offset information; determine a reference time offset interval based on the historical time offset information; and when the time offset information satisfies the reference time offset interval, update the current client time of the client based on the time offset information.
根据本申请实施例的第三方面,提供了一种时间同步装置,应用于客户端,包括: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:
接收模块,被配置为接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;A receiving module, configured to receive a time synchronization instruction, and calculate time offset information between the server and the receiving device based on the time synchronization instruction;
获取模块,被配置为在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;an acquisition module, configured to acquire historical time offset information when determining that the time offset information is abnormal information;
确定模块,被配置为根据所述历史时间偏移信息确定参考时间偏移区间;A determination module, configured to determine a reference time offset interval according to the historical time offset information;
更新模块,被配置为在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。An updating module is configured to update the current client time of the client based on the time offset information when the time offset information satisfies the reference time offset interval.
根据本申请实施例的第四方面,提供了一种计算设备,包括:According to a fourth aspect of an embodiment of the present application, a computing device is provided, including:
存储器和处理器;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 programs/instructions are executed by the processor, the steps of the above-mentioned time synchronization method are implemented.
根据本申请实施例的第五方面,提供了一种计算机可读存储介质,其存储有计算机程序/指令,该计算机程序/指令被处理器执行时实现上述时间同步方法的步骤。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 when the computer program/instruction is executed by a processor, the steps of the above-mentioned time synchronization method are implemented.
根据本申请实施例的第六方面,提供了一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现上述时间同步方法的步骤。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.
本申请提供的时间同步方法,应用于客户端,包括接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;根据所述历史时间偏移信息确定参考时间偏移区间;在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。The time synchronization method provided in the present application is applied to a client, including receiving a time synchronization instruction, and calculating the time offset information between the client and the server based on the time synchronization instruction; when it is determined that the time offset information is abnormal information, obtaining historical time offset information; determining a reference time offset interval based on the historical time offset information; and when the time offset information satisfies the reference time offset interval, updating the current client time of the client based on the time offset information.
通过本申请实施例提供的时间同步方法,在进行时间同步时,会根据时间偏移信息来判断当前的网络条件是否正常,在时间偏移信息为异常信息的情况下,再进一步判断时间偏移信息的异常波动是否满足时间偏移区间,在时间偏移信息的异常波动满足时间偏移区间的情况下,进行时间同步,通过筛选异常的时间偏移信息,可以降低因网络波动造成的较大时间异常带来的时间跳动问题,有效增强了系统时间的连贯性和稳定性。Through the time synchronization method provided in the embodiment of the present application, when performing time synchronization, it is determined whether the current network conditions are normal based on the time offset information. When the time offset information is abnormal information, it is further determined whether the abnormal fluctuation of the time offset information satisfies the time offset interval. When the abnormal fluctuation of the time offset information satisfies the time offset interval, time synchronization is performed. By screening the abnormal time offset information, the time jump problem caused by large time anomalies caused by network fluctuations can be reduced, thereby effectively enhancing the consistency and stability of the system time.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1是本申请一实施例提供的一种时间同步方法的流程图;FIG1 is a flow chart of a time synchronization method provided by an embodiment of the present application;
图2是本申请一实施例提供的一种时间同步方法的示意图;FIG2 is a schematic diagram of a time synchronization method provided by an embodiment of the present application;
图3是本申请一实施例提供的应用于轨道交通综合监控系统的时间同步方法的流程示意图;3 is a schematic flow chart of a time synchronization method applied to a rail transit integrated monitoring system provided in an embodiment of the present application;
图4是本申请一实施例提供的一种时间同步装置的结构示意图;FIG4 is a schematic diagram of the structure of a time synchronization device provided by an embodiment of the present application;
图5是本申请一实施例提供的一种时间同步系统的结构示意图;FIG5 is a schematic diagram of the structure of a time synchronization system provided by an embodiment of the present application;
图6是本申请一实施例提供的一种计算设备的结构框图。FIG6 is a structural block diagram of a computing device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
在下面的描述中阐述了很多具体细节以便于充分理解本申请。但是本申请能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本申请内涵的情况下做类似推广,因此本申请不受下面公开的具体实施的限制。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. Therefore, the present application is not limited to the specific implementation disclosed below.
在本申请一个或多个实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本申请一个或多个实施例。在本申请一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本申请一个或多个实施例中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。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.
应当理解,尽管在本申请一个或多个实施例中可能采用术语第一、第二等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本申请一个或多个实施例范围的情况下,第一也可以被称为第二,类似地,第二也可以被称为第一。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。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".
需要说明的是,本申请所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据,并且相关数据的收集、使用和处理需要遵守相关地区的相关法律法规和标准,并提供有相应的操作入口,供用户选择授权或者拒绝。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.
首先,对本申请一个或多个实施例涉及的名词术语进行解释。First, the terms involved in one or more embodiments of the present application are explained.
网络时间协议:(Network Time Protocol,NTP)是TCP/IP协议族里面的一个应用层协议,用来使客户端和服务器之间进行时钟同步,提供高精准度的时间校正。NTP算法通过发送和接收时间戳,在客户端和服务器间测量时间差,计算出往返旅行的时间,即网络延迟,并确定两个时钟之间的时间偏差。然后,客户端利用这些信息微调自己的时钟,以与服务器保持同步,这个过程会不断重复,以适应网络条件的变化。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.
目前的NTP实现方案主要关注于提供精确的时间同步功能,通过UDP通讯计算客户端与服务器之间的往返延迟和时间偏差来校准本地时钟。NTP协议的工作原理涉及到在客户端和服务器之间交换时间戳,并通过特定的算法计算出精确的时间差,NTP协议通过计算往返延迟和时间偏差来校对客户端的时钟。在面对网络条件不理想的场景时,由于网络延迟导致时间现实出现不连贯的快慢跳动。The current NTP implementation mainly focuses on providing accurate time synchronization, and calibrates the local clock by calculating the round-trip delay and time deviation between the client and the server through UDP communication. 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 and time deviation. When faced with scenarios with unsatisfactory network conditions, the actual time will show inconsistent speed jumps due to network delays.
基于此,在本申请中,提供了时间同步方法,本申请同时涉及时间同步装置及系统,一种计算设备,一种计算机可读存储介质以及计算机程序产品,在下面的实施例中逐一进行详细说明。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.
图1示出了根据本申请一实施例提供的一种时间同步方法的流程图,该时间同步方法应用于客户端,具体包括以下步骤:FIG1 shows a flow chart of a time synchronization method provided according to an embodiment of the present application. The time synchronization method is applied to a client and specifically includes the following steps:
步骤102:接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息。Step 102: Receive a time synchronization instruction, and calculate time offset information between the server and the server based on the time synchronization instruction.
其中,在时间同步的应用场景中,涉及到两个终端,一个是客户端(也被成为被校准端),一个是服务器(也被称为母钟)。本申请提供的方法,应用于客户端,用于调整客户端的时间与服务器同步。In the application scenario of time synchronization, two terminals are involved, one is the client (also called the calibrated terminal) and the other is the server (also called the master clock). The method provided in this application is applied to the client to adjust the time of the client to synchronize with the server.
时间同步指令可以理解为用于控制客户端执行时间同步的指令,该时间同步指令可以是基于某个触发条件自动触发的,例如,每隔固定时间周期触发一次,或者在执行某些特定任务时触发一次。也可以是基于用户或其他客户端发送的指令。在本申请提供的方法中,对时间同步指令的获取方式不做限定,以实际应用为准。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.
时间偏移信息可以理解为通过时间同步算法,计算出来客户端与服务器之间的时间偏移量。本申请提供的时间同步方法,客户端基于接收到的时间同步指令,与服务器进行时间交互同步,计算与服务器之间的时间偏移信息,具体的,基于所述时间同步指令计算与服务器之间的时间偏移信息,包括:The time offset information can be understood as the time offset between the client and the server calculated by the time synchronization algorithm. The time synchronization method provided by the present application, based on the received time synchronization instruction, the client performs time interactive synchronization with the server and calculates the time offset information between the client and the server. Specifically, the time offset information between the client and the server is calculated based on the time synchronization instruction, including:
响应于所述时间同步指令向服务器发送时间同步报文,并记录所述时间同步报文的第一时间戳;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;
根据所述第一时间戳、所述第二时间戳、所述第三时间戳和所述第四时间戳计算所述客户端与所述服务器之间的当前网络延迟和当前时间偏差。The current network delay and the current time deviation between the client and the server are calculated according to the first timestamp, the second timestamp, the third timestamp and the fourth timestamp.
本申请提供的具体实施方式中,基于时间同步指令计算客户端与服务器之间的初始时间偏移信息是通过NTP(Network Time Protocol,网络时间协议)算法计算获得。NTP是一种在计算机网络上同步设备时钟的协议。它的主要目的是确保网络中的各个设备都能够使用相同的时间标准,从而协调各种网络活动。NTP的核心功能是使网络设备能获得高度准确和一致的时间信息,以确保各种网络操作的同步性。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.
NTP的体系结构采用了主从架构,其中有一个或多个NTP服务器作为主时钟源,而其他设备则作为从时钟源。主服务器通常连接到高精度的时钟源,例如原子钟,以提供准确的时间信息。时钟层次结构涉及到在网络中形成一个层次结构,其中,每个层次的设备都通过同步操作向上一层次的设备提供时间信息,这种层次结构有助于确保整个网络中的设备都能够接收到准确的时间信息。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.
在实际应用中,由客户端发送一个NTP报文(时间同步报文)给服务器,在该时间同步报文中携带有客户端发送该时间同步报文的第一时间戳T1。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.
当该时间同步报文抵达到服务器后,在服务器中会在该时间同步报文中添加服务器接收到该时间同步报文的第二时间戳T2。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.
服务器会基于该时间同步报文给出相应的响应,即基于该时间同步报文发送同步响应报文,同时记录服务器发送该同步响应报文的第三时间戳T3。将第一时间戳T1、第二时间戳T2和第三时间戳T3写入到同步响应报文中。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.
客户端接收到该同步响应报文,并记录接收到该同步响应报文的第四时间戳T4。The client receives the synchronization response message, and records a fourth timestamp T4 of receiving the synchronization response message.
至此,在客户端中获取到了第一时间戳T1、第二时间戳T2、第三时间戳T3和第四时间戳T4。即可根据这四个时间戳来进一步计算客户端相对于服务器的当前网络延迟(Delay)和当前时间偏差(Offset)。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, and the current network delay (Delay) and the current time offset (Offset) of the client relative to the server can be further calculated based on these four timestamps.
具体的,参见下述公式1和下述公式2,基于该下述公式1计算当前网络延迟,基于下属公式2计算当前时间偏差。Specifically, referring to the following formula 1 and the following formula 2, the current network delay is calculated based on the following formula 1, and the current time deviation is calculated based on the following formula 2.
Delay = (T4 - T1) - (T3 - T2)公式1Delay = (T4 - T1) - (T3 - T2)Formula 1
Offset = ((T2-T1) + (T3-T4)) /2公式2Offset = ((T2-T1) + (T3-T4)) /2Formula 2
其中,Delay代表客户端相对于服务器的当前网络延迟,Offset代表客户端相对于服务器的当前时间偏差,T1为第一时间戳,T2为第二时间戳,T3为第三时间戳,T4为第四时间戳。当前网络延迟和当前时间偏差可以看做是时间同步指令对应的时间偏移信息。Among them, Delay represents the current network delay of the client relative to the server, Offset represents the current time deviation 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. The current network delay and the current time deviation can be regarded as the time offset information corresponding to the time synchronization instruction.
步骤104:在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息。Step 104: When it is determined that the time offset information is abnormal information, historical time offset information is obtained.
在获取了时间偏移信息之后,要进一步判断一下,时间偏移信息是否是异常信息。在本申请提供的方法中,异常信息可以理解为时间偏移信息中存在异常情况。After obtaining the time offset information, it is necessary to further determine whether the time offset information is abnormal information. In the method provided in the present application, abnormal information can be understood as abnormal conditions existing in the time offset information.
在本申请提供的一具体实施方式中,时间偏移信息中包括当前网络延迟和当前时间偏差,在本实施方式中,通过当前网络延迟来进一判断是否为异常信息,具体的,所述方法还包括:In a specific implementation manner provided in the present application, the time offset information includes the current network delay and the current time deviation. In this implementation manner, whether it is abnormal information is further determined by the current network delay. Specifically, the method further includes:
在所述当前网络延迟大于预设延迟阈值的情况下,确定所述时间偏移信息为异常信息;When the current network delay is greater than a preset delay threshold, determining that the time offset information is abnormal information;
在所述当前网络延迟小于或等于所述预设延迟阈值的情况下,确定所述时间偏移信息为正常信息。When the current network delay is less than or equal to the preset delay threshold, it is determined that the time offset information is normal information.
其中,预设延迟阈值为本申请实施例中提供的一种用于确定时间偏移信息是否异常的延迟阈值,通常情况下,在时间偏移信息中包括有当前网络延迟。若当前网络延迟大于预设延迟阈值,则说明该时间偏移信息为异常信息,若当前网络延迟小于或等于预设延迟阈值,则可以确定时间偏移信息为正常信息。The preset delay threshold is a delay threshold provided in the embodiment of the present application for determining whether the time offset information is abnormal. Generally, the time offset information includes the current network delay. If the current network delay is greater than the preset delay threshold, it means that the time offset information is abnormal information. If the current network delay is less than or equal to the preset delay threshold, it can be determined that the time offset information is normal information.
例如,以系统的预设延迟阈值为5毫秒为例,若在上述步骤中,计算出来的时间偏移信息中的当前网络延迟为3毫秒,则说明时间偏移信息为正常信息,可以直接根据时间偏移信息中的当前时间偏差对客户端的当前客户端时间进行更新。若在上述步骤中,计算出来的时间偏移信息中的当前网络延迟为6毫秒,则说明时间偏移信息为异常信息,需要执行获取历史时间偏移信息的操作。For example, taking the preset delay threshold of the system as 5 milliseconds, if the current network delay in the time offset information calculated in the above steps is 3 milliseconds, it means that the time offset information is normal information, and the current client time of the client can be directly updated according to the current time deviation in the time offset information. If the current network delay in the time offset information calculated in the above steps is 6 milliseconds, it means that the time offset information is abnormal information, and it is necessary to perform the operation of obtaining the historical time offset information.
历史时间偏移信息具体是指用于在当前时间同步指令之前的多个时间同步指令对应的历史时间偏移信息,例如,在本次时间同步指令之前,统计过去10次时间同步指令对应的时间偏移信息,作为历史时间偏移信息。或者统计过去20次时间同步指令对应的时间偏移信息,作为历史时间偏移信息。The historical time offset information specifically refers to the historical time offset information corresponding to multiple time synchronization instructions before the current time synchronization instruction. For example, before the current time synchronization instruction, the time offset information corresponding to the past 10 time synchronization instructions is counted as the historical time offset information. Or the time offset information corresponding to the past 20 time synchronization instructions is counted as the historical time offset information.
在实际应用中,可以设置一个预设长度的数据结构,例如数组或数据队列。在预设长度的数据结构中保存历史时间偏移信息,当确定当前次的时间同步指令对应的时间偏移信息为异常信息的情况下,从预设长度的数据结构中取出历史时间偏移信息。In practical applications, a data structure of preset length, such as an array or a data queue, may be set to store historical time offset information in the data structure of preset length, and when it is determined that the time offset information corresponding to the current time synchronization instruction is abnormal information, the historical time offset information is retrieved from the data structure of preset length.
在本申请提供的另一具体实施方式中,获取历史时间偏移信息,包括:In another specific implementation provided by the present application, obtaining historical time offset information includes:
获取历史时间偏差数组和历史网络延迟数组,其中,所述历史时间偏差数组中保存预设数量的历史时间偏差,所述历史网络延迟数组中保存预设数量的历史网络延迟。A historical time deviation array and a historical network delay array are obtained, wherein the historical time deviation array stores a preset number of historical time deviations, and the historical network delay array stores a preset number of historical network delays.
更进一步的,时间偏移信息包括网络延迟和时间偏差。相应的,历史时间偏移信息也进一步包括历史网络延迟信息和历史时间偏差信息。同时,预设长度的数据结构可以分为网络延迟数据结构和时间偏差数据结构,在网络延迟数据结构中保存有预设数量的历史网络延迟,在时间偏差数据结构中保存有预设数量的历史时间偏差。Furthermore, the time offset information includes network delay and time deviation. Accordingly, the historical time offset information also further includes historical network delay information and historical time deviation information. At the same time, the data structure of the preset length can be divided into a network delay data structure and a time deviation data structure, in which a preset number of historical network delays are stored, and in which a preset number of historical time deviations are stored.
以数据结构为长度为50的回环数组为例,在系统中设置有网络延迟回环数组和时间偏差回环数组,其中,网络延迟回环数组中保存有过去50次时间同步指令对应的网络延迟,时间偏差回环数组中保存有过去50次时间同步指令对应的时间偏差。回环数组保存预设数量的信息,当有新的数据加入到回环数组中时,会有最早进入该回环数组的数据被剔除。在本申请提供的方法中,数据结构的预设长度为偶数。Taking the data structure as a loop array with a length of 50 as an example, a network delay loop array and a time deviation loop array are set in the system, wherein the network delay loop array stores the network delay corresponding to the past 50 time synchronization instructions, and the time deviation loop array stores the time deviation corresponding to the past 50 time synchronization instructions. The loop array stores a preset amount of information. When new data is added to the loop array, the data that enters the loop array earliest will be eliminated. In the method provided in the present application, the preset length of the data structure is an even number.
步骤106:根据所述历史时间偏移信息确定参考时间偏移区间。Step 106: Determine a reference time offset interval according to the historical time offset information.
其中,参考时间偏移区间可以理解为用于确定时间偏移信息是否异常的范围区间。当时间偏移信息位于该参考时间偏移区间内的情况下,可以认为该时间偏移信息是可以被接受的,当时间偏移信息位于该参考时间偏移区间外的情况下,则认为该时间偏移信息时不可被接受的。The reference time offset interval can be understood as a range interval used to determine whether the time offset information is abnormal. When the time offset information is within the reference time offset interval, it can be considered that the time offset information is acceptable, and when the time offset information is outside the reference time offset interval, it is considered that the time offset information is unacceptable.
因此,确定参考时间偏移区间在本申请提供的方法中十分重要,在本申请提供的方法中,是需要根据历史时间偏移信息来确定参考时间偏移区间。历史时间偏移信息中记载的是过去的预设次数的时间同步指令对应的时间偏移信息,通过历史时间偏移信息确定参考时间偏移区间可以更好的对客户端的近期网络状态有较为准确的体现。Therefore, determining the reference time offset interval is very important in the method provided in this application. In the method provided in this application, it is necessary to determine the reference time offset interval based on historical time offset information. The historical time offset information records the time offset information corresponding to the time synchronization instructions of the preset number of times in the past. Determining the reference time offset interval through the historical time offset information can better reflect the recent network status of the client more accurately.
基于此,在本申请提供的另一具体实施方式中,根据所述历史时间偏移信息确定参考时间偏移区间,包括:Based on this, in another specific implementation manner provided in the present application, determining a reference time offset interval according to the historical time offset information includes:
在所述历史时间偏差数组中确定第一时间偏差和第二时间偏差,在所述历史网络延迟数组中确定第一网络延迟和第二网络延迟;Determine a first time deviation and a second time deviation in the historical time deviation array, and determine a first network delay and a second network delay in the historical network delay array;
根据所述第一时间偏差和所述第二时间偏差确定参考时间偏差区间;Determine a reference time deviation interval according to the first time deviation and the second time deviation;
根据所述第一网络延迟和所述第二网络延迟确定参考网络延迟区间。A reference network delay interval is determined according to the first network delay and the second network delay.
在实际应用中,历史时间偏移信息中包括历史时间偏差和历史网络延迟,从历史时间偏差中确定第一时间偏差和第二时间偏差,从历史网络延迟数据中确定第一网络延迟和第二网络延迟。In practical applications, the historical time offset information includes historical time deviation and historical network delay. The first time offset and the second time offset are determined from the historical time deviation, and the first network delay and the second network delay are determined from the historical network delay data.
需要注意的是,第一时间偏差、第二时间偏差、第一网络延迟、第二网络延迟均为历史时间偏移信息中的具体值,历史时间偏移信息中包括有多个历史时间偏差和多个网络延迟,从中选取出相应的第一时间偏差、第二时间偏差、第一网络延迟、第二网络延迟。It should be noted that the first time deviation, the second time deviation, the first network delay, and the second network delay are all specific values in the historical time offset information. The historical time offset information includes multiple historical time deviations and multiple network delays, from which the corresponding first time deviation, second time deviation, first network delay, and second network delay are selected.
为了更好的体现出从历史时间偏移信息中选取第一时间偏差、第二时间偏差、第一网络延迟、第二网络延迟的准确性,所述历史时间偏差数组中确定第一时间偏差和第二时间偏差,在所述历史网络延迟数组中确定第一网络延迟和第二网络延迟,包括:In order to better reflect the accuracy of selecting the first time deviation, the second time deviation, the first network delay, and the second network delay from the historical time offset information, the first time deviation and the second time deviation are determined in the historical time deviation array, and the first network delay and the second network delay are determined in the historical network delay array, including:
对所述历史时间偏差数组中的历史时间偏差按从小到大的顺序进行排序,在时间偏差排序结果中选取下四分位数的值为第一时间偏差,选取上四分位数的值为第二时间偏差;The historical time deviations in the historical time deviation array are sorted in ascending order, and the value of the lower quartile is selected as the first time deviation in the time deviation sorting result, and the value of the upper quartile is selected as the second time deviation;
对所述历史网络延迟数组中的历史网络延迟按从小到大的顺序进行排序,在网络延迟排序结果中选取下四分位数的值为第一网络延迟,选取上四分位数的值为第二网络延迟。The historical network delays in the historical network delay array are sorted in ascending order, and the value of the lower quartile is selected as the first network delay in the network delay sorting result, and the value of the upper quartile is selected as the second network delay.
在实际应用中,将历史时间偏差数组中的历史时间偏差按照从小到大的顺序进行排序,根据时间偏差排序结果,选取四分位数的值为第一时间偏差和第二时间偏差。四分位数也称为四分位点,是指在统计学中将数值由小到大排列并分成四等份,处于25%和75%位置上的值。其中,处于25%位置上的数值为下四分位数,处于75%位置上的数值为上四分位数。通过四分位数可以更好的理解数据的分布情况,用于更好的进行数据分析。In practical applications, the historical time deviations in the historical time deviation array are sorted in ascending order, and according to the time deviation sorting results, the quartile values are selected as the first time deviation and the second time deviation. Quartiles are also called quartile points, which refer to the values at the 25% and 75% positions when the values are arranged from small to large and divided into four equal parts in statistics. Among them, the value at the 25% position is the lower quartile, and the value at the 75% position is the upper quartile. Quartiles can be used to better understand the distribution of data and better perform data analysis.
具体的,从时间偏差排序结果中选取下四分位数(25%位置的数)的值为第一时间偏差,选取上四分位数(75%位置的数)的值为第二时间偏差;从网络延迟排序结果中选取下四分位数(25%位置的数)的值为第一网络延迟,选取上四分位数(75%位置的数)的值为第二网络延迟。Specifically, the value of the lower quartile (the number at the 25% position) from the time deviation sorting result is selected as the first time deviation, and the value of the upper quartile (the number at the 75% position) is selected as the second time deviation; the value of the lower quartile (the number at the 25% position) from the network delay sorting result is selected as the first network delay, and the value of the upper quartile (the number at the 75% position) is selected as the second network delay.
在确定了第一时间偏差、第二时间偏差、第一网络延迟和第二网络延迟之后,即可根据所述第一时间偏差和所述第二时间偏差确定参考时间偏差区间,根据所述第一网络延迟和所述第二网络延迟确定参考网络延迟区间。After determining the first time deviation, the second time deviation, the first network delay, and the second network delay, a reference time deviation interval may be determined according to the first time deviation and the second time deviation, and a reference network delay interval may be determined according to the first network delay and the second network delay.
在实际应用中,可以根据第一时间偏差和第二时间偏差作为参考时间偏差区间的最小值和最大值,根据第一网络延迟和第二网络延迟作为参考网络延迟区间的最小值和最大值。也可以根据本申请实施例中提供的时间偏差区间的算法确定参考时间偏差区间和参考网络延迟区间。In practical applications, the first time deviation and the second time deviation can be used as the minimum and maximum values of the reference time deviation interval, and the first network delay and the second network delay can be used as the minimum and maximum values of the reference network delay interval. The reference time deviation interval and the reference network delay interval can also be determined according to the algorithm of the time deviation interval provided in the embodiment of the present application.
在本申请提供的一具体实施方式中,根据所述第一时间偏差和所述第二时间偏差确定参考时间偏差区间,包括:In a specific implementation manner provided in the present application, determining a reference time deviation interval according to the first time deviation and the second time deviation includes:
根据预设区间上界公式、所述第一时间偏差和所述第二时间偏差计算参考时间偏差最大值;Calculate the maximum value of the reference time deviation according to the preset interval upper limit formula, the first time deviation and the second time deviation;
根据预设区间下界公式、所述第一时间偏差和所述第二时间偏差计算参考时间偏差最小值;Calculate the minimum value of the reference time deviation according to the preset interval lower bound formula, the first time deviation and the second time deviation;
根据所述参考时间偏差最大值和所述参考时间偏差最小值确定参考时间偏差区间。A reference time deviation interval is determined according to the maximum reference time deviation value and the minimum reference time deviation value.
预设区间上界公式用于确定某个区间的最大值。具体的,预设区间上界公式参见下述公式3:The preset interval upper bound formula is used to determine the maximum value of a certain interval. Specifically, the preset interval upper bound formula is shown in the following formula 3:
Max = D2+ V*(D2-D1) 公式3Max = D2+ V*(D2-D1) Formula 3
其中,Max为区间最大值;D1为下四分位数;D2为上四分位数;V为波动阈值,在本申请提供的方法中为常数。Among them, Max is the maximum value of the interval; D1 is the lower quartile; D2 is the upper quartile; V is the fluctuation threshold, which is a constant in the method provided in this application.
根据上述公式3可以计算区间的最大值。以计算参考时间偏差最大值为例,Max即为参考时间偏差最大值,D1即为第一时间偏差,D2即为第二时间偏差。V为波动阈值,在本申请实施例提供的方法中为常数1.5。通过上述公式3可以计算出参考时间偏差最大值。The maximum value of the interval can be calculated according to the above formula 3. Taking the calculation of the maximum value of the reference time deviation as an example, Max is the maximum value of the reference time deviation, D1 is the first time deviation, and D2 is the second time deviation. V is the fluctuation threshold, which is a constant of 1.5 in the method provided in the embodiment of the present application. The maximum value of the reference time deviation can be calculated by the above formula 3.
预设区间下界公式用于确定某个区间的最小值,具体的,预设区间下界公式参见下述公式4:The preset interval lower bound formula is used to determine the minimum value of a certain interval. Specifically, the preset interval lower bound formula is shown in the following formula 4:
Min = D1- V*(D2-D1) 公式4Min = D1- V*(D2-D1) Formula 4
其中,Min为区间最小值;D1为下四分位数;D2为上四分位数;V为波动阈值,在本申请提供的方法中为常数。Among them, Min is the minimum value of the interval; D1 is the lower quartile; D2 is the upper quartile; V is the fluctuation threshold, which is a constant in the method provided in this application.
根据上述公式4可以计算区间的最小值。以计算参考时间偏差最大值为例,Min即为参考时间偏差最小值,D1即为第一时间偏差,D2即为第二时间偏差。V为波动阈值,在本申请实施例提供的方法中为常数1.5。通过上述公式4可以计算出参考时间偏差最小值。The minimum value of the interval can be calculated according to the above formula 4. Taking the calculation of the maximum value of the reference time deviation as an example, Min is the minimum value of the reference time deviation, D1 is the first time deviation, and D2 is the second time deviation. V is the fluctuation threshold, which is a constant of 1.5 in the method provided in the embodiment of the present application. The minimum value of the reference time deviation can be calculated by the above formula 4.
在通过上述公式3和公式4,以及第一时间偏差和第二时间偏差,即可计算出参考时间偏差最小值和参考时间偏差最大值。从而根据参考时间偏差最小值和参考时间偏差最大值确定出参考时间偏差区间。The minimum reference time deviation and the maximum reference time deviation can be calculated by using the above formula 3 and formula 4, as well as the first time deviation and the second time deviation, so as to determine the reference time deviation interval according to the minimum reference time deviation and the maximum reference time deviation.
在本申请提供的另一具体实施方式中,根据所述第一网络延迟和所述第二网络延迟确定参考网络延迟区间,包括:In another specific implementation manner provided in the present application, determining a reference network delay interval according to the first network delay and the second network delay includes:
根据预设区间上界公式、所述第一网络延迟和所述第二网络延迟计算参考网络延迟最大值;Calculate the maximum value of the reference network delay according to the preset interval upper bound formula, the first network delay and the second network delay;
根据预设区间下界公式、所述第一网络延迟和所述第二网络延迟计算参考网络延迟最小值;Calculate a minimum reference network delay according to a preset interval lower bound formula, the first network delay, and the second network delay;
根据所述参考网络延迟最大值和所述参考网络延迟最小值确定参考网络延迟区间。A reference network delay interval is determined according to the maximum reference network delay value and the minimum reference network delay value.
基于与上述参考时间偏差最小值和参考时间偏差最大值相同的计算方式,使用上述公式3和公式4,以及第一网络延迟和第二网络延迟可以计算出参考网络延迟最大值和参考网络延迟最小值,通过参考网络延迟最大值和参考网络延迟最小值可以进一步确定出参考网络延迟区间。Based on the same calculation method as the above-mentioned minimum reference time deviation and maximum reference time deviation, the above-mentioned Formula 3 and Formula 4, as well as the first network delay and the second network delay, can be used to calculate the maximum reference network delay and the minimum reference network delay. The reference network delay interval can be further determined by the maximum reference network delay and the minimum reference network delay.
通过本申请实施例提供的确定参考时间偏差区间和参考网络延迟区间的方法,可以更好的计算出时间偏差或网络延迟的波动区间,通过历史时间偏移信息可以统计处客户端在近期的网络波动情况,从而更好的判断时间偏移信息的网络波动是否是正常范围,以便进行后续的时间同步处理。Through the method for determining the reference time deviation interval and the reference network delay interval provided in the embodiment of the present application, the fluctuation interval of the time deviation or network delay can be better calculated. The recent network fluctuation of the client can be statistically analyzed through the historical time offset information, so as to better judge whether the network fluctuation of the time offset information is within the normal range, so as to perform subsequent time synchronization processing.
在本申请提供的一具体实施方式中,根据所述历史时间偏移信息确定参考时间偏移区间,包括:In a specific implementation provided by the present application, determining a reference time offset interval according to the historical time offset information includes:
在历史时间偏移信息中确定第一时间偏移信息和第二时间偏移信息;Determining first time offset information and second time offset information in the historical time offset information;
根据预设区间上界公式、所述第一时间偏移信息和所述第二时间偏移信息计算参考时间偏移最大值;Calculate the maximum value of the reference time offset according to the preset interval upper bound formula, the first time offset information and the second time offset information;
根据预设区间下界公式、所述第一时间偏移信息和所述第二时间偏移信息计算参考时间偏移最小值;Calculate the minimum value of the reference time offset according to the preset interval lower bound formula, the first time offset information and the second time offset information;
根据所述参考时间偏移最大值和所述参考时间偏移最小值确定参考时间偏移区间。A reference time offset interval is determined according to the reference time offset maximum value and the reference time offset minimum value.
更进一步的,在历史时间偏移信息中确定第一时间偏移信息和第二时间偏移信息,包括:Furthermore, determining the first time offset information and the second time offset information in the historical time offset information includes:
对所述历史时间偏移信息按照从小到大的顺序进行排序;Sorting the historical time offset information in ascending order;
在排序结果中选取下四分位数的值为第一时间偏移信息,选取上四分位数的值为第二时间偏移信息。In the sorting results, the value of the lower quartile is selected as the first time offset information, and the value of the upper quartile is selected as the second time offset information.
需要注意的是,确定第一时间偏移信息和第二时间偏移信息的具体实现方式,参见上述关于第一时间偏差和所述第二时间偏差的相关描述,确定参考时间偏移区间的具体实现方式,参见上述参考时间偏差区间的相关描述,在此不再赘述。It should be noted that for the specific implementation method of determining the first time offset information and the second time offset information, please refer to the above description of the first time offset and the second time offset. For the specific implementation method of determining the reference time offset interval, please refer to the above description of the reference time offset interval, which will not be repeated here.
步骤108:在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。Step 108: When the time offset information satisfies the reference time offset interval, the current client time of the client is updated based on the time offset information.
在通过上述步骤处理后,即可获得参考时间偏移区间。从而可以进一步的判断时间偏移信息是否满足该参考时间偏移区间,若时间偏移信息满足该参考时间偏移区间,则说明当前的网络波动处于正常水平。反之,若时间偏移信息在该参考时间偏移区间之外,则说明当前的网络波动是异常的。After the above steps are processed, the reference time offset interval can be obtained. Therefore, it can be further determined whether the time offset information satisfies the reference time offset interval. If the time offset information satisfies the reference time offset interval, it means that the current network fluctuation is at a normal level. On the contrary, if the time offset information is outside the reference time offset interval, it means that the current network fluctuation is abnormal.
如果当前的网络波动处于正常水平,则可以执行同步命令,将计算出来的时间偏移信息用于更新客户端的当前客户端时间。若当前的网络波动处于异常,则对本次时间同步指令不做处理。If the current network fluctuation is at a normal level, the synchronization command can be executed, and the calculated time offset information is used to update the current client time of the client. If the current network fluctuation is abnormal, the time synchronization command will not be processed.
在本申请提供的一具体实施方式中,所述参考时间偏移区间包括参考时间偏差区间和参考网络延迟区间,所述时间偏移信息包括当前网络延迟和当前时间偏差;In a specific implementation provided by the present application, the reference time offset interval includes a reference time offset interval and a reference network delay interval, and the time offset information includes a current network delay and a current time offset;
所述方法还包括:The method further comprises:
在所述当前时间偏差位于所述参考时间偏差区间内,且所述当前网络延迟位于所述参考网络延迟区间内的情况下,确定所述时间偏移信息满足所述参考时间偏移区间;In a case where the current time deviation is within the reference time deviation interval and the current network delay is within the reference network delay interval, determining that the time offset information satisfies the reference time offset interval;
在所述当前时间偏差位于所述参考时间偏差区间外,或所述当前网络延迟位于所述参考网络延迟区间外的情况下,确定所述时间偏移信息未满足所述参考时间偏移区间。In a case where the current time deviation is outside the reference time deviation interval, or the current network delay is outside the reference network delay interval, it is determined that the time offset information does not satisfy the reference time offset interval.
在实际应用中,参考时间偏移区间具体包括参考时间偏差区间和参考网络延迟区间,时间偏移信息具体包括当前网络延迟和当前时间偏差。具体的,在当前网络延迟在参考网络延迟区间内,且当前时间偏差在参考时间偏差区间内的情况下,说明当前的网络波动处于正常水平,则可以确定时间偏移信息满足参考时间偏移区间。In practical applications, the reference time offset interval specifically includes a reference time offset interval and a reference network delay interval, and the time offset information specifically includes a current network delay and a current time offset. Specifically, when the current network delay is within the reference network delay interval and the current time offset is within the reference time offset interval, it indicates that the current network fluctuation is at a normal level, and it can be determined that the time offset information satisfies the reference time offset interval.
反之,若当前时间偏差位于参考时间偏差区间外,或者当前网络延迟位于参考网络延迟区间外的情况下,说明当前网络波动处于异常水平,确定时间偏移信息未满足参考时间偏移区间。On the contrary, if the current time deviation is outside the reference time deviation interval, or the current network delay is outside the reference network delay interval, it means that the current network fluctuation is at an abnormal level, and it is determined that the time offset information does not meet the reference time offset interval.
在本申请提供的另一具体实施方式中,所述方法还包括:In another specific embodiment provided in the present application, the method further comprises:
在所述时间偏移信息未满足所述参考时间偏移区间的情况下,不基于所述时间偏移信息更新所述客户端的当前客户时间。In a case where the time offset information does not satisfy the reference time offset interval, the current client time of the client is not updated based on the time offset information.
当时间偏移信息未满足参考时间偏移区间的情况下,则不对本次时间同步指令执行响应的时间同步操作。即不基于时间偏移信息更新客户端的当前客户端时间。When the time offset information does not satisfy the reference time offset interval, the time synchronization operation in response to the time synchronization instruction is not performed, that is, the current client time of the client is not updated based on the time offset information.
在确定时间偏移信息满足参考时间偏移区间的情况下,根据时间偏移信息来更新客户端的当前客户端时间,更进一步的,是根据时间偏移信息中的当前时间偏差对客户端的当前客户端时间进行更新。When it is determined that the time offset information satisfies the reference time offset interval, the current client time of the client is updated according to the time offset information. Furthermore, the current client time of the client is updated according to the current time deviation in the time offset information.
在实际应用中,无论本次时间同步指令是否执行,都会获取到本次时间同步指令对应的时间偏移信息,该时间偏移信息记录了当前情况下客户端与服务器之间的网络波动情况,为了更好的记录该网络波动信息,为后续的数据处理提供数据支持,所述方法还包括:In actual applications, regardless of whether the time synchronization instruction is executed, the time offset information corresponding to the time synchronization instruction will be obtained. The time offset information records the network fluctuation between the client and the server in the current situation. In order to better record the network fluctuation information and provide data support for subsequent data processing, the method also includes:
根据所述时间偏移信息更新所述历史时间偏移信息。The historical time offset information is updated according to the time offset information.
即本申请提供的方法中,会根据每次的时间同步指令对应的时间偏移信息对历史时间偏移信息进行更新。具体的,是将时间偏移信息添加到历史时间偏移信息中,若历史时间偏移信息中的数量不足,则可以直接将时间偏移信息添加进去。若历史时间偏移信息中的数量已经达到阈值,则从中取出最早的历史时间偏移信息,并将当前次的时间偏移信息添加到该历史时间偏移信息中。That is, in the method provided by the present application, the historical time offset information is updated according to the time offset information corresponding to each time synchronization instruction. Specifically, the time offset information is added to the historical time offset information. If the number in the historical time offset information is insufficient, the time offset information can be directly added. If the number in the historical time offset information has reached the threshold, the earliest historical time offset information is taken out, and the current time offset information is added to the historical time offset information.
本申请实施例提供的时间同步方法,应用于客户端,包括接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;根据所述历史时间偏移信息确定参考时间偏移区间;在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。The time synchronization method provided in the embodiment of the present application is applied to a client, including receiving a time synchronization instruction, and calculating the time offset information between the client and the server based on the time synchronization instruction; when it is determined that the time offset information is abnormal information, obtaining historical time offset information; determining a reference time offset interval based on the historical time offset information; and when the time offset information satisfies the reference time offset interval, updating the current client time of the client based on the time offset information.
通过本申请实施例提供的方法,在获得了当前次的时间同步指令,并计算客户端与服务器之间的时间偏移信息后,还要进一步的对时间偏移信息进行筛选,判断其是否为异常信息,若在确定时间偏移信息为异常信息的情况下,需要再根据历史时间偏移信息来进一步判断该时间偏移信息是否是正常范围内的网络波动。只有在时间偏移信息时正常范围内的网络波动的情况下,才会基于该时间偏移信息对当前客户端时间进行更新,否则就舍弃当前次的时间偏移信息。通过本方法,可以有效降低错误时间偏移信息的应用,避免因网络异常波动导致的客户端时间跳跃,增强了系统时间的连贯性和稳定性。Through the method provided by the embodiment of the present application, after obtaining the current time synchronization instruction and calculating the time offset information between the client and the server, the time offset information is further screened to determine whether it is abnormal information. If the time offset information is determined to be abnormal information, it is necessary to further determine whether the time offset information is a network fluctuation within a normal range based on the historical time offset information. Only when the network fluctuation is within the normal range when the time offset information is in the normal range, the current client time will be updated based on the time offset information, otherwise the current time offset information will be discarded. Through this method, the application of erroneous time offset information can be effectively reduced, the client time jump caused by abnormal network fluctuations can be avoided, and the consistency and stability of the system time can be enhanced.
下述结合附图2,对所述时间同步方法进行进一步说明。其中,图2示出了本申请一实施例提供的一种时间同步方法的示意图。The time synchronization method is further described below in conjunction with Figure 2. Figure 2 shows a schematic diagram of a time synchronization method provided by an embodiment of the present application.
如图2所示,本时间同步方法应用在客户端,客户端接收到时间同步指令,并基于该时间同步执行向服务器发送时间同步报文,并在时间同步报文中加入客户端的第一时间戳T1。As shown in FIG. 2 , 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. The first timestamp T1 of the client is added to the time synchronization message.
服务器接收到客户端发送的时间同步报文,并在时间同步报文中记录服务器接收到该报文的第二时间戳T2。服务器响应于该时间同步报文向客户端发送同步响应报文,将第一时间戳、第二时间戳添加到同步响应报文的同时,还会再同步响应报文中添加服务器发送该同步响应报文的第三时间戳T3。需要注意的是,第二时间戳T2和第三时间戳T3均为服务器的服务器时间戳。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.
客户端在接收到服务器发送的同步响应报文后,会记录客户端接收到该报文的第四时间戳T4。至此,在客户端中收集到了用于计算客户端相较于服务器的时间偏移信息。时间偏移信息具体包括当前网络延迟(Delay)和当前时间偏差(Offset)。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 time offset information used to calculate the time offset of the client compared to the server. The time offset information specifically includes the current network delay (Delay) and the current time deviation (Offset).
在当前网络延迟小于或等于预设延迟阈值的情况下,使用当前时间偏差更新客户端的本地客户端时钟。When the current network delay is less than or equal to the preset delay threshold, the local client clock of the client is updated using the current time deviation.
在当前网络延迟大于预设延迟阈值的情况下,获取历史时间偏差和历史网络延迟,根据历史时间偏差确定参考时间偏差区间,根据历史网络延迟确定参考网络延迟区间。When the current network delay is greater than a preset delay threshold, the historical time deviation and the historical network delay are obtained, a reference time deviation interval is determined according to the historical time deviation, and a reference network delay interval is determined according to the historical network delay.
再进一步判断当前网络延迟是否在参考网络延迟区间中,当前时间偏差是否在参考时间偏差区间中。在当前网络延迟在参考网络延迟区间,且当前时间偏差在参考时间偏差区间中的情况下,使用当前时间偏差更新客户端的本地客户端时钟。否则,不进行当前次的时钟同步。It is further determined whether the current network delay is within the reference network delay interval and whether the current time deviation is within the reference time deviation interval. If the current network delay is within the reference network delay interval and the current time deviation is within the reference time deviation interval, the local client clock of the client is updated using the current time deviation. Otherwise, the current clock synchronization is not performed.
参见图3,图3示出了本申请一实施例提供的应用于轨道交通综合监控系统的时间同步方法的流程示意图,该方法应用于轨道交通综合监控系统中的交通对象终端。具体包括:Referring to FIG. 3 , FIG. 3 shows a schematic flow chart of a time synchronization method applied to a rail transit integrated monitoring system provided by an embodiment of the present application, and the method is applied to a transportation object terminal in the rail transit integrated monitoring system. Specifically, it includes:
步骤302:接收当前次的时间同步指令,并基于该时间同步指令计算与服务器之间的当前网络延迟和当前时间偏差。Step 302: Receive the current time synchronization instruction, and calculate the current network delay and current time deviation between the server and the server based on the time synchronization instruction.
步骤304:判断当前网络延迟是否大于预设延迟阈值,若是,则执行步骤306,若否,则执行步骤314。Step 304: Determine whether the current network delay is greater than a preset delay threshold, if so, execute step 306, if not, execute step 314.
步骤306:获取历史时间偏差数组和历史网络延迟数组,从历史时间偏差数组中获取至少一个历史时间偏差,从历史网络延迟数组中获取至少一个历史网络延迟。Step 306: Obtain a historical time deviation array and a historical network delay array, obtain at least one historical time deviation from the historical time deviation array, and obtain at least one historical network delay from the historical network delay array.
步骤308:对各历史时间偏差按从小到大的顺序进行排序,在时间偏差排序结果中选取下四分位数的值为第一时间偏差,选取上四分位数的值为第二时间偏差,并根据预设区间上界公式和预设区间下界公式确定参考时间偏差区间。Step 308: Sort the historical time deviations in ascending order, select the lower quartile value as the first time deviation, select the upper quartile value as the second time deviation in the time deviation sorting result, and determine the reference time deviation interval according to the preset interval upper limit formula and the preset interval lower limit formula.
步骤310:对各历史网络延迟按从小到大的顺序进行排序,在网络延迟排序结果中选取下四分位数的值为第一网络延迟,选取上四分位数的值为第二网络延迟,并根据预设区间上界公式和预设区间下界公式确定参考网络延迟区间。Step 310: Sort the historical network delays in ascending order, select the lower quartile value as the first network delay, select the upper quartile value as the second network delay in the network delay sorting result, and determine the reference network delay interval according to the preset interval upper limit formula and the preset interval lower limit formula.
步骤312:判断是否所述当前时间偏差在所述参考时间偏差区间内,且所述当前网络延迟位于所述参考网络延迟区间内,若是,则执行步骤314,若否,则执行步骤316。Step 312: Determine whether the current time deviation is within the reference time deviation interval and the current network delay is within the reference network delay interval. If so, execute step 314; if not, execute step 316.
步骤314:基于所述当前时间偏差更新当前终端时间。Step 314: Update the current terminal time based on the current time deviation.
步骤316:中止当前次的时间同步指令。Step 316: Terminate the current time synchronization instruction.
步骤318:将当前时间偏差添加到历史时间偏差数组,将当前网络延迟添加到历史网络延迟数组。Step 318: Add the current time deviation to the historical time deviation array, and add the current network delay to the historical network delay array.
通过本申请实施例提供的方法,在获得了当前次的时间同步指令,并计算客户端与服务器之间的时间偏移信息后,还要进一步的对时间偏移信息进行筛选,判断其是否为异常信息,若在确定时间偏移信息为异常信息的情况下,需要再根据历史时间偏移信息来进一步判断该时间偏移信息是否是正常范围内的网络波动。只有在时间偏移信息时正常范围内的网络波动的情况下,才会基于该时间偏移信息对当前客户端时间进行更新,否则就舍弃当前次的时间偏移信息。通过本方法,可以有效降低错误时间偏移信息的应用,避免因网络异常波动导致的客户端时间跳跃,增强了系统时间的连贯性和稳定性。Through the method provided by the embodiment of the present application, after obtaining the current time synchronization instruction and calculating the time offset information between the client and the server, the time offset information is further screened to determine whether it is abnormal information. If the time offset information is determined to be abnormal information, it is necessary to further determine whether the time offset information is a network fluctuation within a normal range based on the historical time offset information. Only when the network fluctuation is within the normal range when the time offset information is in the normal range, the current client time will be updated based on the time offset information, otherwise the current time offset information will be discarded. Through this method, the application of erroneous time offset information can be effectively reduced, the client time jump caused by abnormal network fluctuations can be avoided, and the consistency and stability of the system time can be enhanced.
与上述方法实施例相对应,本申请还提供了时间同步装置实施例,图4示出了本申请一实施例提供的一种时间同步装置的结构示意图。如图4所示,该装置包括:Corresponding to the above method embodiment, the present application also provides a time synchronization device embodiment, and FIG4 shows a schematic diagram of the structure of a time synchronization device provided by an embodiment of the present application. As shown in FIG4, the device includes:
接收模块402,被配置为接收时间同步指令,并基于所述时间同步指令计算与服务器之间的时间偏移信息;The receiving module 402 is configured to receive a time synchronization instruction and calculate the time offset information between the server and the receiving module based on the time synchronization instruction;
获取模块404,被配置为在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;The acquisition module 404 is configured to acquire historical time offset information when it is determined that the time offset information is abnormal information;
确定模块406,被配置为根据所述历史时间偏移信息确定参考时间偏移区间;A determination module 406 is configured to determine a reference time offset interval according to the historical time offset information;
更新模块408,被配置为在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。The updating module 408 is configured to update the current client time of the client based on the time offset information when the time offset information satisfies the reference time offset interval.
可选的,所述接收模块402,进一步被配置为:Optionally, the receiving module 402 is further configured to:
响应于所述时间同步指令向服务器发送时间同步报文,并记录所述时间同步报文的第一时间戳;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;
根据所述第一时间戳、所述第二时间戳、所述第三时间戳和所述第四时间戳计算所述客户端与所述服务器之间的当前网络延迟和当前时间偏差。The current network delay and the current time deviation between the client and the server are calculated according to the first timestamp, the second timestamp, the third timestamp and the fourth timestamp.
可选的,所述装置还包括异常信息确定模块,被配置为:Optionally, the device further includes an abnormal information determination module, configured to:
在所述当前网络延迟大于预设延迟阈值的情况下,确定所述时间偏移信息为异常信息;When the current network delay is greater than a preset delay threshold, determining that the time offset information is abnormal information;
在所述当前网络延迟小于或等于所述预设延迟阈值的情况下,确定所述时间偏移信息为正常信息。When the current network delay is less than or equal to the preset delay threshold, it is determined that the time offset information is normal information.
可选的,所述获取模块404,进一步被配置为:Optionally, the acquisition module 404 is further configured to:
获取历史时间偏差数组和历史网络延迟数组,其中,所述历史时间偏差数组中保存预设数量的历史时间偏差,所述历史网络延迟数组中保存预设数量的历史网络延迟。A historical time deviation array and a historical network delay array are obtained, wherein the historical time deviation array stores a preset number of historical time deviations, and the historical network delay array stores a preset number of historical network delays.
可选的,所述确定模块406,进一步被配置为:Optionally, the determining module 406 is further configured to:
在所述历史时间偏差数组中确定第一时间偏差和第二时间偏差,在所述历史网络延迟数组中确定第一网络延迟和第二网络延迟;Determine a first time deviation and a second time deviation in the historical time deviation array, and determine a first network delay and a second network delay in the historical network delay array;
根据所述第一时间偏差和所述第二时间偏差确定参考时间偏差区间;Determine a reference time deviation interval according to the first time deviation and the second time deviation;
根据所述第一网络延迟和所述第二网络延迟确定参考网络延迟区间。A reference network delay interval is determined according to the first network delay and the second network delay.
可选的,所述确定模块406,进一步被配置为:Optionally, the determining module 406 is further configured to:
对所述历史时间偏差数组中的历史时间偏差按从小到大的顺序进行排序,在时间偏差排序结果中选取下四分位数的值为第一时间偏差,选取上四分位数的值为第二时间偏差;The historical time deviations in the historical time deviation array are sorted in ascending order, and the value of the lower quartile is selected as the first time deviation in the time deviation sorting result, and the value of the upper quartile is selected as the second time deviation;
对所述历史网络延迟数组中的历史网络延迟按从小到大的顺序进行排序,在网络延迟排序结果中选取下四分位数的值为第一网络延迟,选取上四分位数的值为第二网络延迟。The historical network delays in the historical network delay array are sorted in ascending order, and the value of the lower quartile is selected as the first network delay in the network delay sorting result, and the value of the upper quartile is selected as the second network delay.
可选的,所述确定模块406,进一步被配置为:Optionally, the determining module 406 is further configured to:
根据预设区间上界公式、所述第一时间偏差和所述第二时间偏差计算参考时间偏差最大值;Calculate the maximum value of the reference time deviation according to the preset interval upper limit formula, the first time deviation and the second time deviation;
根据预设区间下界公式、所述第一时间偏差和所述第二时间偏差计算参考时间偏差最小值;Calculate the minimum value of the reference time deviation according to the preset interval lower bound formula, the first time deviation and the second time deviation;
根据所述参考时间偏差最大值和所述参考时间偏差最小值确定参考时间偏差区间。A reference time deviation interval is determined according to the maximum reference time deviation value and the minimum reference time deviation value.
可选的,所述确定模块406,进一步被配置为:Optionally, the determining module 406 is further configured to:
根据预设区间上界公式、所述第一网络延迟和所述第二网络延迟计算参考网络延迟最大值;Calculate the maximum value of the reference network delay according to the preset interval upper bound formula, the first network delay and the second network delay;
根据预设区间下界公式、所述第一网络延迟和所述第二网络延迟计算参考网络延迟最小值;Calculate a minimum reference network delay according to a preset interval lower bound formula, the first network delay, and the second network delay;
根据所述参考网络延迟最大值和所述参考网络延迟最小值确定参考网络延迟区间。A reference network delay interval is determined according to the maximum reference network delay value and the minimum reference network delay value.
可选的,所述参考时间偏移区间包括参考时间偏差区间和参考网络延迟区间,所述时间偏移信息包括当前网络延迟和当前时间偏差;Optionally, the reference time offset interval includes a reference time deviation interval and a reference network delay interval, and the time offset information includes a current network delay and a current time deviation;
所述装置还包括判断模块,被配置为:The device also includes a judgment module configured to:
在所述当前时间偏差位于所述参考时间偏差区间内,且所述当前网络延迟位于所述参考网络延迟区间内的情况下,确定所述时间偏移信息满足所述参考时间偏移区间;In a case where the current time deviation is within the reference time deviation interval and the current network delay is within the reference network delay interval, determining that the time offset information satisfies the reference time offset interval;
在所述当前时间偏差位于所述参考时间偏差区间外,或所述当前网络延迟位于所述参考网络延迟区间外的情况下,确定所述时间偏移信息未满足所述参考时间偏移区间。In a case where the current time deviation is outside the reference time deviation interval, or the current network delay is outside the reference network delay interval, it is determined that the time offset information does not satisfy the reference time offset interval.
可选的,所述装置还包括中止模块,被配置为:Optionally, the device further includes a termination module configured to:
在所述时间偏移信息未满足所述参考时间偏移区间的情况下,不基于所述时间偏移信息更新所述客户端的当前客户时间。In a case where the time offset information does not satisfy the reference time offset interval, the current client time of the client is not updated based on the time offset information.
可选的,所述装置还包括更新模块,被配置为:Optionally, the device further includes an updating module configured to:
根据所述时间偏移信息更新所述历史时间偏移信息。The historical time offset information is updated according to the time offset information.
通过本申请实施例提供的装置,在获得了当前次的时间同步指令,并计算客户端与服务器之间的时间偏移信息后,还要进一步的对时间偏移信息进行筛选,判断其是否为异常信息,若在确定时间偏移信息为异常信息的情况下,需要再根据历史时间偏移信息来进一步判断该时间偏移信息是否是正常范围内的网络波动。只有在时间偏移信息时正常范围内的网络波动的情况下,才会基于该时间偏移信息对当前客户端时间进行更新,否则就舍弃当前次的时间偏移信息。通过本方法,可以有效降低错误时间偏移信息的应用,避免因网络异常波动导致的客户端时间跳跃,增强了系统时间的连贯性和稳定性。Through the device provided by the embodiment of the present application, after obtaining the current time synchronization instruction and calculating the time offset information between the client and the server, the time offset information is further screened to determine whether it is abnormal information. If the time offset information is determined to be abnormal information, it is necessary to further determine whether the time offset information is a network fluctuation within a normal range based on the historical time offset information. Only when the network fluctuation is within the normal range when the time offset information is in the time offset information, the current client time will be updated based on the time offset information, otherwise the current time offset information will be discarded. Through this method, the application of erroneous time offset information can be effectively reduced, the client time jump caused by abnormal network fluctuations can be avoided, and the consistency and stability of the system time can be enhanced.
图5示出了本申请一实施例提供的一种时间同步系统的结构示意图,如图5所示,该时间同步系统包括客户端502和服务器504。FIG5 shows a schematic diagram of the structure of a time synchronization system provided in an embodiment of the present application. As shown in FIG5 , the time synchronization system includes a client 502 and a server 504 .
所述客户端502,被配置为基于时间同步指令向所述服务器504发送时间同步报文;The client 502 is configured to send a time synchronization message to the server 504 based on the time synchronization instruction;
所述服务器504,被配置为响应于所述时间同步报文向所述客户端502发送同步响应报文;The server 504 is configured to send a synchronization response message to the client 502 in response to the time synchronization message;
所述客户端502,进一步被配置为根据所述时间同步报文和所述同步响应报文计算与所述服务器之间的时间偏移信息;在确定所述时间偏移信息为异常信息的情况下,获取历史时间偏移信息;根据所述历史时间偏移信息确定参考时间偏移区间;在所述时间偏移信息满足所述参考时间偏移区间的情况下,基于所述时间偏移信息更新所述客户端的当前客户端时间。The client 502 is further configured to calculate the time offset information between the client and the server based on the time synchronization message and the synchronization response message; when it is determined that the time offset information is abnormal information, obtain historical time offset information; determine a reference time offset interval based on the historical time offset information; and when the time offset information satisfies the reference time offset interval, update the current client time of the client based on the time offset information.
通过本申请实施例提供的系统,在获得了当前次的时间同步指令,并计算客户端与服务器之间的时间偏移信息后,还要进一步的对时间偏移信息进行筛选,判断其是否为异常信息,若在确定时间偏移信息为异常信息的情况下,需要再根据历史时间偏移信息来进一步判断该时间偏移信息是否是正常范围内的网络波动。只有在时间偏移信息时正常范围内的网络波动的情况下,才会基于该时间偏移信息对当前客户端时间进行更新,否则就舍弃当前次的时间偏移信息。通过本方法,可以有效降低错误时间偏移信息的应用,避免因网络异常波动导致的客户端时间跳跃,增强了系统时间的连贯性和稳定性。Through the system provided by the embodiment of the present application, after obtaining the current time synchronization instruction and calculating the time offset information between the client and the server, the time offset information is further screened to determine whether it is abnormal information. If the time offset information is determined to be abnormal information, it is necessary to further determine whether the time offset information is a network fluctuation within a normal range based on the historical time offset information. Only when the network fluctuation is within the normal range when the time offset information is in the normal range, the current client time will be updated based on the time offset information, otherwise the current time offset information will be discarded. Through this method, the application of erroneous time offset information can be effectively reduced, the client time jump caused by abnormal network fluctuations can be avoided, and the consistency and stability of the system time can be enhanced.
上述为本实施例的一种时间同步装置的示意性方案。需要说明的是,该时间同步装置的技术方案与上述的时间同步方法的技术方案属于同一构思,时间同步装置的技术方案未详细描述的细节内容,均可以参见上述时间同步方法的技术方案的描述。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.
图6示出了根据本申请一实施例提供的一种计算设备600的结构框图。该计算设备600的部件包括但不限于存储器610和处理器620。处理器620与存储器610通过总线630相连接,数据库650用于保存数据。Fig. 6 shows a block diagram of a computing device 600 according to an embodiment of the present application. The components of the computing device 600 include but are not limited to a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and a database 650 is used to store data.
计算设备600还包括接入设备640,接入设备640使得计算设备600能够经由一个或多个网络660通信。这些网络的示例包括公用交换电话网(PSTN,Public SwitchedTelephone Network)、局域网(LAN,Local Area Network)、广域网(WAN,Wide AreaNetwork)、个域网(PAN,Personal Area Network)或诸如因特网的通信网络的组合。接入设备640可以包括有线或无线的任何类型的网络接口(例如,网络接口卡(NIC,networkinterface controller))中的一个或多个,诸如IEEE802.11无线局域网(WLAN,WirelessLocal Area Network)无线接口、全球微波互联接入(Wi-MAX,WorldwideInteroperability for Microwave Access)接口、以太网接口、通用串行总线(USB,Universal Serial Bus)接口、蜂窝网络接口、蓝牙接口、近场通信(NFC,Near FieldCommunication)接口,等等。The computing device 600 also includes an access device 640 that enables the computing device 600 to communicate via one or more networks 660. 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 640 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.
在本申请的一个实施例中,计算设备600的上述部件以及图6中未示出的其他部件也可以彼此相连接,例如通过总线。应当理解,图6所示的计算设备结构框图仅仅是出于示例的目的,而不是对本申请范围的限制。本领域技术人员可以根据需要,增添或替换其他部件。In one embodiment of the present application, the above components of the computing device 600 and other components not shown in FIG6 may also be connected to each other, for example, through a bus. It should be understood that the computing device structure block diagram shown in FIG6 is only for illustrative purposes 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.
计算设备600可以是任何类型的静止或移动计算设备,包括移动计算机或移动计算设备(例如,平板计算机、个人数字助理、膝上型计算机、笔记本计算机、上网本等)、移动电话(例如,智能手机)、可佩戴的计算设备(例如,智能手表、智能眼镜等)或其他类型的移动设备,或者诸如台式计算机或个人计算机(PC,Personal Computer)的静止计算设备。计算设备600还可以是移动式或静止式的服务器。The computing device 600 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 600 may also be a mobile or stationary server.
其中,处理器620用于执行如下计算机程序/指令,该计算机程序/指令被处理器执行时实现上述时间同步方法的步骤。The processor 620 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.
上述为本实施例的一种计算设备的示意性方案。需要说明的是,该计算设备的技术方案与上述的时间同步方法的技术方案属于同一构思,计算设备的技术方案未详细描述的细节内容,均可以参见上述时间同步方法的技术方案的描述。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.
本说明书一实施例还提供一种计算机可读存储介质,其存储有计算机程序/指令,该计算机程序/指令被处理器执行时实现上述时间同步方法的步骤。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.
上述为本实施例的一种计算机可读存储介质的示意性方案。需要说明的是,该存储介质的技术方案与上述的时间同步方法的技术方案属于同一构思,存储介质的技术方案未详细描述的细节内容,均可以参见上述时间同步方法的技术方案的描述。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.
本说明书一实施例还提供一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现上述时间同步方法的步骤。An embodiment of the present specification also 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.
上述为本实施例的一种计算机程序产品的示意性方案。需要说明的是,该计算机程序产品的技术方案与上述的时间同步方法的技术方案属于同一构思,计算机程序产品的技术方案未详细描述的细节内容,均可以参见上述时间同步方法的技术方案的描述。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.
上述对本申请特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。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.
所述计算机指令包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读介质包含的内容可以根据专利实践的要求进行适当的增减,例如在某些地区,根据专利实践,计算机可读介质不包括电载波信号和电信信号。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.
需要说明的是,对于前述的各方法实施例,为了简便描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其它顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定都是本申请所必须的。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.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。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.
以上公开的本申请优选实施例只是用于帮助阐述本申请。可选实施例并没有详尽叙述所有的细节,也不限制该发明仅为所述的具体实施方式。显然,根据本申请的内容,可作很多的修改和变化。本申请选取并具体描述这些实施例,是为了更好地解释本申请的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本申请。本申请仅受权利要求书及其全部范围和等效物的限制。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 (15)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411162825.3A CN118694464B (en) | 2024-08-23 | 2024-08-23 | Time synchronization method, device and system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411162825.3A CN118694464B (en) | 2024-08-23 | 2024-08-23 | Time synchronization method, device and system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN118694464A true CN118694464A (en) | 2024-09-24 |
| CN118694464B CN118694464B (en) | 2025-03-07 |
Family
ID=92774935
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202411162825.3A Active CN118694464B (en) | 2024-08-23 | 2024-08-23 | Time synchronization method, device and system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118694464B (en) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119154985A (en) * | 2024-11-11 | 2024-12-17 | 浙江大华技术股份有限公司 | Time synchronization method, terminal and computer readable storage medium |
| CN119766830A (en) * | 2025-03-06 | 2025-04-04 | 杭州浩联智能科技有限公司 | Data transmission method, device, equipment and medium |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2018202842A (en) * | 2017-06-09 | 2018-12-27 | キヤノン株式会社 | Information processing apparatus, information processing method, and program |
| CN112346512A (en) * | 2020-11-09 | 2021-02-09 | 北京沃东天骏信息技术有限公司 | Time synchronization method and device |
| GB2595881B (en) * | 2020-06-09 | 2023-01-11 | Canon Kk | Method for assessing synchronization between a communication device and a remote time server |
| CN117639997A (en) * | 2023-12-12 | 2024-03-01 | 中国人民解放军国防科技大学 | Network security time synchronization method and device |
| US20240179658A1 (en) * | 2021-03-30 | 2024-05-30 | Telefonaktiebolaget Lm Ericsson (Publ) | Methods and devices for time synchronization |
-
2024
- 2024-08-23 CN CN202411162825.3A patent/CN118694464B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2018202842A (en) * | 2017-06-09 | 2018-12-27 | キヤノン株式会社 | Information processing apparatus, information processing method, and program |
| GB2595881B (en) * | 2020-06-09 | 2023-01-11 | Canon Kk | Method for assessing synchronization between a communication device and a remote time server |
| CN112346512A (en) * | 2020-11-09 | 2021-02-09 | 北京沃东天骏信息技术有限公司 | Time synchronization method and device |
| US20240179658A1 (en) * | 2021-03-30 | 2024-05-30 | Telefonaktiebolaget Lm Ericsson (Publ) | Methods and devices for time synchronization |
| CN117639997A (en) * | 2023-12-12 | 2024-03-01 | 中国人民解放军国防科技大学 | Network security time synchronization method and device |
Non-Patent Citations (1)
| Title |
|---|
| 詹芝贤: "基于LTE-R的铁路时间同步技术研究", 《中国优秀硕士学位论文全文数据库 工程科技Ⅱ辑 2024年第01期》, 15 January 2024 (2024-01-15) * |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119154985A (en) * | 2024-11-11 | 2024-12-17 | 浙江大华技术股份有限公司 | Time synchronization method, terminal and computer readable storage medium |
| CN119766830A (en) * | 2025-03-06 | 2025-04-04 | 杭州浩联智能科技有限公司 | Data transmission method, device, equipment and medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN118694464B (en) | 2025-03-07 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN118694464A (en) | Time synchronization method, device and system | |
| EP3291551B1 (en) | Image delay detection method and system | |
| US20150156097A1 (en) | Time Monitor | |
| EP2378718B1 (en) | Method, node and system for controlling version in distributed system | |
| CN109392074B (en) | Clock calibration method and device | |
| JPWO2013094032A1 (en) | Information processing apparatus, information processing method, and program | |
| CN103842918A (en) | Time control device, time control method, and program | |
| US20180176872A1 (en) | Metered interface | |
| CN109634970A (en) | Table method of data synchronization, equipment, storage medium and device | |
| CN106717079B (en) | Clock synchronization using WIFI beacons | |
| CN119946076B (en) | Cross-platform communication sharing synchronization method and system | |
| JP7540507B2 (en) | Packet capture device, time stamp correction method, packet capture method, and packet capture program | |
| EP3598247B1 (en) | Network time correction method and apparatus | |
| US20250016184A1 (en) | Method and apparatus for determining click-farming in live room | |
| CN114328750A (en) | Method and device for synchronizing service data with ODS (oxide dispersion strengthened) layer | |
| CN118075531A (en) | Multi-screen spliced synchronous display method and device, electronic equipment and storage medium | |
| CN108900497B (en) | Method and system for data synchronization between heterogeneous systems | |
| CN118784138A (en) | Time synchronization method, device and system | |
| CN115801636A (en) | Delay calculation method, device and computer-readable storage medium | |
| WO2020238997A1 (en) | Time synchronization method, service board, and network device | |
| JP2022115505A (en) | Video-audio synchronization device, video-audio synchronization method, program | |
| US12306664B1 (en) | Dynamic precision time message rate support | |
| JP7659721B2 (en) | Audio reproduction method, apparatus, electronic device and storage medium | |
| CN113873344B (en) | Streaming media playing method, device and system | |
| JPH0756498A (en) | Plant maintenance support system |
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 |