NTP server selection method and device
By acquiring the network time-consuming of candidate NTP servers, determining the stability evaluation parameters, and selecting the most stable NTP server, the problem of large gap in equipment time synchronization in computer networks is solved, and the synchronization effect and vehicle performance accuracy are improved.
Patent Information
- Application Number
- CN202510707058.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-07-18
AI Technical Summary
In computer networks, traditional NTP server selection methods lead to poor device time synchronization effect, resulting in poor device operation effect. Especially in vehicle headlight performance, the gap in vehicle time synchronization is too large, affecting the performance effect.
By acquiring the network time consumption of candidate NTP servers, determining the stability evaluation parameters, selecting the most stable NTP server for time synchronization, reducing the network time consumption gap between devices.
Improve the accuracy and consistency of equipment time synchronization, ensuring that vehicle headlight performances are carried out in accordance with predetermined patterns, saving time and labor costs.
Smart Images

Figure CN120343058A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer networks, and particularly to a method and device for selecting an NTP server. Background Art
[0002] With the development of computer network technology, in order to meet the requirements of high-precision time synchronization of each device in the computer network in multiple fields such as financial transactions, scientific research, and car light shows, an NTP (Network Time Protocol Server) server has emerged. An NTP server is a server used to synchronize each device in the computer network. It obtains an accurate time signal by connecting to a high-precision time source, such as an atomic clock, a GPS (Global Positioning System) satellite, etc., and then transmits the time signal to each device in the computer network to help these devices calibrate the time, ensuring that each device in the computer network has a unified time standard and achieving time synchronization.
[0003] In traditional technologies, an NTP server is usually selected for time synchronization based on usage experience or randomly. However, due to the influence of various reasons such as physical distance, server performance, and network environment, in the process of time synchronization, there are often situations where the time calibration gaps of multiple devices are too large, resulting in poor time synchronization effects of each device in the computer network and seriously affecting the operation effects of each device.
[0004] Taking the car light show of multiple vehicles as an example, in the process of time synchronization of multiple vehicles, in some cases, the time calibration gap between different vehicles can reach 50 ms (milliseconds) or even more, resulting in multiple vehicles being unable to synchronously control the opening and closing of car lights according to the performance script, and making the car light show patterns completely chaotic. Based on this, when realizing time synchronization of multiple devices in the computer network, how to select an NTP server to reduce the time calibration gap between different devices has become an urgent problem to be solved. Summary of the Invention
[0005] Based on this, in view of the above technical problems, it is necessary to provide a method and device for selecting an NTP server, which can select a suitable NTP server to reduce the time calibration gap between different devices when realizing time synchronization of multiple devices in the computer network.
[0006] In a first aspect, the present application provides a method for selecting an NTP server, including:
[0007] Obtain the network latencies of multiple candidate Network Time Protocol (NTP) servers; wherein, the network latency of each candidate NTP server is determined based on the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time feedback by the candidate NTP server based on the time calibration request.
[0008] Determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the network latencies of multiple candidate NTP servers.
[0009] Select a target NTP server from each candidate NTP server according to the determined evaluation parameter; wherein, the target NTP server is used to synchronize the time of multiple vehicles.
[0010] In one embodiment, determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the network latencies of multiple candidate NTP servers includes: for each candidate NTP server, determining the standard deviation of the network latencies of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server; or, determining the data fluctuation characteristics of each group of network latencies of the candidate NTP server, and determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network latencies of the candidate NTP server; wherein, each group of network latencies includes at least two network latencies.
[0011] In one embodiment, determining the data fluctuation characteristics of each group of network latencies of the candidate NTP server includes: for each group of network latencies, determining a first deviation value between the maximum network latency and the average latency of the group of network latencies, and a second deviation value between the minimum network latency and the average latency of the group of network latencies as the data fluctuation characteristics of the group of network latencies.
[0012] In one embodiment, determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network latencies of the candidate NTP server includes: determining a first average value of the first deviation values corresponding to each group of network latencies of the candidate NTP server, and determining a second average value of the second deviation values corresponding to each group of network latencies of the candidate NTP server; determining an evaluation parameter for characterizing the stability of the candidate NTP server according to the sum of the first average value and the second average value.
[0013] In one embodiment, selecting a target NTP server from each candidate NTP server according to the determined evaluation parameter includes: determining the candidate NTP server with the minimum evaluation parameter among each candidate NTP server as the target NTP server.
[0014] In one embodiment, the method for selecting an NTP server further includes: determining the magnitude relationship between the total number of network time consumptions of each candidate NTP server and a preset quantity threshold; correspondingly, determining the standard deviation of the multiple network time consumptions of the candidate NTP servers includes: when the total number is greater than the preset quantity threshold, determining the standard deviation of the multiple network time consumptions of the candidate NTP servers; determining the data fluctuation characteristics of each group of network time consumptions of the candidate NTP servers includes: when the total number is not greater than the preset threshold, determining the data fluctuation characteristics of each group of network time consumptions of the candidate NTP servers.
[0015] In one embodiment, before obtaining the multiple network time consumptions of each candidate Network Time Protocol (NTP) server, the method further includes: sequentially sending multiple time calibration requests to each preset NTP server, so that the preset NTP server feeds back the server time based on each time calibration request; removing the first abnormal NTP servers from each preset NTP server to obtain each candidate NTP server; wherein, the first abnormal NTP servers include the preset NTP servers whose received quantity of server time is less than the sent quantity of time calibration requests.
[0016] In one embodiment, removing the first abnormal NTP servers from each preset NTP server to obtain each candidate NTP server includes: removing the first abnormal NTP servers and the second abnormal NTP servers from each preset NTP server to obtain each candidate NTP server; wherein, the second abnormal NTP servers include the preset NTP servers whose deviation value between the maximum network time consumption and the minimum network time consumption in the network time consumptions is greater than the network time consumption threshold.
[0017] In one embodiment, sequentially sending multiple time calibration requests to each preset NTP server includes: sequentially sending multiple ping commands to each preset NTP server; wherein, each ping command includes multiple time calibration requests.
[0018] In a second aspect, the present application further provides an NTP server selection device, including:
[0019] A time consumption acquisition module, configured to obtain the multiple network time consumptions of each candidate Network Time Protocol (NTP) server; wherein, the network time consumption of each candidate NTP server is determined according to the time stamp of sending a time calibration request to the candidate NTP server and the time stamp of receiving the server time fed back by the candidate NTP server based on the time calibration request.
[0020] A parameter determination module, configured to determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network time consumptions of each candidate NTP server.
[0021] An equipment selection module, configured to select a target NTP server from each candidate NTP server according to the determined evaluation parameters; wherein, the target NTP server is used to synchronize the time of multiple vehicles.
[0022] In a third aspect, the present application further provides a computer device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps of the methods provided in the embodiments of the first aspect are implemented.
[0023] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the methods provided in the embodiments of the first aspect are implemented.
[0024] In a fifth aspect, the present application further provides a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of the methods provided in the embodiments of the first aspect are implemented.
[0025] The above NTP server selection method and device, for each candidate NTP server, first determine multiple network latencies of the NTP server according to the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time feedback by the candidate NTP server based on the above time calibration request; then determine an evaluation parameter for characterizing the stability of the NTP server according to the multiple network latencies of the candidate NTP server. Furthermore, select a target NTP server from each candidate NTP server according to the evaluation parameter corresponding to each candidate NTP server for time synchronization of multiple vehicles. In this way, on the one hand, since the real network latencies of each candidate NTP server are statistically counted, the determined evaluation parameters for characterizing the stability of each candidate NTP server are more accurate; on the other hand, since the stability of the NTP server can reflect the distribution dispersion degree of the multiple network latencies of the NTP server, the smaller the distribution dispersion degree of the network latencies of the NTP server with better stability, that is, the more concentrated (the smaller the volatility) the network latencies of the NTP server with better stability. Therefore, when different devices use the NTP server with better stability for time synchronization, the network latency gap of time calibration of different devices is smaller. Therefore, selecting the target NTP server based on the evaluation parameter corresponding to each candidate NTP server can improve the reliability of the selected target NTP server, and further reduce the network latency gap of time calibration of different devices using the target NTP server, ensuring that the synchronization time error of each device is within a controllable range, enabling the services required to be executed by each device to proceed normally, and improving the operation effect. Further, the above target NTP server can be used for time synchronization of multiple vehicles. Thus, in the field of car light shows, the network latency gap of time calibration of different vehicles can be reduced, the time synchronization effect of multiple vehicles can be improved, ensuring that multiple vehicles synchronously control the opening and closing of car lights according to the performance script, enabling the car light show images to be displayed and transformed according to the performance script, ensuring the effect of the car light show, and saving the waste of time cost and labor cost caused by too large a time gap between vehicles. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments of the present application or related technologies. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0027] Figure 1 It is an application environment diagram of the NTP server selection method provided by some embodiments of the present application;
[0028] Figure 2Schematic flowchart of the NTP server selection method provided by some embodiments of the present application;
[0029] Figure 3 Schematic flowchart of the NTP server selection method provided by other embodiments of the present application;
[0030] Figure 4 Schematic flowchart of the NTP server selection method provided by still other embodiments of the present application;
[0031] Figure 5 Schematic flowchart of the process for determining evaluation parameters provided by some embodiments of the present application;
[0032] Figure 6 Schematic flowchart of the process for determining evaluation parameters provided by other embodiments of the present application;
[0033] Figure 7 Schematic flowchart of the NTP server selection method provided by still other embodiments of the present application;
[0034] Figure 8 Schematic flowchart of the NTP server selection method provided by yet other embodiments of the present application;
[0035] Figure 9 Block diagram of the structure of the NTP server selection device provided by some embodiments of the present application;
[0036] Figure 10 Internal structure diagram of the computer device provided by some embodiments of the present application. Detailed Description of the Invention
[0037] In order to make the objectives, technical solutions, and advantages of the present application more clearly understood, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0038] In the traditional technology, an NTP server is usually selected for time synchronization based on usage experience or randomly. However, due to the influence of various factors such as physical distance, server performance, and network environment, there is often a large difference in the network time consumption for time calibration among multiple devices during the time synchronization process. As a result, the time synchronization effect of each device in the computer network is poor, seriously affecting the operation effect of each device.
[0039] Based on this, when implementing time synchronization for multiple devices in a computer network, how to select an NTP server to reduce the time calibration difference between different devices has become an urgent problem to be solved.
[0040] To solve the above technical problems, in an exemplary embodiment, a method for selecting an NTP server is provided. This method can be applied to a computer device with functions such as data processing and analysis. The computer device can be presented in the form of a server or in the form of a terminal. Among them, the terminal can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. The portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The head-mounted device can be a virtual reality (VR) device, an augmented reality (AR) device, smart glasses, etc. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0041] In an exemplary embodiment, a method for selecting an NTP server provided by an embodiment of the present application can be applied to an application environment as Figure 1 shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or placed on the cloud or other network servers. Among them, the terminal 102 sends a time calibration request to each candidate NTP server, and determines the network delays of each candidate NTP server according to the timestamp when the time calibration request is sent and the timestamp when the server time based on the time calibration request is received from the candidate NTP server, and stores the above network delays in the data storage system. Then, the server 104 obtains the multiple delays of each candidate NTP server from the data storage system to execute a method for selecting an NTP server provided by an embodiment of the present application.
[0042] In an alternative embodiment, as Figure 2 shown, a method for selecting an NTP server is provided. Taking the server in Figure 1 as an example, the method includes the following steps:
[0043] S201, obtain the network delays of each candidate NTP server.
[0044] Among them, the network delay of each candidate NTP server is determined according to the timestamp when the time calibration request is sent to the candidate NTP server and the timestamp when the server time based on the time calibration request is received from the candidate NTP server.
[0045] A time calibration request generally refers to a request sent by a device or system to an NTP server to obtain accurate time and synchronize the local time; synchronizing the local time means resetting the local time to the server time when receiving the server time feedback from the NTP server based on the time calibration request; the server time refers to the current standard time obtained by the device or system at the NTP server side after synchronization through the NTP protocol. Its format and accuracy usually depend on the configuration of the NTP server and the protocol version. For example, the accuracy of an ordinary NTP server is usually at the millisecond (ms) level and is suitable for synchronizing the clocks of daily network devices and computers, while the accuracy of a high-precision NTP server (such as an NTP server connected to an atomic clock (cesium clock, rubidium clock) or GPS / Beidou) can reach the microsecond (μs) or even nanosecond (ns) level.
[0046] Optionally, when a device or system sends a time calibration request to an NTP server, it can record the timestamp of sending the above time calibration request according to the local time, and when receiving the server time feedback from the NTP server, record the timestamp of receiving the above server time according to the local time again. Then, based on the above two timestamps, determine the network latency of this time calibration of the device or system. For example, determine the time difference between the above two timestamps as the network latency of this time calibration of the device or system.
[0047] Based on this, in order to select a target NTP server for time synchronization of multiple vehicles, multiple candidate NTP servers can be selected first. Then, for each candidate NTP server, a specified device or system can be controlled to sequentially send multiple time calibration requests to this candidate NTP server, and for each time calibration request, record the timestamp of sending this time calibration request and the timestamp of receiving the server time feedback from this candidate NTP server based on this time calibration request. Thus, based on the above two timestamps (the timestamp of sending this time calibration request and the timestamp of receiving the server time feedback from this candidate NTP server based on this time calibration request), determine the network latency of this time calibration. In this way, for each candidate NTP server, the network latencies of multiple time calibrations can be determined as the multiple network latencies of this candidate NTP server. Then, the multiple network latencies of each candidate NTP server can be obtained. Among them, the number of network latencies of different candidate NTP servers is the same.
[0048] Optionally, for each candidate NTP server, multiple time calibration requests can be sent to this candidate NTP server one by one, that is, send multiple time calibration requests, and send one time calibration request each time.
[0049] In an optional embodiment, multiple ping commands can be sent to each candidate NTP server in sequence; each ping command includes multiple time calibration requests.
[0050] Among them, the above-mentioned specified device or system can be the execution entity (such as a server) of this NTP server selection method, or other devices or systems independent of the execution entity of this NTP server selection method (such as any one of multiple vehicles to be time-synchronized subsequently, other servers).
[0051] Optionally, the present application does not limit the selection method of the above-mentioned candidate NTP servers. For example, multiple candidate NTP servers can be selected according to the historical experience of using various NTP servers before; multiple candidate NTP servers whose distances from the geographical location where the multiple vehicles to be time-synchronized are located do not exceed a preset distance can also be selected, where the above-mentioned preset distance can be determined according to the historical experience of using various NTP servers before; multiple candidate NTP servers can also be selected in ascending order of the distances from their locations to the geographical location where the multiple vehicles are located; multiple candidate NTP servers with better server performance can also be selected according to the server performance of various available NTP servers known. Of course, the factors such as the above physical distance, server performance, and network environment can also be comprehensively considered to select multiple candidate NTP servers. In addition, the present application also does not limit the number of the above-mentioned multiple candidate NTP servers, which can be limited according to empirical values, experimental values of multiple tests, and requirements of actual application scenarios.
[0052] Optionally, in order to improve the reliability of the determined target NTP server, multiple network time consumptions of each candidate NTP server within the time same as or close to the time of the actual application scenario of time synchronization of multiple vehicles can be obtained according to the time of the actual application scenario of time synchronization of multiple vehicles. For example, if it is desired to perform time synchronization on multiple vehicles between 8:00 pm and 9:00 pm on May 31, 2025 for a headlight show, then between 8:00 pm and 9:00 pm on May 30, 2025, a suitable time (such as 8:30 pm) can be selected to obtain the multiple network time consumptions of each candidate NTP server, so as to select the target NTP server from multiple candidate NTP servers. In this way, the influence of factors such as the network environment on the stability of the NTP server within different time ranges can be fully considered, the reliability of the determined target NTP server can be further improved, the network time consumption gap of different devices using the target NTP server for time calibration can be further reduced, and further, the synchronization time error of each device can be ensured to be within a controllable range, so that the services that each device needs to execute can proceed normally and the operation effect can be improved.
[0053] S202. Determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network time consumptions of each candidate NTP server.
[0054] As described above, the stability of the NTP server can reflect the degree of distribution dispersion of the network latency of the NTP server. The better the stability of the NTP server, the smaller the degree of distribution dispersion of the network latency, that is, the more concentrated (less volatile) the multiple network latencies of the NTP server with better stability. Therefore, when different devices use the NTP server with better stability for time synchronization, the difference in network latency for time calibration among different devices is smaller. Therefore, the target server can be selected from each candidate NTP server according to the stability of each candidate NTP server.
[0055] Based on this, after obtaining the multiple network latencies of each candidate NTP server, for each candidate NTP server, an evaluation parameter for characterizing the stability of the candidate NTP server can be determined according to the multiple network latencies of the candidate NTP server, and used as the evaluation parameter corresponding to the candidate NTP server.
[0056] Optionally, the above evaluation parameter can be but is not limited to the standard deviation of multiple network latencies, the variance of multiple network latencies, the mean absolute deviation (MAD) of multiple network latencies, or the range of multiple network latencies. In this regard, no specific limitation is made. As long as the evaluation parameter can characterize the stability of the candidate NTP server and thus reflect the degree of distribution dispersion of the multiple network latencies of the candidate NTP server, it falls within the protection scope of this application.
[0057] S203. Select the target NTP server from each candidate NTP server according to the determined evaluation parameter.
[0058] Among them, the target NTP server is used to synchronize the time of multiple vehicles.
[0059] As described above, the target server can be selected from each candidate NTP server according to the stability of each candidate NTP server. Since the above evaluation parameter is used to characterize the stability of the candidate NTP server, after determining the evaluation parameter corresponding to each candidate NTP server, the target NTP server can be selected from each candidate NTP server according to the determined evaluation parameter.
[0060] In an optional embodiment, when the larger the evaluation parameter, the higher the stability it represents, the candidate NTP server with the largest corresponding evaluation parameter is selected from each candidate NTP server as the target NTP server. For example, when the reciprocal of the standard deviation is used as the evaluation parameter, the candidate NTP server with the largest corresponding evaluation parameter can be selected from each candidate NTP server as the target NTP server.
[0061] In another alternative embodiment, when the evaluation parameter is smaller, the higher the represented stability is. Among the candidate NTP servers, the candidate NTP server corresponding to the smallest evaluation parameter is selected as the target NTP server. For example, when the standard deviation is used as the evaluation parameter, the candidate NTP server corresponding to the smallest evaluation parameter can be selected from the candidate NTP servers as the target NTP server.
[0062] Optionally, the selected target NTP server can be used to synchronize the time of multiple vehicles. In this way, in the field of vehicle light shows, the network time-consuming gap for time calibration of different vehicles can be reduced, the time synchronization effect of multiple vehicles can be improved, and it is ensured that multiple vehicles synchronously control the opening and closing of vehicle lights according to the performance script, so that the vehicle light show images are displayed and transformed according to the performance script, ensuring the effect of the vehicle light show and saving the waste of time cost and labor cost caused by inconsistent times of each vehicle.
[0063] The above NTP server selection method, for each candidate NTP server, first determines multiple network latencies of the NTP server according to the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time fed back by the candidate NTP server based on the above time calibration request; then determines an evaluation parameter for characterizing the stability of the NTP server according to the multiple network latencies of the candidate NTP server. Furthermore, according to the evaluation parameter corresponding to each candidate NTP server, a target NTP server is selected from each candidate NTP server for time synchronization of multiple vehicles. In this way, on the one hand, since the actual network latencies of each candidate NTP server are statistically analyzed, the evaluation parameters determined for characterizing the stability of each candidate NTP server are more accurate; on the other hand, since the stability of the NTP server can reflect the distribution dispersion degree of the multiple network latencies of the NTP server, the smaller the distribution dispersion degree of the network latencies of the NTP server with better stability, that is, the more concentrated (less volatile) the network latencies of the NTP server with better stability. Therefore, when different devices use the NTP server with better stability for time synchronization, the difference in network latencies for time calibration of different devices is smaller. Therefore, based on the evaluation parameters corresponding to each candidate NTP server, the target NTP server is selected, which can improve the reliability of the selected target NTP server, and further reduce the difference in network latencies for time calibration of different devices using the target NTP server, ensuring that the synchronization time error of each device is within a controllable range, enabling the services that each device needs to execute to proceed normally, and improving the operation effect. Further, the above target NTP server can be used for time synchronization of multiple vehicles. Thus, in the field of vehicle light shows, the difference in network latencies for time calibration of different vehicles can be reduced, the time synchronization effect of multiple vehicles can be improved, ensuring that multiple vehicles synchronously control the opening and closing of vehicle lights according to the performance script, enabling the vehicle light show images to be displayed and transformed according to the performance script, ensuring the effect of the vehicle light show, and saving the waste of time cost and labor cost caused by too large a time difference between vehicles.
[0064] Based on the above embodiments, in an exemplary embodiment, as Figure 3 shown, the NTP server selection method may include the following steps:
[0065] S301, sequentially send multiple time calibration requests to each preset NTP server, so that the preset NTP server feeds back the server time based on each time calibration request.
[0066] In order to select a target NTP server from each candidate NTP server, it is necessary to first determine multiple candidate NTP servers. Among them, multiple NTP servers can be first selected from various available NTP servers as preset NTP servers according to factors such as physical distance, server performance, and network environment.
[0067] For example, multiple preset NTP servers can be selected based on the historical experience of using various NTP servers before; multiple preset NTP servers whose distance from the geographical location where the multiple vehicles to be time-synchronized are located does not exceed a preset distance can also be selected according to the geographical locations of the multiple vehicles, where the above preset distance can be determined based on the historical experience of using various NTP servers before; multiple preset NTP servers can also be selected in ascending order of the distance from their locations to the geographical locations where the multiple vehicles are located; multiple preset NTP servers with better server performance can also be selected according to the server performance of various available NTP servers known. Of course, multiple preset NTP servers can also be selected by comprehensively considering the above factors of physical distance, server performance, and network environment.
[0068] Among them, the above examples are only illustrative examples of the selection methods of multiple preset NTP servers, rather than limitations. Any method capable of selecting multiple preset NTP servers belongs to the protection scope of this application. Moreover, this application also does not limit the number of the above multiple preset NTP servers, which can be determined according to empirical values, test values, etc. For example, it can be 4, etc.
[0069] After multiple preset NTP servers are selected, multiple time calibration requests can be sequentially sent to each preset NTP server so that the preset NTP server feeds back the server time based on each time calibration request. Among them, for each preset NTP server, for each time calibration request sent to this preset NTP server, the timestamp when this time calibration request is sent can be recorded. Then, this preset NTP server can feed back the server time based on this time calibration request, and the timestamp when the server time fed back by this preset NTP server based on this time calibration request is received can be recorded. Furthermore, based on the above two timestamps (the timestamp when the time calibration request is sent and the timestamp when the server time fed back by this preset NTP server based on this time calibration request is received), the network latency corresponding to this time calibration request can be determined as a network latency of this preset NTP server.
[0070] Optionally, for each preset NTP server, multiple time calibration requests can be sent to this preset NTP server one by one, that is, multiple time calibration requests are sent, and each time one time calibration request is sent.
[0071] In an alternative embodiment, the sending of the multiple time calibration requests in S301 is further refined. Thus, the above S301 can include sending multiple ping commands to each preset NTP server in sequence; where each ping command includes multiple time calibration requests.
[0072] In this embodiment, since the ping command is a classic tool for testing network connectivity, it judges the network connection status by sending ICMP (Internet Control Message Protocol) echo request packets to the target host and waiting for a response. Therefore, a time calibration request can be sent to the preset NTP server through the ping command. Among them, for each preset NTP server, multiple ping commands can be sequentially sent to the preset NTP server, and each ping command includes multiple time calibration requests. After receiving each ping command, the preset NTP server is equivalent to receiving multiple time calibration requests, and the preset NTP server can sequentially feedback the server time based on each time calibration request among the multiple time calibration requests to determine the multiple network latencies of the preset NTP server.
[0073] For example, if each ping command includes four time calibration requests, after receiving each ping command, the preset NTP server will sequentially feedback the server time based on each of the four time calibration requests included in the ping command, so that the four network latencies of the preset NTP server can be determined.
[0074] That is to say, for each preset NTP server, if each ping command includes N time calibration requests and M ping commands are sequentially sent to the preset NTP server, then when the preset NTP server is working properly, the number of server times feedback by the preset NTP server received is M * N, and then the M * N network latencies of the preset NTP server can be determined. Among them, M is a positive integer, and N is a positive integer greater than 1.
[0075] Optionally, since each ping command includes multiple time calibration requests, a ping command can also be sent to each preset NTP server.
[0076] S302, eliminate the first abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server.
[0077] Among them, the first abnormal NTP server includes a preset NTP server whose received number of server times is less than the sent number of time calibration requests.
[0078] It can be understood that under normal circumstances, for each preset NTP server, the number of sent time calibration requests should be the same as the number of server times feedback by the preset NTP server received.
[0079] However, in some cases, due to network fluctuations or other reasons, after sending a time calibration request to a preset NTP server, it may not be possible to receive the server time feedback by the preset NTP server based on the time calibration request, resulting in a difference between the number of time calibration requests sent to the preset NTP server and the number of server times feedback by the preset NTP server. For example, the number of server times feedback by the preset NTP server received is less than the number of time calibration requests sent to the preset NTP server. Furthermore, among multiple preset NTP servers, the preset NTP server with the number of received server times less than the number of sent time calibration requests can be used as the first abnormal NTP server.
[0080] Among them, for each time calibration request sent to a preset NTP server, in the case where the server time feedback by the preset NTP server based on this time calibration request is not received, this time calibration request can be determined as a time calibration request that fails. Thus, it can also be considered that the first abnormal NTP server includes the preset NTP server with a time calibration request that fails among the multiple received time calibration requests.
[0081] Undoubtedly, in order to ensure the effect of time synchronization of multiple vehicles by the selected target NTP server subsequently, it is first necessary to ensure that the selected target NTP server can normally respond to the time calibration request, that is, it can normally feedback the server time when receiving the time calibration request. Therefore, the above first abnormal NTP server cannot be selected as the NTP server, and further, the above first abnormal NTP server cannot be used as a candidate NTP server to avoid being misselected as the target NTP server.
[0082] Based on this, after sending multiple time calibration requests to each preset NTP server in turn to make the preset NTP server feedback the server time based on each time calibration request, the first abnormal NTP servers in each preset NTP server can be excluded. Furthermore, after excluding the first abnormal NTP servers from each preset NTP server, the remaining preset NTP servers can be used as candidate NTP servers.
[0083] For example, as shown below, in the case of sending four ping commands to a preset NTP server in turn, and each ping command includes four time calibration requests, the multiple network delays (16 network delays) obtained for the preset NTP servers A, B, C, and D are assumed that the network delay threshold is 45 milliseconds.
[0084] 1) Preset NTP server A:
[0085] For the first ping command, the obtained network delays are: 149ms, 92ms, 90ms, and 94ms.
[0086] For the second ping command, the network latencies obtained are: 94ms, 115ms, 90ms, and 91ms.
[0087] For the third ping command, the network latencies obtained are: 91ms, 92ms, 92ms, and 99ms.
[0088] For the fourth ping command, the network latencies obtained are: 91ms, 102ms, 92ms, and 91ms.
[0089] 2) Preset NTP server B:
[0090] For the first ping command, the network latencies obtained are: 30ms, 28ms, 28ms, and 28ms.
[0091] For the second ping command, the network latencies obtained are: 28ms, 28ms, 35ms, and 28ms.
[0092] For the third ping command, the network latencies obtained are: 78ms, 33ms, 33ms, and 28ms.
[0093] For the fourth ping command, the network latencies obtained are: 28ms, 32ms, 28ms, and 28ms.
[0094] 3) Preset NTP server C:
[0095] For the first ping command, the network latencies obtained are: 220ms, 240ms, 222ms, and 220ms.
[0096] For the second ping command, the network latencies obtained are: 235ms, 221ms, and 209ms, and the fourth calibration request fails (request timeout).
[0097] For the third ping command, the network latencies obtained are: 225ms, 226ms, 226ms, and 225ms.
[0098] For the fourth ping command, the network latencies obtained are: 226ms, 226ms, 225ms, and 225ms.
[0099] 4) Preset NTP server D:
[0100] For the first ping command, the network latencies obtained are: 29ms, 27ms, 26ms, and 25ms.
[0101] For the second ping command, the network latency obtained is: 26ms, 25ms, 25ms, and 25ms respectively.
[0102] For the third ping command, the network latency obtained is: 26ms, 25ms, 26ms, and 28ms respectively.
[0103] For the fourth ping command, the network latency obtained is: 25ms, 25ms, 27ms, and 25ms respectively.
[0104] Based on this, for the above-mentioned preset NTP servers A, B, C, and D, among them, there is a time synchronization request that fails in the time synchronization requests corresponding to the preset NTP server C (the fourth time synchronization request in the second ping command). Therefore, the preset NTP server C is the first abnormal NTP server. Based on this, the preset NTP server C among the above-mentioned preset NTP servers A, B, C, and D is removed, and the remaining preset NTP servers A, B, and D are determined as candidate NTP servers, obtaining two candidate NTP servers A, B, and D.
[0105] In an alternative embodiment, after the first abnormal NTP server is proposed from each preset NTP server, in the case where only one preset NTP server remains, the remaining NTP server can be determined as the target NTP server.
[0106] S303, obtain the multiple network latencies of each candidate Network Time Protocol (NTP) server.
[0107] As described above, in the case of sequentially sending multiple time synchronization requests to each preset NTP server, the timestamp of sending the time synchronization request and the timestamp of receiving the server time feedback by the preset NTP server based on the time synchronization request can be determined, and the multiple network latencies of each preset NTP server can be determined. Then, after determining each candidate NTP server from each preset NTP server, the multiple network latencies of each candidate NTP server can be directly obtained.
[0108] S304, determine the evaluation parameter used to characterize the stability of the corresponding candidate NTP server according to the multiple network latencies of each candidate NTP server.
[0109] S305, select the target NTP server from each candidate NTP server according to the determined evaluation parameter.
[0110] Among them, the specific implementation manners of the above S304 - S305 are the same as those of the above S202 - S203, and will not be elaborated here.
[0111] In this embodiment, according to the magnitude relationship between the number of received server times and the number of sent time calibration requests, the first abnormal NTP servers among the preset NTP servers are excluded, which can prevent the first abnormal NTP servers from being misselected as the target NTP servers, avoid the situation where the synchronous time calibration of multiple vehicles fails, and thus avoid the waste of time cost and labor cost. Moreover, the execution entity of this NTP server selection method determines each candidate NTP server and obtains the multiple network time consumptions of each candidate NTP server, which can avoid data interaction between other devices or systems and the execution entity of this NTP server selection method, save the resources and time consumed by server selection, and improve the efficiency of NTP server selection.
[0112] Based on the above embodiments, in an exemplary embodiment, optionally, as Figure 4 shown, this NTP server selection method may include the following steps:
[0113] S401. Send multiple time calibration requests to each preset NTP server in sequence, so that the preset NTP server feeds back the server time based on each time calibration request.
[0114] Among them, the specific implementation manner of the above S401 is the same as that of the above S301, and will not be elaborated here.
[0115] S402. Exclude the first abnormal NTP servers and the second abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server.
[0116] Among them, the second abnormal NTP servers include the preset NTP servers whose deviation value between the maximum network time consumption and the minimum network time consumption in the network time consumption is greater than the network time consumption threshold.
[0117] As mentioned above, there may be first abnormal NTP servers among the preset NTP servers. Further, there may also be preset NTP servers with relatively large differences in network time consumption among the preset NTP servers, then it can be considered that the distribution dispersion degree of the network time consumption of these preset NTP servers is relatively large, and further it can be considered that the stability of these preset NTP servers is relatively poor.
[0118] Based on this, in order to ensure the effect of time synchronization of multiple vehicles by the subsequently selected target NTP server, reduce the network time consumption gap of different vehicles using the target NTP server for time calibration, and avoid the synchronous time error of multiple vehicles exceeding the controllable range and affecting the service execution effect of multiple vehicles, it is necessary to prevent the preset NTP servers with relatively poor stability from being selected as the target NTP servers. Furthermore, the preset NTP servers with relatively poor stability cannot be used as candidate NTP servers to avoid being misselected as the target NTP servers.
[0119] Among them, the stability of each preset NTP server can be preliminarily screened by the range of the network time consumption of multiple network time consumptions of each preset NTP server. The so-called range is the difference between the maximum value and the minimum value in the data, which can reflect the value range of the data and is used to roughly evaluate the data fluctuation situation. That is to say, for each preset NTP server, the deviation value between the maximum network time consumption and the minimum network time consumption among the multiple network time consumptions of the preset NTP server is the range of the multiple network time consumptions of the preset NTP server. Furthermore, among the preset NTP servers, the preset NTP servers with the deviation value between the maximum network time consumption and the minimum network time consumption in the network time consumption greater than the network time consumption threshold can be used as the second abnormal NTP servers.
[0120] The above network time consumption threshold can be set according to empirical values, experimental values of multiple tests, application scenario requirements for time synchronization of multiple vehicles, etc., and no specific limitation is made here. For example, in the field of headlight shows, the above network time consumption threshold can be determined according to the sensitivity of the human eye to scene changes. Exemplarily, in the field of headlight shows, the above network time consumption threshold can be 40 milliseconds.
[0121] Based on this, after sequentially sending multiple time calibration requests to each preset NTP server so that the preset NTP server feeds back the server time based on each time calibration request, the first abnormal NTP server and the second abnormal NTP server in each preset NTP server can be excluded. Then, after excluding the first abnormal NTP server and the second abnormal NTP server from each preset NTP server, the remaining preset NTP servers can be used as each candidate NTP server.
[0122] Optionally, the first abnormal NTP server in each preset NTP server can be excluded first, and then the second abnormal NTP server in the remaining preset NTP servers can be excluded to obtain each candidate NTP server.
[0123] Optionally, the second abnormal NTP server in each preset NTP server can be excluded first, and then the first abnormal NTP server in the remaining preset NTP servers can be excluded to obtain each candidate NTP server.
[0124] Optionally, the first abnormal NTP server and the second abnormal NTP server in each preset NTP server can be excluded simultaneously to obtain each candidate NTP server.
[0125] It can be understood that in some cases, there is a preset NTP server that is both the first abnormal NTP server and the second abnormal NTP server. For example, among the multiple time calibration requests received by a preset NTP server, there are time calibration requests that fail. Moreover, among the network time consumptions of the successfully requested time calibration requests of this preset NTP server, the deviation value between the maximum network time consumption and the minimum network time consumption is greater than the network time consumption threshold.
[0126] For example, for the preset NTP servers A, B, C, and D as exemplified above, among them, there is a time calibration request that fails in the time calibration requests corresponding to the preset NTP server C (the fourth time calibration request in the second ping command). Therefore, the preset NTP server C is the first abnormal NTP server; the maximum network time consumption of the preset NTP server A is 149 ms, and the minimum network time consumption is 90 ms. Then, the deviation value between the maximum network time consumption and the minimum network time consumption of the preset NTP server A is 59 milliseconds, which is greater than the network time consumption threshold (45 milliseconds). Therefore, the preset NTP server A is the second abnormal NTP server. Based on this, the preset NTP server A and the preset NTP server C among the above preset NTP servers A, B, C, and D are excluded, and the remaining preset NTP servers B and D are determined as candidate NTP servers, obtaining two candidate NTP servers B and D.
[0127] In an optional embodiment, after the first abnormal NTP server and the second abnormal NTP server are proposed from each preset NTP server, when there is only one remaining preset NTP server, the remaining NTP server can be determined as the target NTP server.
[0128] S403. Obtain the multiple network time consumptions of each candidate Network Time Protocol (NTP) server.
[0129] S404. Determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network time consumptions of each candidate NTP server.
[0130] S405. Select a target NTP server from each candidate NTP server according to the determined evaluation parameter.
[0131] Among them, the specific implementation manners of the above S403 - S405 are the same as those of the above S303 - S305, and will not be elaborated here.
[0132] In this embodiment, according to the relationship between the deviation value of the maximum network latency and the minimum network latency in the network latency and the network latency threshold, the second abnormal NTP servers among the preset NTP servers are eliminated, which can initially screen the stability of each preset NTP server, avoid misselecting the second abnormal NTP servers as the target NTP servers, and further avoid wasting time and labor costs caused by excessive time differences among vehicles. On this basis, the number of candidate NTP servers is further reduced, and then the amount of network latency data to be processed in the subsequent determination of evaluation parameters is reduced, so as to reduce the time and computing resources consumed in the server selection process and further improve the efficiency of NTP server selection.
[0133] Based on the above embodiments, in an exemplary embodiment, the determination of the evaluation parameters in S202 above is further refined. Then, in S202 above, according to the multiple network latencies of each candidate NTP server, determining the evaluation parameter for characterizing the stability of the corresponding candidate NTP server may include, for each candidate NTP server, determining the standard deviation of the multiple network latencies of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server.
[0134] In this embodiment, for each candidate NTP server, the standard deviation of the multiple network latencies of the candidate NTP server can be determined as the evaluation parameter for characterizing the stability of the candidate NTP server.
[0135] Among them, for each candidate NTP server, the determination process of the standard deviation of the multiple network latencies of the candidate NTP server may include the following process: determining the average value of the multiple network latencies as the first average value; determining the square of the difference between each network latency and the above first average value; determining the average value of each square as the second average value; determining the square root of the above second average value. The determined square root is the standard deviation of the multiple network latencies of the candidate NTP server.
[0136] Correspondingly, in this embodiment, since the smaller the standard deviation, the smaller the degree of dispersion of the data it reflects. Therefore, for each candidate NTP server, the smaller the standard deviation of the multiple network latencies of the candidate NTP server, the higher the stability of the NTP server characterized by the standard deviation. Therefore, in S203 above, selecting the target NTP server from each candidate NTP server according to the determined evaluation parameter may include determining the candidate NTP server with the smallest evaluation parameter among each candidate NTP server as the target NTP server.
[0137] For example, as previously exemplified, candidate NTP servers A, B, and D are determined.
[0138] For candidate NTP server A, it can be determined that the standard deviation of multiple network latency times of candidate NTP server A is 14.64, that is, the evaluation parameter characterizing the stability of candidate NTP server A is 14.64.
[0139] For candidate NTP server B, it can be determined that the standard deviation of multiple network latency times of candidate NTP server B is 4, that is, the evaluation parameter characterizing the stability of candidate NTP server A is 4.
[0140] For candidate NTP server D, it can be determined that the standard deviation of multiple network latency times of candidate NTP server B is 1.14, that is, the evaluation parameter characterizing the stability of candidate NTP server A is 1.14.
[0141] Then, select candidate NTP server D as the target NTP server.
[0142] In this embodiment, since when determining the standard deviation of multiple network latency times of each candidate NTP server, the contributions of all data in the multiple network latency times are included, the influence of extreme values and intermediate values in the multiple network latency times can be avoided, thereby, the actual distribution dispersion degree of the multiple network latency times can be more truly reflected, and further, the stability of each candidate NTP server can be more accurately characterized, and the reliability of the finally determined target NTP server can be further improved.
[0143] Based on the above embodiments, in an exemplary embodiment, the determination of the evaluation parameter in S202 above is further refined. As Figure 5 shown, the following steps may be included:
[0144] S501, for each candidate NTP server, determine the data fluctuation characteristics of each group of network latency times of the candidate NTP server.
[0145] Wherein, each group of network latency times includes at least two network latency times.
[0146] For each candidate NTP server, the groups of network latency times of the candidate NTP server can be first determined, and then the data fluctuation characteristics of each group of network latency times of the candidate NTP server can be determined.
[0147] In this embodiment, the so-called data fluctuation characteristics refer to the dispersion degree, change law and irregularity presented by the data during the distribution and change process, reflecting the stability, randomness and predictability of the data.
[0148] Optionally, the above data fluctuation characteristics may, but are not limited to, be the absolute average difference of multiple network latencies (i.e., the average of the absolute differences between all network latencies and the average of multiple network latencies), the Median Absolute Deviation (MAD) (i.e., the median of the absolute differences between all network latencies and the median of multiple network latencies), or the Coefficient of Range (i.e., the ratio of the difference between the maximum network latency and the minimum network latency among multiple network latencies to the sum of the maximum network latency and the minimum network latency). In this regard, no specific limitation is made, as long as the parameters that can characterize the data fluctuation characteristics of the multiple network latencies of the candidate NTP servers fall within the protection scope of this application.
[0149] In an optional embodiment, to further refine the determination of the data fluctuation characteristics in S501 above, S501 may include, for each group of network latencies, determining a first deviation value between the maximum network latency and the average latency in this group of network latencies, and a second deviation value between the minimum network latency and the average latency in this group of network latencies, as the data fluctuation characteristics of this group of network latencies.
[0150] In this embodiment, for each candidate NTP server, after determining each group of network latencies of this candidate NTP server, for each group of network latencies, the average latency of this group of network latencies may be determined first; then, a first deviation value between the maximum network latency and the above average latency in this group of network latencies, and a second deviation value between the minimum network latency and the above average latency in this group of network latencies may be determined. In this way, the above first deviation value and second deviation value may be used as the data fluctuation characteristics of this group of network latencies.
[0151] Optionally, for each candidate NTP server, the multiple network latencies of this candidate NTP server may be evenly divided into multiple groups to obtain multiple groups of network latencies of this candidate NTP server. Among them, each group of network latencies includes at least two network latencies, and the number of groups of network latencies of different candidate NTP servers and the specific number of network latencies included in each group of network latencies are the same.
[0152] Among them, the specific number of each group of network latencies and / or the determined number of groups of network latencies may both be determined according to the total number of multiple network latencies, empirical values, experimental values of multiple tests, and the requirements of the actual application scenario. In this regard, no specific limitation is made. For example, the specific number of each group of network latencies is 4, and the number of groups of network latencies is 4, etc.
[0153] Optionally, when multiple time calibration requests are sent to each candidate NTP server through the ping command, so that the candidate NTP server feeds back the server time based on each time calibration request, and then the network delays of the candidate NTP server are determined, the multiple network delays determined based on the candidate NTP server's response to each ping command can be divided into a group of network delays. In this way, the specific number of network delays included in each group of network delays of each candidate NTP server is the same as the number of time calibration requests included in each ping command, and the number of groups of network delays of each candidate NTP server is the same as the total number of ping commands received.
[0154] S502. For each candidate NTP server, according to the data fluctuation characteristics of each group of network delays of the candidate NTP server, determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server.
[0155] For each candidate NTP server, after determining the data fluctuation characteristics of each group of network delays of the candidate NTP server, an evaluation parameter for characterizing the stability of the candidate NTP server can be further determined according to the data fluctuation characteristics of each group of network delays of the candidate NTP server.
[0156] Optionally, for each candidate NTP server, the average value of the data fluctuation characteristics of each group of network delays of the candidate NTP server can be determined as an evaluation parameter for characterizing the stability of the candidate NTP server. For each candidate NTP server, the average absolute deviation of the data fluctuation characteristics of each group of network delays of the candidate NTP server can also be determined as an evaluation parameter for characterizing the stability of the candidate NTP server. In this regard, there is no specific limitation, as long as the evaluation parameter that can be determined according to the data fluctuation characteristics of each group of network delays to characterize the stability of the candidate NTP server and thus reflect the distribution dispersion degree of the multiple network delays of the candidate NTP server falls within the protection scope of this application.
[0157] Correspondingly, in an optional embodiment, for each candidate NTP server, since the smaller the evaluation parameter corresponding to the candidate NTP server determined in S502 above, the higher the stability of the NTP server characterized by the evaluation parameter, therefore, S203 above, selecting the target NTP server from each candidate NTP server according to the determined evaluation parameter can include determining the candidate NTP server with the smallest evaluation parameter among each candidate NTP server as the target NTP server.
[0158] In this embodiment, by grouping the multiple network time consumptions of each candidate NTP server and determining the data fluctuation characteristics of each group of network time consumptions, the stability used to characterize the corresponding candidate NTP server can be determined, and the internal structure of the data of the multiple network time consumptions of each candidate NTP server can be captured, avoiding the overall characteristics of the multiple network time consumptions from masking the local differences within the multiple network time consumptions. Therefore, the evaluation accuracy and robustness of the determined evaluation parameter for the distribution dispersion degree of the multiple network time consumptions can be improved, and then the actual distribution dispersion degree of the multiple network time consumptions can be more truly reflected, the stability of each candidate NTP server can be more accurately characterized, and the reliability of the finally determined target NTP server can be further improved.
[0159] Based on the above embodiments, in an exemplary embodiment, the determination of the evaluation parameter in S502 is further refined. Optionally, as Figure 6 shown, the following steps may be included:
[0160] S601, for each candidate NTP server, determine the first average value of the first deviation values corresponding to each group of network time consumptions of the candidate NTP server, and determine the second average value of the second deviation values corresponding to each group of network time consumptions of the candidate NTP server.
[0161] In this embodiment, for each candidate NTP server, first determine the network time consumptions of each group of the candidate NTP server; then, for each group of network time consumptions, first determine the average time consumption of the group of network time consumptions; then determine the first deviation value between the maximum network time consumption and the above average time consumption in the group of network time consumptions, and the second deviation value between the minimum network time consumption and the above average time consumption in the group of network time consumptions; then use the above first deviation value and second deviation value as the data fluctuation characteristics of the group of network time consumptions.
[0162] In this way, for each candidate NTP server, after obtaining the data fluctuation characteristics of each group of network time consumptions of the candidate NTP server, the first average value of the first deviation values corresponding to each group of network time consumptions of the candidate NTP server can be determined, and the second average value of the second deviation values corresponding to each group of network time consumptions of the candidate NTP server can be determined.
[0163] S602, for each candidate NTP server, determine the evaluation parameter used to characterize the stability of the candidate NTP server according to the sum of the first average value and the second average value.
[0164] Furthermore, for each candidate NTP server, after determining the above first average value and second average value, the evaluation parameter used to characterize the stability of the candidate NTP server can be determined according to the sum of the first average value and the second average value.
[0165] Optionally, for each candidate NTP server, the sum value of the above first average value and the second average value can be determined as an evaluation parameter for characterizing the stability of the candidate NTP server.
[0166] Optionally, for each candidate NTP server, the weighted sum value of the above first average value and the second average value can be determined as an evaluation parameter for characterizing the stability of the candidate NTP server. Specifically, the first weight of the first average value and the second weight of the second average value can be preset in advance, so as to determine the first product of the first average value and the first weight, and the second product of the second average value and the second weight, and then determine the sum value of the first product and the second product as an evaluation parameter for characterizing the stability of the candidate NTP server. Among them, the above first weight can be set according to empirical values, test values of multiple tests, and the requirements of the actual application scenario. For example, both the first weight and the second weight are 0.5, the first weight is 0.8 and the second weight is 0.2, etc., and no specific limitation is made in this regard.
[0167] Correspondingly, in an optional embodiment, for each candidate NTP server, since the smaller the evaluation parameter corresponding to the candidate NTP server determined in S502 above, the higher the stability of the NTP server characterized by the evaluation parameter, therefore, in S203 above, according to the determined evaluation parameter, selecting the target NTP server from each candidate NTP server may include determining the candidate NTP server with the smallest evaluation parameter among each candidate NTP server as the target NTP server.
[0168] For example, as previously exemplified, candidate NTP servers B and D are determined, and the network time consumption of the four time calibration requests included in each ping command is a set of network time consumption.
[0169] For candidate NTP server B:
[0170] For the first group of network time consumption, the maximum network time consumption = 30ms, the minimum network time consumption = 28ms, and the average network time consumption = (30ms + 28ms + 28ms + 28ms) / 4 = 28.5; then the first deviation value t1max = 30 - 28.5 = 1.5ms, and the second deviation value t1min = 28.5 - 28 = 0.5ms.
[0171] For the second group of network time consumption, the maximum network time consumption = 35ms, the minimum network time consumption = 28ms, and the average network time consumption = (28ms + 28ms + 35ms + 28ms) / 4 = 29.75; then the first deviation value t2max = 35 - 29.75 = 5.25ms, and the second deviation value t2min = 29.75 - 28 = 1.75ms.
[0172] The third group of network latency, maximum network latency = 78 ms, minimum network latency = 28 ms, average network latency = (78 ms + 33 ms + 33 ms + 28 ms) / 4 = 43; then the first deviation value t3max = 78 - 43 = 35 ms, and the second deviation value t3min = 43 - 28 = 15 ms.
[0173] The fourth group of network latency, maximum network latency = 32 ms, minimum network latency = 28 ms, average network latency = (28 ms + 32 ms + 28 ms + 28 ms) / 4 = 29; then the first deviation value t4max = 32 - 29 = 3 ms, and the second deviation value t4min = 29 - 29 = 0 ms.
[0174] The average value of the first deviation values of the network latencies of each group = (t1max + t2max + t3max + t4max) / 4 = (1.5 ms + 5.25 ms + 35 ms + 3 ms) / 4 = 11.18 ms;
[0175] The average value of the second deviation values of the network latencies of each group = (t1min + t2min + t3min + t4min) / 4 = (0.5 ms + 1.75 ms + 15 ms + 0 ms) / 4 = 4.31 ms;
[0176] The evaluation parameter used to characterize the stability of the candidate NTP server B is: A1 = 11.18 ms + 4.31 ms = 15.51 ms.
[0177] For the candidate NTP server D:
[0178] The first group of network latency, maximum network latency = 29 ms, minimum network latency = 25 ms, average network latency = (29 ms + 27 ms + 26 ms + 25 ms) / 4 = 26.75; then the first deviation value T1max = 29 - 26.75 = 2.25 ms, and the second deviation value T1min = 26.75 - 25 = 1.75 ms.
[0179] The second group of network latency, maximum network latency = 26 ms, minimum network latency = 25 ms, average network latency = (26 ms + 25 ms + 25 ms + 25 ms) / 4 = 25.25; then the first deviation value T2max = 26 - 25.25 = 0.75 ms, and the second deviation value T2min = 25.25 - 25 = 0.25 ms.
[0180] The third group of network time consumption, the maximum network time consumption = 28 ms, the minimum network time consumption = 25 ms, the average network time consumption = (26 ms + 25 ms + 26 ms + 28 ms) / 4 = 26.25; then the first deviation value T3max = 28 - 26.25 = 1.75 ms, and the second deviation value T3min = 26.25 - 25 = 1.25 ms.
[0181] The fourth group of network time consumption, the maximum network time consumption = 27 ms, the minimum network time consumption = 25 ms, the average network time consumption = (25 ms + 25 ms + 27 ms + 25 ms) / 4 = 25.5; then the first deviation value T4max = 27 - 26.25 = 0.75 ms, and the second deviation value T4min = 26.25 - 25 = 1.25 ms.
[0182] The average value of the first deviation values of the network time consumptions of each group = (T1max + T2max + T3max + T4max) / 4 = (2.25 ms + 0.75 ms + 1.75 ms + 0.75 ms) / 4 = 1.38 ms;
[0183] The average value of the second deviation values of the network time consumptions of each group = (T1min + T2min + T3min + T4min) / 4 = (1.75 ms + 0.25 ms + 1.25 ms + 1.25 ms) / 4 = 0.88 ms;
[0184] The evaluation parameter for characterizing the stability of the candidate NTP server D is: A2 = 1.38 ms + 0.88 ms = 2.26 ms.
[0185] Then select the candidate NTP server D as the target NTP server.
[0186] In this embodiment, for each candidate NTP server, through the first average value of the first deviation values corresponding to the network time consumptions of each group of the candidate NTP server, and determining the second average value of the second deviation values corresponding to the network time consumptions of each group of the candidate NTP server, and then, according to the sum of the first average value and the second average value, determining the evaluation parameter for characterizing the stability of the candidate NTP server, the fluctuation range of multiple network time consumptions of the candidate NTP server can be captured hierarchically, avoiding the one-sidedness of a single index. By calculating the average value of multiple groups of deviation values, accidental anomalies in multiple network time consumptions can be filtered out, retaining the continuous fluctuation characteristics, enhancing the robustness of the finally determined evaluation parameter, and further being able to more truly reflect the actual distribution dispersion degree of multiple network time consumptions, more accurately characterize the stability of each candidate NTP server, and further improve the reliability of the finally determined target NTP server.
[0187] Based on the above embodiments, in an exemplary embodiment, the determination of the evaluation parameters in S202 is further refined. Optionally, as Figure 7 shown, the NTP server selection method may include the following steps:
[0188] S701, obtain the network latencies of each candidate NTP server.
[0189] Among them, the specific implementation manner of the above S701 is the same as that of the above S201, and will not be elaborated here.
[0190] S702, determine the magnitude relationship between the total number of network latencies of each candidate NTP server and a preset number threshold.
[0191] After obtaining the network latencies of each candidate NTP server, for each candidate NTP server, the magnitude relationship between the total number of network latencies of the candidate NTP server and the preset number threshold can be determined first, and then, according to the above magnitude relationship, a suitable method for determining the evaluation parameters can be selected.
[0192] Among them, the above preset number threshold can be set according to empirical values, experimental values of multiple tests, requirements of the actual application scenario, etc., and no specific limitation is made thereto.
[0193] S703, when the total number is greater than the preset number threshold, for each candidate NTP server, determine the standard deviation of the multiple network latencies of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server.
[0194] In the case of a large number, the standard deviation can better characterize the distribution dispersion degree of the data. Therefore, when the total number is greater than the preset number threshold, for each candidate NTP server, determine the standard deviation of the multiple network latencies of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server, so as to improve the accuracy of the determined evaluation parameters, more accurately characterize the stability of each candidate NTP server, and further improve the reliability of the finally determined target NTP server.
[0195] S704, when the total number is not greater than the preset number threshold, for each candidate NTP server, determine the data fluctuation characteristics of each group of network latencies of the candidate NTP server, and determine the evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network latencies of the candidate NTP server.
[0196] As described above, for each candidate NTP server, by determining the data fluctuation characteristics of each group of network time consumption of the candidate NTP server, and then according to the determined data fluctuation characteristics, determining the evaluation parameters for characterizing the stability of the corresponding candidate NTP server. Although there are many determination steps, the determination method for each step is relatively simple. Therefore, the overall determination process of the evaluation parameters is relatively simple. Thus, when the total quantity does not exceed the preset threshold, using the data fluctuation characteristics of each group of network time consumption of the candidate NTP server as the evaluation parameters for characterizing the stability of the corresponding candidate NTP server can simplify the determination process of the evaluation parameters and improve the efficiency of server selection.
[0197] S705. Select a target NTP server from each candidate NTP server according to the determined evaluation parameters.
[0198] Among them, the specific implementation manner of the above S705 is the same as that of the above S203 and will not be elaborated here.
[0199] In this embodiment, according to the size relationship between the total quantity of multiple network time consumptions of each candidate NTP server and the preset quantity threshold, selecting a suitable evaluation parameter determination method can balance the accuracy of the evaluation parameters and the efficiency of NTP server selection during the actual application process. Thus, the overall effect of NTP server selection can be improved.
[0200] Based on the above embodiments, in an exemplary embodiment, as Figure 8 shown, the NTP server selection method may include the following steps:
[0201] S801. Send multiple ping commands to each preset NTP server in sequence so that the preset NTP server feeds back the server time based on each time synchronization request.
[0202] S802. Eliminate the first abnormal NTP server and the second abnormal NTP server among each preset NTP server to obtain each candidate NTP server.
[0203] S803. Obtain the multiple network time consumptions of each candidate Network Time Protocol (NTP) server.
[0204] S804. Determine the size relationship between the total quantity of the network time consumptions of each candidate NTP server and the preset quantity threshold.
[0205] S805. When the total quantity is greater than the preset quantity threshold, determine the standard deviation of the multiple network time consumptions of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server.
[0206] S806. When the total quantity is not greater than a preset quantity threshold, for each set of network time consumption of each candidate NTP server, determine a first deviation value between the maximum network time consumption and the average time consumption in this set of network time consumption, and a second deviation value between the minimum network time consumption and the average time consumption in this set of network time consumption, as the data fluctuation characteristic of this set of network time consumption.
[0207] S807. For each candidate NTP server, determine a first average value of the first deviation values corresponding to each set of network time consumption of the candidate NTP server, and determine a second average value of the second deviation values corresponding to each set of network time consumption of the candidate NTP server.
[0208] S808. For each candidate NTP server, determine an evaluation parameter used to characterize the stability of the candidate NTP server according to the sum of the first average value and the second average value.
[0209] S809. Determine the candidate NTP server with the smallest evaluation parameter among the candidate NTP servers as the target NTP server.
[0210] Among them, the specific implementation manners of the above S801 - S809 are the same as the specific implementation manners in the above embodiments, and will not be elaborated here.
[0211] It should be understood that although the steps in the flowcharts involved in the above - mentioned embodiments are shown in sequence according to the arrows, these steps do not necessarily execute in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above - mentioned embodiments may include multiple steps or multiple stages. These steps or stages do not necessarily execute at the same moment, but can execute at different moments. The execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0212] Based on the same inventive concept, the embodiments of the present application also provide an NTP server selection device for implementing the NTP server selection method involved above. The implementation solutions for solving problems provided by this device are similar to the implementation solutions recorded in the above method. Therefore, the specific limitations in one or more embodiments of the NTP server selection device provided below can refer to the limitations on the NTP server selection method in the above text, and will not be elaborated here.
[0213] In an exemplary embodiment, as Figure 9As shown, a Network Time Protocol (NTP) server selection device is provided, including: a time-consuming acquisition module 910, a parameter determination module 920, and a device selection module 930, where:
[0214] The time-consuming acquisition module 910 is configured to obtain multiple network time consumptions of each candidate Network Time Protocol (NTP) server; wherein, the network time consumption of each candidate NTP server is determined according to the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time fed back by the candidate NTP server based on the time calibration request.
[0215] The parameter determination module 920 is configured to determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network time consumptions of each candidate NTP server.
[0216] The device selection module 930 is configured to select a target NTP server from each candidate NTP server according to the determined evaluation parameter; wherein, the target NTP server is used to synchronize the time of multiple vehicles.
[0217] In an exemplary embodiment, the parameter determination module 920 includes:
[0218] A first determination unit, configured to, for each candidate NTP server, determine the standard deviation of the multiple network time consumptions of the candidate NTP server as an evaluation parameter for characterizing the stability of the corresponding candidate NTP server; or,
[0219] A second determination unit, configured to, for each candidate NTP server, determine the data fluctuation characteristics of each group of network time consumptions of the candidate NTP server, and determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network time consumptions of the candidate NTP server; wherein, each group of network time consumptions includes at least two network time consumptions.
[0220] In an exemplary embodiment, the second determination unit is specifically configured to: for each group of network time consumptions, determine a first deviation value between the maximum network time consumption and the average time consumption of the group of network time consumptions, and a second deviation value between the minimum network time consumption and the average time consumption of the group of network time consumptions as the data fluctuation characteristics of the group of network time consumptions.
[0221] In an exemplary embodiment, the second determination unit is specifically configured to: determine a first average value of the first deviation values corresponding to each group of network time consumptions of the candidate NTP server, and determine a second average value of the second deviation values corresponding to each group of network time consumptions of the candidate NTP server; and determine an evaluation parameter for characterizing the stability of the candidate NTP server according to the sum of the first average value and the second average value.
[0222] In an exemplary embodiment, the device selection module 930 is specifically configured to: determine the candidate NTP server with the smallest evaluation parameter among the candidate NTP servers as the target NTP server.
[0223] In an exemplary embodiment, the NTP server selection device further includes:
[0224] A numerical comparison module, configured to determine the magnitude relationship between the total number of network time consumptions of each candidate NTP server and a preset number threshold;
[0225] A first determination unit, specifically configured to determine the standard deviation of the multiple network time consumptions of the candidate NTP server when the total number is greater than the preset number threshold;
[0226] A second determination unit, specifically configured to determine the data fluctuation characteristics of each group of network time consumptions of the candidate NTP server when the total number is not greater than the preset number threshold.
[0227] In an exemplary embodiment, the NTP server selection device further includes:
[0228] A request sending module, configured to sequentially send a plurality of time calibration requests to each preset NTP server before obtaining the multiple network time consumptions of each candidate Network Time Protocol (NTP) server, so that the preset NTP server feeds back the server time based on each time calibration request;
[0229] A device elimination module, configured to eliminate the first abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server; wherein, the first abnormal NTP servers include the preset NTP servers whose received number of server times is less than the sent number of time calibration requests.
[0230] In an exemplary embodiment, the device elimination module is specifically configured to: eliminate the first abnormal NTP servers and the second abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server; wherein, the second abnormal NTP servers include: the preset NTP servers whose deviation value between the maximum network time consumption and the minimum network time consumption in the network time consumption is greater than the network time consumption threshold.
[0231] In an exemplary embodiment, the request sending module is specifically configured to: sequentially send a plurality of ping commands to each preset NTP server; wherein, each ping command includes a plurality of time calibration requests.
[0232] Each module in the above NTP server selection device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above modules can be embedded in the processor of a computer device in hardware form or be independent of it, or be stored in the memory of the computer device in software form so that the processor can call and execute the operations corresponding to each of the above modules.
[0233] In an exemplary embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 10 shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as the network time consumption of multiple candidate NPC servers. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. When the computer program is executed by the processor, it implements an NTP server selection method.
[0234] Those skilled in the art can understand that Figure 10 the structure shown in
[0235] is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0236] In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps in each of the above method embodiments.
[0237] In an embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, it implements the following steps: the steps in each of the above method embodiments.
[0238] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in this application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in this application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, artificial intelligence (AI) processors, etc., without limitation.
[0239] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this application.
[0240] The above-described embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all fall within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.
Claims
1. A method for selecting an NTP server, characterized in that, The method includes: Obtaining multiple network latencies of each candidate Network Time Protocol (NTP) server; wherein, the network latency of each candidate NTP server is determined according to the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time fed back by the candidate NTP server based on the time calibration request; Determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network latencies of each candidate NTP server; Selecting a target NTP server from each candidate NTP server according to the determined evaluation parameter; wherein, the target NTP server is used to synchronize the time of multiple vehicles.
2. The method according to claim 1, wherein Determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network latencies of each candidate NTP server, including: For each candidate NTP server, determining the standard deviation of the multiple network latencies of the candidate NTP server as the evaluation parameter for characterizing the stability of the corresponding candidate NTP server; or, For each candidate NTP server, determining the data fluctuation characteristics of each group of network latencies of the candidate NTP server, and determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network latencies of the candidate NTP server; wherein, each group of network latencies includes at least two network latencies.
3. The method according to claim 2, characterized in that, Determining the data fluctuation characteristics of each group of network latencies of the candidate NTP server includes: For each group of network latencies, determining a first deviation value between the maximum network latency and the average latency of the group of network latencies, and a second deviation value between the minimum network latency and the average latency of the group of network latencies as the data fluctuation characteristics of the group of network latencies.
4. The method according to claim 3, characterized in that, Determining an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the data fluctuation characteristics of each group of network latencies of the candidate NTP server includes: Determining a first average value of the first deviation values corresponding to each group of network latencies of the candidate NTP server, and determining a second average value of the second deviation values corresponding to each group of network latencies of the candidate NTP server; Determining an evaluation parameter for characterizing the stability of the candidate NTP server according to the sum of the first average value and the second average value.
5. The method according to claim 2, wherein Selecting a target NTP server from each candidate NTP server according to the determined evaluation parameter includes: Determining the candidate NTP server with the minimum evaluation parameter among each candidate NTP server as the target NTP server.
6. The method according to any one of claims 2-5, characterized in that, The method further includes: Determining the magnitude relationship between the total number of network latencies of each candidate NTP server and a preset number threshold; Correspondingly, determining the standard deviation of the multiple network latencies of the candidate NTP server includes: In the case where the total number is greater than the preset number threshold, determining the standard deviation of the multiple network latencies of the candidate NTP server; Determining the data fluctuation characteristics of each group of network latencies of the candidate NTP server includes: When the total quantity is not greater than the preset quantity threshold, determine the data fluctuation characteristics of the network latency of each group of candidate NTP servers.
7. The method according to claim 1, characterized in that Before obtaining the multiple network latencies of each candidate Network Time Protocol (NTP) server, the method further includes: Sequentially send multiple time calibration requests to each preset NTP server, so that the preset NTP server feeds back the server time based on each time calibration request; Eliminate the first abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server; wherein, the first abnormal NTP servers include the preset NTP servers whose received quantity of server time is less than the sent quantity of time calibration requests.
8. The method according to claim 7, wherein Eliminating the first abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server includes: Eliminate the first abnormal NTP servers and the second abnormal NTP servers among the preset NTP servers to obtain each candidate NTP server; wherein, the second abnormal NTP servers include the preset NTP servers whose deviation value between the maximum network latency and the minimum network latency in the network latency is greater than the network latency threshold.
9. The method according to claim 7, wherein Sequentially sending multiple time calibration requests to each preset NTP server includes: Sequentially send multiple ping commands to each preset NTP server; wherein each ping command includes multiple time calibration requests.
10. An NTP server selection device, characterized in that, The device includes: A latency acquisition module, configured to acquire the multiple network latencies of each candidate Network Time Protocol (NTP) server; wherein, the network latency of each candidate NTP server is determined according to the timestamp of sending a time calibration request to the candidate NTP server and the timestamp of receiving the server time fed back by the candidate NTP server based on the time calibration request; A parameter determination module, configured to determine an evaluation parameter for characterizing the stability of the corresponding candidate NTP server according to the multiple network latencies of each candidate NTP server; A device selection module, configured to select a target NTP server from each candidate NTP server according to the determined evaluation parameter; wherein, the target NTP server is used for time synchronization of multiple vehicles.