Server time calibration method, device, electronic device and medium
By obtaining the time stamp information of network equipment, calculating the time difference and adjusting the server time, the problem of servers being unable to be calibrated in the internal local network is solved, and the accuracy of time and the stability of the server are improved.
Patent Information
- Application Number
- CN202210904051.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2042-07-29
AI Technical Summary
In the internal LAN, the server cannot perform time calibration by accessing the NTP server, resulting in large time errors and uncertainty.
By obtaining the timestamp information of at least two network devices, calculating the time difference value, and determining whether the server time needs to be calibrated based on the number of differences distributions, the server time is adjusted using the difference value within the time difference range with the largest number of distributions.
Improve the accuracy of server time, avoid business chaos and crashes caused by inaccurate time, and ensure the normal operation of the server.
Smart Images

Figure CN115276872B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, electronic device, and medium for calibrating time of a server. Background Art
[0002] With the rapid development of Internet technology, servers are used in many scenarios. Server time is very important for the normal operation of services and devices that access services.
[0003] Typically, servers are calibrated using a Network Time Protocol (NTP) server. However, for security reasons, some enterprises require that many critical application servers be disconnected from the internet. Instead, the servers and the entire network reside within an isolated internal LAN. In these cases, time calibration cannot be performed by accessing an NTP server, and manual time modification is often required. This results in significant errors and uncertainty. Summary of the Invention
[0004] In order to solve the above technical problems, the present disclosure provides a time calibration method, device, electronic device and medium for a server.
[0005] In a first aspect, the present disclosure provides a server time calibration method, applied to the server, the method comprising:
[0006] Obtaining timestamp information respectively sent by at least two network devices;
[0007] Obtaining a time difference based on each of the timestamp information and the time information of the server;
[0008] Determining whether the time of the server needs to be calibrated based on the distribution of the time difference values within different time difference ranges;
[0009] If the time of the server needs to be calibrated, the time information of the server is adjusted based on the time difference within the time difference range with the largest distribution number.
[0010] Optionally, the determining whether the server time needs to be calibrated based on the distribution quantity of the time difference values within different time difference ranges includes:
[0011] Determining whether the time of the server needs to be calibrated according to a relationship between the distribution quantity and a first preset threshold;
[0012] or,
[0013] Whether the time of the server needs to be calibrated is determined according to a relationship between a ratio of the distribution quantity to the total quantity of time differences and a second preset threshold.
[0014] Optionally, if the time of the server needs to be calibrated, adjusting the time information of the server based on the time difference within the time difference range with the largest distribution number includes:
[0015] If the time of the server needs to be calibrated, adjusting the time information of the server based on the minimum time difference within the time difference range with the largest number of distributions;
[0016] or,
[0017] If the time of the server needs to be calibrated, adjusting the time information of the server based on the timestamp information of the network device corresponding to the minimum time difference value in the time difference value range with the largest number of distributions;
[0018] or,
[0019] If the time of the server needs to be calibrated, the time information of the server is adjusted based on the average value of all time differences within the time difference range with the largest distribution number.
[0020] Optionally, obtaining timestamp information respectively sent by at least two network devices includes:
[0021] The timestamp information is obtained from access requests or transmission data of the at least two network devices.
[0022] Optionally, if the time of the server needs to be calibrated, before adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions, the method further includes:
[0023] It is determined that the server is in an idle period.
[0024] Optionally, after adjusting the time information of the server, the method further includes:
[0025] Determine the adjusted server time information as reference time information;
[0026] The reference time information is sent to other servers, so that the other servers adjust their time information based on the reference time information.
[0027] Optionally, before determining whether the server time needs to be calibrated based on the distribution of the time differences within different time difference ranges, the method further includes:
[0028] Counting the distribution number of the time difference values by using a counter corresponding to each time difference range;
[0029] After adjusting the time information of the server, the method further includes:
[0030] Reset the counter corresponding to each time difference range.
[0031] In a second aspect, the present disclosure provides a server time calibration device, which is applied to the server, and includes:
[0032] A first acquisition module is used to obtain timestamp information respectively sent by at least two network devices;
[0033] A second acquisition module is used to acquire a time difference based on each of the timestamp information and the time information of the server;
[0034] a determination module, configured to determine whether the time of the server needs to be calibrated based on the distribution quantity of the time difference values within different time difference ranges;
[0035] The adjustment module is configured to adjust the time information of the server based on the time difference within the time difference range with the largest distribution number if the time of the server needs to be calibrated.
[0036] Optionally, determine the module, specifically for:
[0037] Determining whether the time of the server needs to be calibrated according to a relationship between the distribution quantity and a first preset threshold;
[0038] or,
[0039] Whether the time of the server needs to be calibrated is determined according to a relationship between a ratio of the distribution quantity to the total quantity of time differences and a second preset threshold.
[0040] Optional, adjustment module, specifically used for:
[0041] If the time of the server needs to be calibrated, adjusting the time information of the server based on the minimum time difference within the time difference range with the largest number of distributions;
[0042] or,
[0043] If the time of the server needs to be calibrated, adjusting the time information of the server based on the timestamp information of the network device corresponding to the minimum time difference value in the time difference value range with the largest number of distributions;
[0044] or,
[0045] If the time of the server needs to be calibrated, the time information of the server is adjusted based on the average value of all time differences within the time difference range with the largest distribution number.
[0046] Optionally, the first acquisition module is specifically configured to:
[0047] The timestamp information is obtained from access requests or transmission data of the at least two network devices.
[0048] Optionally, the above device further includes:
[0049] The idle period determination module is used to determine that the server is in the idle period before adjusting the time information of the server based on the time difference within the time difference range with the largest distribution number if the time of the server needs to be calibrated.
[0050] Optionally, the above device further includes:
[0051] a reference time determining module, configured to, after adjusting the time information of the server, determine the adjusted time information of the server as the reference time information;
[0052] The sending module is configured to send the reference time information to other servers, so that the other servers adjust their time information based on the reference time information.
[0053] Optionally, the above device further includes:
[0054] a statistics module, configured to count the number of distributions of the time differences using a counter corresponding to each time difference range before determining whether the time of the server needs to be calibrated based on the number of distributions of the time differences in different time difference ranges;
[0055] The reset module is used to reset the counter corresponding to each time difference range after adjusting the time information of the server.
[0056] In a third aspect, the present disclosure further provides an electronic device, comprising:
[0057] one or more processors;
[0058] a storage device for storing one or more programs,
[0059] When the one or more programs are executed by the one or more processors, the one or more processors implement the server time calibration method described in any one of the embodiments of the present disclosure.
[0060] In a fourth aspect, the present disclosure further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the server time calibration method described in any one of the embodiments of the present disclosure.
[0061] The technical solution provided by the embodiment of the present disclosure has the following advantages compared with the existing technology: first, the timestamp information sent by at least two network devices is obtained respectively, and then the time difference is obtained based on each timestamp information and the time information of the server. Then, based on the distribution number of the time difference in different time difference ranges, it is determined whether the server time needs to be calibrated. Finally, if the server time needs to be calibrated, the server time information is adjusted based on the time difference in the time difference range with the largest distribution number. In the above solution, the server time is calibrated by the timestamp information of the network device, which can improve the accuracy of the server time. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0063] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0064] Figure 1 This is a flow chart of a method for calibrating server time provided by an embodiment of the present disclosure;
[0065] Figure 2A This is a flow chart of another method for calibrating server time provided by an embodiment of the present disclosure;
[0066] Figure 2B This is a flow chart of another method for calibrating server time provided by an embodiment of the present disclosure;
[0067] Figure 3 This is a schematic structural diagram of a time calibration device for a server provided by an embodiment of the present disclosure;
[0068] Figure 4 It is a structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0069] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.
[0070] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0071] Figure 1 This is a flow chart of a server time calibration method provided by an embodiment of the present disclosure. This embodiment is applicable to the case where a server cannot be time-calibrated by accessing an NTP server. The method of this embodiment can be executed by a server time calibration device, which can be implemented in hardware / software and can be configured in an electronic device. Figure 1 As shown, the method specifically includes the following:
[0072] S110: Obtain timestamp information respectively sent by at least two network devices.
[0073] Among them, network devices can be understood as devices with Internet access capabilities and can automatically perform time calibration, such as Android devices, personal computers, and tablets.
[0074] In order to solve the problem in the prior art that it is impossible to calibrate the server time by accessing the NTP server, and manual time modification causes a large error band and great uncertainty, this embodiment obtains the timestamp information sent by at least two network devices respectively, so as to facilitate the subsequent acquisition of the time difference based on each timestamp information and the server time information.
[0075] It should be noted that the timestamp information sent by at least two network devices is relatively accurate.
[0076] S120: Obtain a time difference based on each timestamp information and the time information of the server.
[0077] The server time information may be understood as the time information currently displayed on the server.
[0078] After obtaining the timestamp information sent by at least two network devices, each timestamp information is subtracted from the time information of the server to obtain the corresponding time difference value. The number of time difference values is the same as the number of network devices.
[0079] S130: Determine whether the server time needs to be calibrated based on the distribution quantity of the time difference values within different time difference ranges.
[0080] The time difference range may be a pre-set time difference range, or may be determined according to the server's time accuracy requirements, or may depend on specific circumstances, which is not limited in this embodiment.
[0081] After obtaining at least two time differences, the distribution number of at least two time differences within different time difference ranges can be determined. Based on the distribution number and the corresponding judgment method, it is possible to determine whether the server time is accurate and whether the server time needs to be calibrated.
[0082] S140: If the server time needs to be calibrated, adjust the server time information based on the time difference within the time difference range with the largest distribution number.
[0083] If the server time is inaccurate (i.e., deviated), it means that the server time needs to be calibrated. If the server time needs to be calibrated, since the corresponding distribution numbers in different time difference ranges may be different, the time difference values contained in the time difference range with the largest distribution number can be used as the basis for adjusting the server time information. The server time information is adjusted based on the time difference values in the time difference range with the largest distribution number to ensure that the server time information is accurate. This avoids the situation where the server time information differs significantly from the actual time, causing confusion in the time recorded by the server in the data processing process, resulting in business confusion or even business crashes, as well as the invalidation of related verifications determined based on timestamps, resulting in verification failures.
[0084] Correspondingly, if the server time is accurate, it means that the server time does not need to be calibrated.
[0085] In this embodiment, first, timestamp information sent by at least two network devices is obtained respectively, and then a time difference is obtained based on each timestamp information and the time information of the server. Then, based on the distribution number of the time difference in different time difference ranges, it is determined whether the server time needs to be calibrated. Finally, if the server time needs to be calibrated, the server time information is adjusted based on the time difference in the time difference range with the largest distribution number. In the above scheme, the server time is calibrated by the timestamp information of the network device, which can improve the accuracy of the server time.
[0086] In this embodiment, optionally, if the time of the server needs to be calibrated, before adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions, the following steps may be specifically performed:
[0087] It is determined that the server is in an idle period.
[0088] Specifically, the server usually needs to process a large amount of work or business, so before adjusting the server's time information based on the time difference within the time difference range with the largest distribution number, it is also necessary to determine whether the server is in an idle period, so as to adjust the server's time information when the server is in the idle period to avoid affecting the normal operation of the server.
[0089] In this embodiment, the above method can adjust the server time without affecting the normal operation of the server, which is beneficial to improving the processing efficiency of the server.
[0090] In some embodiments, optionally, adjusting the server time information may be a real-time adjustment, that is, after determining that the server time needs to be calibrated, adjusting the server time information in real time based on the time difference within the time difference range with the largest distribution number.
[0091] In this embodiment, the above method can immediately adjust the time information of the server to avoid affecting the services or processes related to the time information of the server.
[0092] In this embodiment, optionally, after adjusting the time information of the server, the following steps may be specifically performed:
[0093] Determine the adjusted server time information as reference time information;
[0094] The reference time information is sent to other servers, so that the other servers adjust their time information based on the reference time information.
[0095] In this embodiment, after the time information of the server is adjusted, the adjusted time information of the server is determined as the reference time information, and the reference time information is sent to other servers so that other servers adjust their time information based on the reference time information. This can synchronize the time information between the servers and avoid too large a difference in time information between the servers, causing business confusion and affecting the normal operation of the servers.
[0096] In this embodiment, optionally, before determining whether the server time needs to be calibrated based on the distribution of the time differences within different time difference ranges, the method further includes:
[0097] Counting the distribution number of the time difference values by using a counter corresponding to each time difference range;
[0098] After adjusting the time information of the server, the method further includes:
[0099] Reset the counter corresponding to each time difference range.
[0100] In this embodiment, a corresponding counter can be configured for each time difference range. This counter can then be used to count the number of time differences within the current time difference range, facilitating subsequent determination of whether the server time requires calibration. After adjusting the server time information, resetting the counter for each time difference range facilitates subsequent restart of the corresponding counter to re-monitor the server time information and ensure the server time information is accurate.
[0101] Figure 2A This is a flow chart of another method for calibrating the time of a server provided by an embodiment of the present disclosure. This embodiment is optimized based on the above embodiment. Optionally, this embodiment provides a detailed explanation of one of the methods for determining whether the time of the server needs to be calibrated. Figure 2A As shown, the method specifically includes the following:
[0102] S110: Obtain timestamp information respectively sent by at least two network devices.
[0103] S120: Obtain a time difference based on each timestamp information and the time information of the server.
[0104] S1301: Determine whether the server time needs to be calibrated based on the relationship between the distribution quantity and a first preset threshold.
[0105] The first preset threshold may be a predetermined value, such as 40, or may be determined according to specific circumstances, which is not limited in this embodiment.
[0106] Based on the distribution number of time differences within different time difference ranges, the size relationship between each distribution number and the first preset threshold can be determined, so as to determine whether the server time needs to be calibrated based on the size relationship between the distribution number and the first preset threshold. Specifically: if there is at least one distribution number within the time difference range that is greater than or equal to the first preset threshold, it means that the server time has deviated, and it is determined that the server time needs to be calibrated; otherwise, it means that the server time is accurate and does not need to be calibrated.
[0107] For example, assuming that the timestamp information sent by 100 network devices is obtained, there are 4 time difference ranges, namely [0,1], (1,2], (2,3] and (3,+∞], the first preset threshold is 40, the number of time differences distributed in [0,1] is 10, the number of time differences distributed in (1,2] is 30, the number of time differences distributed in (2,3] is 55, and the number of time differences distributed in (3,+∞] is 5. Then the number of time differences distributed in (2,3] is greater than the first preset threshold. Therefore, it can be determined that the server time needs to be calibrated.
[0108] S140: If the server time needs to be calibrated, adjust the server time information based on the time difference within the time difference range with the largest distribution number.
[0109] In this embodiment, first, timestamp information sent by at least two network devices is obtained respectively, and then a time difference is obtained based on each timestamp information and the time information of the server. Then, based on the relationship between the distribution quantity and the first preset threshold, it is determined whether the server time needs to be calibrated. Finally, if the server time needs to be calibrated, the server time information is adjusted based on the time difference within the time difference range with the largest distribution quantity. The above method can determine under what circumstances the server time needs to be calibrated, so that the server time can be calibrated in time subsequently, ensuring that the server time is accurate, improving the accuracy of the server time, and avoiding adverse effects caused by inaccurate server time.
[0110] Figure 2B This is a flow chart of another method for calibrating the time of a server provided by an embodiment of the present disclosure. Optionally, based on the above embodiment, Figure 2B Another method for determining whether the server time needs to be calibrated is mainly explained in detail, and S1301 is replaced by S1302.
[0111] S1302: Determine whether the server time needs to be calibrated based on a ratio of the distribution quantity to the total time difference quantity and a second preset threshold.
[0112] The second preset threshold may be a predetermined ratio, for example, 40%, or may be determined according to specific circumstances, which is not limited in this embodiment. The total number of time differences is the number of network devices.
[0113] Based on the distribution number of time differences in different time difference ranges and the total number of time differences, the ratio of each distribution number to the total number of time differences can be determined, so as to determine whether the server time needs to be calibrated based on the relationship between the ratio of the distribution number to the total number of time differences and the second preset threshold. Specifically: if among these ratios, there is at least one time difference range whose ratio to the total number of time differences is greater than or equal to the second preset threshold, it means that the server time has deviated and it is determined that the server time needs to be calibrated; otherwise, it means that the server time is accurate and does not need to be calibrated.
[0114] For example, assuming that the timestamp information sent by 100 network devices is obtained, there are 4 time difference ranges, namely [0,1], (1,2], (2,3] and (3,+∞], the second preset threshold is 40%, the number of time differences distributed in [0,1] is 15, and the ratio of the number of time differences to the total number of time differences is 15%, the number of time differences distributed in (1,2] is 25, and the ratio of the number of time differences to the total number of time differences is 25%, the number of time differences distributed in (2,3] is 50, and the ratio of the number of time differences to the total number of time differences is 50%, the number of time differences distributed in (3,+∞] is 10, and the ratio of the number of time differences to the total number of time differences is 10%, then the ratio of the number of time differences distributed in (2,3] to the total number of time differences is greater than the second preset threshold, therefore, it can be determined that the server time needs to be calibrated.
[0115] It should be noted that: Figure 2B The S110, S120 and S140 in Figure 1 S110, S120 and S140 are the same and will not be repeated here.
[0116] In this embodiment, optionally, if the time of the server needs to be calibrated, adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions may specifically include:
[0117] If the time of the server needs to be calibrated, adjusting the time information of the server based on the minimum time difference within the time difference range with the largest number of distributions;
[0118] or,
[0119] If the time of the server needs to be calibrated, adjusting the time information of the server based on the timestamp information of the network device corresponding to the minimum time difference value in the time difference value range with the largest number of distributions;
[0120] or,
[0121] If the time of the server needs to be calibrated, the time information of the server is adjusted based on the average value of all time differences within the time difference range with the largest distribution number.
[0122] In this embodiment, since there may be multiple time differences within the time difference range with the largest number of distributions, if the server time needs to be calibrated, the server time information can be adjusted based on the time difference within the time difference range with the largest number of distributions. Specifically, the server time information can be adjusted according to the minimum time difference within the time difference range with the largest number of distributions. The server time information can also be adjusted according to the timestamp information of the network device corresponding to the minimum time difference within the time difference range with the largest number of distributions. The server time information can also be adjusted according to the average value of all time differences within the time difference range with the largest number of distributions. Adjusting the server time information by any of the above three methods is simple and quick, which is conducive to improving the accuracy of the server time.
[0123] In this embodiment, optionally, obtaining timestamp information respectively sent by at least two network devices may specifically include:
[0124] The timestamp information is obtained from access requests or transmission data of the at least two network devices.
[0125] In this embodiment, by extracting access requests or transmission data of at least two network devices, timestamp information corresponding to the at least two network devices can be obtained, thereby facilitating subsequent acquisition of a time difference.
[0126] Figure 3 This is a schematic diagram of the structure of a server time calibration device provided by an embodiment of the present disclosure. This device is configured in an electronic device and can implement the server time calibration method described in any embodiment of the present application. The device specifically includes the following:
[0127] A first acquisition module 310 is configured to acquire timestamp information respectively sent by at least two network devices;
[0128] A second obtaining module 320 is configured to obtain a time difference based on each of the timestamp information and the time information of the server;
[0129] A determination module 330 is configured to determine whether the time of the server needs to be calibrated based on the distribution of the time difference values within different time difference ranges;
[0130] The adjustment module 340 is configured to adjust the time information of the server based on the time difference within the time difference range with the largest number of distributions if the time of the server needs to be calibrated.
[0131] In this embodiment, optionally, the determining module 330 is specifically configured to:
[0132] Determining whether the time of the server needs to be calibrated according to a relationship between the distribution quantity and a first preset threshold;
[0133] or,
[0134] Whether the time of the server needs to be calibrated is determined according to a relationship between a ratio of the distribution quantity to the total quantity of time differences and a second preset threshold.
[0135] In this embodiment, the adjustment module 340 is optionally configured to:
[0136] If the time of the server needs to be calibrated, adjusting the time information of the server based on the minimum time difference within the time difference range with the largest number of distributions;
[0137] or,
[0138] If the time of the server needs to be calibrated, adjusting the time information of the server based on the timestamp information of the network device corresponding to the minimum time difference value in the time difference value range with the largest number of distributions;
[0139] or,
[0140] If the time of the server needs to be calibrated, the time information of the server is adjusted based on the average value of all time differences within the time difference range with the largest distribution number.
[0141] In this embodiment, optionally, the first acquisition module 310 is specifically configured to:
[0142] The timestamp information is obtained from access requests or transmission data of the at least two network devices.
[0143] In this embodiment, optionally, the apparatus further includes:
[0144] The idle period determination module is used to determine that the server is in the idle period before adjusting the time information of the server based on the time difference within the time difference range with the largest distribution number if the time of the server needs to be calibrated.
[0145] In this embodiment, optionally, the apparatus further includes:
[0146] a reference time determining module, configured to, after adjusting the time information of the server, determine the adjusted time information of the server as the reference time information;
[0147] The sending module is configured to send the reference time information to other servers, so that the other servers adjust their time information based on the reference time information.
[0148] In this embodiment, optionally, the apparatus further includes:
[0149] a statistics module, configured to count the number of distributions of the time differences using a counter corresponding to each time difference range before determining whether the time of the server needs to be calibrated based on the number of distributions of the time differences in different time difference ranges;
[0150] The reset module is used to reset the counter corresponding to each time difference range after adjusting the time information of the server.
[0151] The time calibration device for a server provided by an embodiment of the present disclosure first obtains timestamp information respectively sent by at least two network devices, then obtains a time difference based on each timestamp information and the time information of the server, and then determines whether the server time needs to be calibrated based on the distribution number of the time difference in different time difference ranges. Finally, if it is determined that the server time needs to be calibrated, the server time information is adjusted based on the time difference in the time difference range with the largest distribution number. In the above scheme, the server time is calibrated by the timestamp information of the network device, which can improve the accuracy of the server time.
[0152] The server time calibration device provided in the embodiment of the present disclosure can execute the server time calibration method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0153] Figure 4 Schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 4 As shown, the electronic device includes a processor 410 and a storage device 420; the number of processors 410 in the electronic device can be one or more. Figure 4 In the figure, a processor 410 is used as an example; the processor 410 and the storage device 420 in the electronic device can be connected via a bus or other means. Figure 4 The bus connection is taken as an example.
[0154] Storage device 420, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the server time calibration method in the embodiments of the present disclosure. Processor 410 executes the software programs, instructions, and modules stored in storage device 420 to execute various functional applications and data processing of the electronic device, thereby implementing the server time calibration method provided in the embodiments of the present disclosure.
[0155] The storage device 420 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data created based on the use of the terminal, etc. Furthermore, the storage device 420 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the storage device 420 may further include a memory remotely located relative to the processor 410, and these remote memories may be connected to the electronic device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0156] An electronic device provided in this embodiment can be used to execute the time calibration method for a server provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0157] The embodiment of the present disclosure further provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to implement the server time calibration method provided by the embodiment of the present disclosure.
[0158] Of course, the computer executable instructions of a storage medium provided by an embodiment of the present disclosure are not limited to the operations of the method described above, but can also execute related operations in the server time calibration method provided by any embodiment of the present disclosure.
[0159] Through the above description of the implementation methods, those skilled in the art can clearly understand that the present disclosure can be implemented with the help of software and necessary general-purpose hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer's floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present disclosure.
[0160] It is worth noting that in the embodiment of the time calibration device of the above-mentioned server, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this disclosure.
[0161] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0162] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.
Claims
1. A time calibration method for a server, characterized in that: Applied to a server, the method includes: Obtaining timestamp information respectively sent by at least two network devices, wherein the network devices are devices having an Internet access function and capable of automatically performing time calibration; Obtaining a time difference based on each of the timestamp information and the time information of the server; Determining whether the server time needs to be calibrated based on the distribution of the time difference values within different time difference ranges, where the time difference range is a pre-set time difference range; If the time of the server needs to be calibrated, adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions; The determining whether the time of the server needs to be calibrated based on the distribution quantity of the time difference values within different time difference value ranges includes: Determining whether the time of the server needs to be calibrated according to a relationship between the distribution quantity and a first preset threshold; or, Determining whether the time of the server needs to be calibrated according to a relationship between a ratio of the number of distributions to the total number of time differences and a second preset threshold; The determining whether the time of the server needs to be calibrated according to the relationship between the distribution quantity and the first preset threshold value includes: If there is at least one distribution number within the time difference range that is greater than or equal to a first preset threshold, determining that the time of the server needs to be calibrated; The determining whether the server time needs to be calibrated according to a relationship between a ratio of the distribution quantity to the total number of time differences and a second preset threshold value includes: If there is at least one time difference value range in which the ratio of the number of distributions to the total number of time differences is greater than or equal to a second preset threshold, it is determined that the time of the server needs to be calibrated.
2. The method according to claim 1, characterized in that If the time of the server needs to be calibrated, adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions includes: If the time of the server needs to be calibrated, adjusting the time information of the server based on the minimum time difference within the time difference range with the largest number of distributions; or, If the time of the server needs to be calibrated, adjusting the time information of the server based on the timestamp information of the network device corresponding to the minimum time difference value in the time difference value range with the largest number of distributions; or, If the time of the server needs to be calibrated, the time information of the server is adjusted based on the average value of all time differences within the time difference range with the largest distribution number.
3. The method according to any one of claims 1-2, characterized in that The obtaining of timestamp information respectively sent by at least two network devices includes: The timestamp information is obtained from access requests or transmission data of the at least two network devices.
4. The method according to any one of claims 1 to 2, characterized in that If the time of the server needs to be calibrated, before adjusting the time information of the server based on the time difference within the time difference range with the largest number of distributions, the method further includes: It is determined that the server is in an idle period.
5. The method according to any one of claims 1-2, characterized in that After adjusting the time information of the server, the method further includes: Determine the adjusted server time information as reference time information; The reference time information is sent to other servers, so that the other servers adjust their time information based on the reference time information.
6. The method according to any one of claims 1-2, characterized in that Before determining whether the time of the server needs to be calibrated based on the distribution of the time difference values within different time difference ranges, the method further includes: Counting the distribution number of the time difference values by using a counter corresponding to each time difference range; After adjusting the time information of the server, the method further includes: Reset the counter corresponding to each time difference range.
7. A time calibration device for a server, characterized in that: Applied to a server, the device includes: A first acquisition module is configured to acquire timestamp information respectively sent by at least two network devices, wherein the network devices are devices with Internet access functions and capable of automatic time calibration; A second acquisition module is used to acquire a time difference based on each of the timestamp information and the time information of the server; a determination module, configured to determine whether the time of the server needs to be calibrated based on the distribution quantity of the time difference within different time difference ranges, wherein the time difference range is a preset time difference range; an adjustment module, configured to adjust the time information of the server based on the time difference within the time difference range with the largest number of distributions if the time of the server needs to be calibrated; The determining module is configured to determine whether the time of the server needs to be calibrated based on a relationship between the distribution quantity and a first preset threshold; or, Determining whether the time of the server needs to be calibrated according to a relationship between a ratio of the number of distributions to the total number of time differences and a second preset threshold; The determining module is configured to determine that the time of the server needs to be calibrated if there is at least one distribution number within a time difference range that is greater than or equal to a first preset threshold; The determining module is configured to determine that the server time needs to be calibrated if the ratio of the number of distributions within at least one time difference range to the total number of time differences is greater than or equal to a second preset threshold.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method of accurate time checking of terminal based on distributed clock source
CN108020716A
Time verification method and device, computer equipment and storage medium
CN111490843A