Dual-machine hot standby optimization method, system, device and computer-readable storage medium

By reading local configuration files and connection services in the dual-machine hot standby system and obtaining expired key values ​​in the preset key value database to determine the service status, the problem of low accuracy of main and standby service switching in the dual-machine hot standby system is solved, and the stability and accuracy of the system are improved.

CN114281606BActive Publication Date: 2025-06-06HANGZHOU HIKVISION SYST TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111556510.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-17
Publication Date
2025-06-06
Estimated Expiration
2041-12-17

AI Technical Summary

Technical Problem

The accuracy of switching between the main and backup service in the existing dual-machine hot standby system is low, which causes the backup service to misjudgment or disconnection of the network connection between the main service and the backup service to malfunction, resulting in the split of the dual-machine hot standby system into two independent individuals competing for data.

Method used

Read the local configuration file through the first service and connect the first service and the second service; if the connection is successful, set the first service as a backup service; if the connection fails, obtain the expired key value in the preset key value database of the second service to determine whether the second service is running normally; if the second service is running normally, set the first service as a backup service; if the second service is not running normally, set the first service as the main service.

Benefits of technology

The accuracy of the main and backup service switching in the dual-machine hot standby system is improved, and misjudgment caused by network connection jitter or disconnection is prevented, and the phenomenon of the dual-machine hot standby system being split into two independent individuals competing for data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281606B_ABST
    Figure CN114281606B_ABST
Patent Text Reader

Abstract

The present application discloses a dual-machine hot standby optimization method, system, device and computer-readable storage medium, which are applied to a first server. The dual-machine hot standby optimization method includes: reading a local configuration file through a first service, and connecting the first service and a second service deployed on a second server according to the second service information in the local configuration file; if the connection is successful, setting the first service as a backup service; if the connection fails, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally, wherein the preset key value database is deployed on a third server; if the second service is not operating normally, setting the first service as the primary service; if the second service is operating normally, setting the first service as the backup service. The present application solves the technical problem of low accuracy of switching between primary and backup services in a dual-machine hot standby system in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network communication technology, and in particular to a dual-machine hot standby optimization method, system, device and computer-readable storage medium. Background Art

[0002] With the continuous development of network communication technology, in order to ensure the integrity and availability of system services during operation, a dual-machine hot standby solution is usually adopted. In this solution, the main service and the backup service usually detect each other's faults through heartbeat detection. Under normal circumstances, the main service is in working state and the backup service is in monitoring state. Once the backup service detects that the main service is abnormal, the backup service will replace the main service in a very short time and fully realize the function of the main service. However, when the main service runs normally but the network connection between the main service and the backup service jitters or is disconnected, the backup service usually misjudges that the main service has a fault and mistakenly switches itself to the main service. That is, the accuracy of the main and backup service switching in the current dual-machine hot standby system is low, resulting in: there will be two running main services at the same time, resulting in a "brain split" phenomenon, which makes the normally running dual-machine hot standby system split into two independent individuals to compete for data. Summary of the invention

[0003] The main purpose of the present application is to provide a dual-machine hot standby optimization method, system, device and computer-readable storage medium, aiming to solve the technical problem of low accuracy of active-standby service switching in a dual-machine hot standby system in the prior art.

[0004] To achieve the above object, the present application provides a dual-machine hot standby optimization method, which is applied to a first server, and the dual-machine hot standby optimization method includes:

[0005] Reading a local configuration file through the first service, and connecting the first service and a second service deployed on a second server according to second service information in the local configuration file;

[0006] If the connection is successful, setting the first service as a backup service;

[0007] If the connection fails, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally, wherein the preset key value database is deployed on a third server;

[0008] If the second service does not operate normally, setting the first service as the primary service;

[0009] If the second service runs normally, the first service is set as a backup service.

[0010] To achieve the above purpose, the present application also provides a dual-machine hot standby optimization method, which is applied to the second server, and the dual-machine hot standby optimization method includes:

[0011] When the second service in the second server serves as the main service, the second expired key value in the preset key value database is regularly maintained, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is running normally, so as to determine whether to set the first service as the main service or the backup service.

[0012] The present application also provides a dual-machine hot standby optimization device, which is applied to a first server and includes:

[0013] A network connection module, configured to read a local configuration file through a first service, and connect the first service to a second service deployed on a second server according to second service information in the local configuration file;

[0014] A first active-standby switching module, configured to set the first service as a standby service if the connection is successful;

[0015] A key value acquisition module, used for acquiring a second expired key value in a preset key value database regularly maintained by the second service if the connection fails, so as to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server;

[0016] A second active-standby switching module, configured to set the first service as the primary service if the second service does not operate normally;

[0017] The third active-standby switching module is configured to set the first service as a standby service if the second service runs normally.

[0018] The present application also provides a dual-machine hot standby optimization device, which is applied to a second server and includes:

[0019] A key value maintenance module is used to regularly maintain the second expired key value in a preset key value database when the second service in the second server serves as the main service, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is operating normally, so as to determine whether to set the first service as the main service or the backup service.

[0020] The present application also provides a dual-machine hot standby optimization system, the dual-machine hot standby optimization system comprising:

[0021] A first server, the first server is used to: read a local configuration file through a first service, and connect the first service and a second service deployed on a second server according to second service information in the local configuration file; if the connection is successful, set the first service as a standby service; if the connection fails, obtain a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server; if the second service is not running normally, set the first service as a primary service; if the second service is running normally, set the first service as a standby service;

[0022] A second server, the second server is used to: when the second service in the second server is used as the main service, regularly maintain the second expired key value in the preset key value database, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is running normally, so as to determine whether to set the first service as the main service or the backup service;

[0023] A third server is used to deploy the preset key-value database.

[0024] The present application also provides an electronic device, which is a physical device, and includes: a memory, a processor, and a program of the dual-machine hot standby optimization method stored in the memory and executable on the processor. When the program of the dual-machine hot standby optimization method is executed by the processor, the steps of the dual-machine hot standby optimization method as described above can be implemented.

[0025] The present application also provides a computer-readable storage medium, on which is stored a program for implementing a dual-machine hot standby optimization method. When the program of the dual-machine hot standby optimization method is executed by a processor, the steps of the dual-machine hot standby optimization method as described above are implemented.

[0026] The present application also provides a computer program product, including a computer program, which implements the steps of the dual-machine hot standby optimization method as described above when executed by a processor.

[0027] The present application provides a dual-machine hot standby optimization method, system, device and computer-readable storage medium. Compared with the technical means used in the prior art that the main service and the backup service perform mutual fault detection through heartbeat detection to perform main-backup switching, the present application first reads a local configuration file through a first service, and connects the first service and the second service deployed on a second server according to the second service information in the local configuration file; if the connection is successful, it proves that the second service is running as the main service, so the first service is set as a backup service; if the connection fails, the second expired key value in the preset key value database regularly maintained by the second service is obtained to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server; if the acquisition is successful , it proves that the second expired key value has not been deleted due to expiration, so the second server is still connected to the third server normally, and the second service is still regularly maintaining the second expired key value. At this time, it is inferred that the reason for the connection failure is that the network connection between the first server and the second server is jittered or disconnected, and the second service is running normally at this time, and then the first service is set as a backup service to prevent multiple main services from competing for data; if the acquisition fails, the second expired key value is deleted due to expiration, so the second server is not connected to the third server normally, and the second service is not regularly maintaining the second expired key value. At this time, it is inferred that the second server fails and causes the second service to stop running (not running normally), and then the first service is set as the main service to ensure that the network system can operate normally. Therefore, the purpose of determining whether the reason for the connection failure is the jitter or disconnection of the network connection or the failure of the second server is achieved by obtaining the second expired key value regularly maintained by the second service from the key-value database. This can prevent the first service from misjudging that the second service stops running due to the jitter or disconnection of the network connection when the second service is running normally, and the first service switches itself to the main service when the second service is the main service. In other words, the situation where the dual-machine hot standby system is split into two independent individuals can be prevented. Therefore, the technical defect that when the main service is running normally but the network connection between the main service and the backup service is jittering or disconnected, the backup service usually misjudges that the main service has failed and sets itself as the main service, causing the normally running dual-machine hot standby system to be split into two independent individuals to compete for data is overcome, thereby improving the accuracy of switching between the main and backup services in the dual-machine hot standby system. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0030] Figure 1 A schematic diagram of the flow chart of the first embodiment of the dual-machine hot standby optimization method of the present application;

[0031] Figure 2 A schematic diagram of the framework of a dual-machine hot standby system in an embodiment of the dual-machine hot standby optimization method of the present application;

[0032] Figure 3 This is a flow chart of the second embodiment of the dual-machine hot standby optimization method of the present application;

[0033] Figure 4 A schematic diagram of the flow chart of the third embodiment of the dual-machine hot standby optimization method of the present application;

[0034] Figure 5 A flowchart of a fourth embodiment of the dual-machine hot standby optimization method of the present application;

[0035] Figure 6 Schematic diagram of the device structure of the hardware operating environment involved in the dual-machine hot standby optimization method in the embodiment of the present application.

[0036] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0037] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of this application.

[0038] Embodiment 1

[0039] In a dual-machine hot standby system, there is usually a long connection between the main service and the backup service. The main service and the backup service send heartbeat packets through the long connection to detect whether they are running normally. Once the backup service finds that the heartbeat packet is lost, it determines that the main service is not running normally, and switches itself to the main service to ensure the normal operation of the network system. However, when the heartbeat packet is lost, there are usually two situations: the first situation is that the server where the main service is located fails and stops running, which causes the main service to not run normally. At this time, the backup service needs to switch to the main service to ensure the normal operation of the network system; the second situation is that the heartbeat packet is lost due to network connection jitter or disconnection, but the main service is still running normally. At this time, if the main and backup switching is performed by detecting the heartbeat packet, the backup service will be directly switched to the main service by mistake. Therefore, there is an inaccurate main and backup switching in the current dual-machine hot standby system, resulting in: there are two main services in the dual-machine hot standby system at the same time. At this time, the normally running dual-machine hot standby system is split into two independent individuals to compete for data, resulting in a "brain split" phenomenon.

[0040] The present application embodiment provides a dual-machine hot standby optimization method, which is applied to a first server. In the first embodiment of the dual-machine hot standby optimization method of the present application, referring to Figure 1 , the dual-machine hot standby optimization method includes:

[0041] Step S10, reading a local configuration file through the first service, and connecting the first service and a second service deployed on a second server according to second service information in the local configuration file;

[0042] Step S20: If the connection is successful, the first service is set as a backup service;

[0043] Step S30, if the connection fails, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server;

[0044] Step S40: if the second service does not run normally, setting the first service as the main service;

[0045] Step S50: If the second service runs normally, the first service is set as a standby service.

[0046] The embodiment of the present application first reads a local configuration file through the first service, and connects the first service and the second service deployed on the second server according to the second service information in the local configuration file; if the connection between the first service and the second service is successful, it proves that the second service is operating normally as the main service, so the first service is set as a backup service; if the connection fails, the second expired key value regularly maintained by the second service is obtained from the preset key value database, and if the acquisition is successful, it proves that the second service is still regularly maintaining the second expired key value, and the second expired key value has not been deleted due to expiration. At this time, it is inferred that the cause of the connection failure is probably the network connection jitter or disconnection, and the second The service is running normally at this time, so the first service is set as a backup service. If the acquisition fails, it proves that the second service is not regularly maintaining the second expired key value, and the second expired key value is deleted due to expiration. At this time, it is inferred that the second server has failed and caused the second service to stop running, so the first service is set as the main service, thereby achieving the purpose of accurate master-slave switching in the dual-machine hot standby system. It can prevent the situation where the first service mistakenly judges that the second service stops running due to network connection jitter or disconnection when the second service is running normally, and the first service switches itself to the main service when the second service is the main service, thereby improving the accuracy of master-slave switching in the dual-machine hot standby system.

[0047] In one practicable manner, if Figure 2 The framework diagram of the dual-machine hot standby system in the embodiment of the present application is shown, the first service is deployed on the first server, the second service is deployed on the second server, the preset key-value database is deployed on the third server, the preset key-value database can be Redis (Remote Dictionary Server), one of the first service and the second service is the main service, and the other is the backup service, and there is a long connection and heartbeat detection between the main service and the backup service. The first server and the second server can both store local configuration files, and the local configuration files can be obtained by manual configuration by the user or obtained by receiving the central platform. For example, the local configuration file in the first server can include the second service information, and can also include the preset key-value database information, the second service information can include the address information of the second service, the address information of the second service can be the IP address and port number of the second server, the preset key-value database information is the address information of the preset key-value database, can be the IP address and port number of the preset key-value database, and can also be the identity password for using the preset key-value database.

[0048] Exemplarily, steps S10 to S50 include:

[0049] The local configuration file is read by the first service. If there is no address information of the second service in the local configuration file, it indicates that there is only the first service in the current system, and the first service is set as the main service; if the address information of the second service is obtained from the local configuration file, a long connection is established between the first service and the second service according to the address information of the second service to connect the first service and the second service. If the connection between the first service and the second service is successful, it proves that the second service is running normally as the main service, and the first service is set as the backup service; if the connection between the first service and the second service fails, the second expired key value regularly maintained by the second service is obtained from the preset key value database. If the second expired key value is successfully obtained, it proves that the second service is still regularly maintaining the second expired key value, and the second service is running normally, so the first service is set as the backup service; if the second expired key value is failed to be obtained, it proves that the second service stops regularly maintaining the second expired key value, and the second service is not running normally, so the first service is set as the main service to ensure the normal operation of the network system. The purpose of detecting whether the second service is running normally when the first service fails to successfully connect to the second service as the main service is achieved, providing an accurate basis for the first service to switch between the main and backup services, and improving the accuracy of the first service to switch between the main and backup services.

[0050] Wherein, regarding step S40, after setting the first service as the primary service, the dual-machine hot standby optimization method further includes:

[0051] Step A10: regularly maintaining the first expired key value in the preset key value database.

[0052] Wherein, the step of regularly maintaining the first expired key value in the preset key value database comprises:

[0053] Step A11, writing the first expired key value into the preset key value database;

[0054] Step A12: regularly updating the first expired key value, wherein an update interval of the first expired key value is shorter than an expiration interval of the first expired key value.

[0055] Exemplarily, the first expired key value is written into the preset key value database, and the first expired key value in the preset key value database is updated regularly, wherein the update interval of the first expired key value is less than the expiration interval of the first expired key value, so as to ensure that the first expired key value will not be deleted in the preset key value database due to expiration. When the second service fails to connect to the first service, it will continuously obtain the first expired key value from the preset key value database, wherein the time interval for the second service to continuously obtain the first expired key value from the preset key value database is greater than the expiration time interval of the first expired key value. So as an example, when the first service is not operating normally, the second service may successfully obtain the first expired key value for the first time, and because the first service is not operating normally, the first expired key value will be deleted due to expiration, so the second service will fail to obtain the first expired key value for the second time, and then the second service successfully detects that the first service is not operating normally, and the second service will switch to the main service. The purpose of assisting the second service in detecting whether the first service is operating normally when the second service fails to successfully connect to the first service as the main service is achieved, providing an accurate basis for the second service to switch between the main and standby modes, and improving the accuracy of the second service to switch between the main and standby modes.

[0056] In another practicable manner, the first service writes the first expiration key value into the preset key value database in each preset time unit in the preset first time line, wherein the preset first time line and the preset second time line together constitute a complete time line in the network system, and if the preset first time line is set as an odd time line, then the preset second time line is an even time line, and if the preset first time line is set as an even time line, then the preset second time line is an odd time line. The odd time line is a time line composed of preset basic time units arranged in odd numbers, and the even time line is a time line composed of preset basic time units arranged in even numbers. For example, assuming that the preset first timeline is an odd timeline and the preset second timeline is an even timeline, the time corresponding to the preset first timeline is the 2n+1th second, where n is a positive integer, and the first service will update the first expiration key value in each preset basic time unit in the 2n+1th second, for example, the first expiration key value may be updated once in the 1st second, again in the 3rd second, and again in the 5th second, etc.; the time corresponding to the preset second timeline is the 2n+2th second, where n is a positive integer, and the second service will obtain the first expiration key value from the preset key value database in each preset basic time unit in the 2n+2th second, for example, the first expiration key value may be obtained once in the 2nd second, again in the 4th second, and again in the 6th second, etc., wherein the second service obtains the first expiration key value at least once in each preset basic time unit of the preset second timeline.

[0057] The second service will obtain the first expired key value written by the first service from the preset key value database in each preset basic unit in the preset second timeline, wherein if the second service detects that the first expired key value fails to be obtained, it is determined that the first service is not operating normally, and if the second service does not detect that the first expired key value fails to be obtained, it is determined that the first service is operating normally. The expiration interval of the first expired key value can be set to be slightly larger than a preset basic time unit. For example, assuming that the second service always obtains the first expired key value at the beginning of a preset basic time unit, the timing of the first service writing the first expired key value in a preset basic time unit is not restricted. For example, if a preset basic time unit is 1s, the expiration time interval of the first expired key value can be set to 1.2s, or 1.5s, but not more than 2 seconds. Therefore, the embodiment of the present application achieves the purpose of assisting the second service in detecting whether the first service is operating normally by writing the first expired key value in the preset key value database by the first service, providing an accurate basis for the second service to perform active-standby switching, and improving the accuracy of the second service to perform active-standby switching.

[0058] The embodiment of the present application provides a dual-machine hot standby optimization method. Compared with the technical means used in the prior art that the main service and the backup service perform mutual fault detection through heartbeat detection to perform main-backup switching, the embodiment of the present application first reads a local configuration file through a first service, and connects the first service and the second service deployed on a second server according to the second service information in the local configuration file; if the connection is successful, it proves that the second service is running as the main service, so the first service is set as a backup service; if the connection fails, the second expired key value in the preset key value database regularly maintained by the second service is obtained to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server; if the acquisition is successful, it proves that the second service is running as the main service, so the first service is set as a backup service. The expired key value has not been deleted due to expiration, so the second server is still connected to the third server normally, and the second service is still regularly maintaining the second expired key value. At this time, it is inferred that the reason for the connection failure is probably that the network connection between the first server and the second server is jittering or disconnected, and the second service is operating normally at this time, and the first service is set as a backup service to prevent multiple main services from competing for data; if the acquisition fails, the second expired key value is deleted due to expiration, so the second server is not connected to the third server normally, and the second service is not regularly maintaining the second expired key value. At this time, it is inferred that the second server fails and causes the second service to stop running (not operating normally), and then the first service is set as the main service to ensure that the network system can operate normally. Therefore, the purpose of determining whether the reason for the connection failure is the jitter or disconnection of the network connection or the failure of the second server is achieved by obtaining the second expired key value regularly maintained by the second service from the key-value database. This can prevent the first service from misjudging that the second service stops running due to the jitter or disconnection of the network connection when the second service is running normally, and the first service switches itself to the main service when the second service is the main service. In other words, the situation where the dual-machine hot standby system is split into two independent individuals can be prevented. Therefore, the technical defect that when the main service is running normally but the network connection between the main service and the backup service is jittering or disconnected, the backup service usually misjudges that the main service has failed and sets itself as the main service, causing the normally running dual-machine hot standby system to be split into two independent individuals to compete for data is overcome, thereby improving the accuracy of switching between the main and backup services in the dual-machine hot standby system.

[0059] Embodiment 2

[0060] Further, based on the first embodiment of the present application, in another embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be described in detail later. Figure 3 In step S30, the step of obtaining the second expired key value in the preset key value database regularly maintained by the second service to determine whether the second service is operating normally includes:

[0061] Step S31, continuously acquiring from the preset key value database a second expired key value that is regularly updated by the second service, wherein an interval of continuous acquisition is greater than an expiration interval of the second expired key value;

[0062] Step S32: if the second expired key value is obtained successfully, it is determined that the second service is running normally;

[0063] Step S33: If the continuous acquisition of the second expired key value fails, it is determined that the second service is not operating normally.

[0064] In one implementable manner, the second service maintains the second expired key value by periodically updating the second expired key value in a preset key value database, wherein the update interval of the second service periodically updating the second expired key value is less than the expiration time interval of the second expired key value, so as to ensure that the second service updates the second expired key value before the second expired key value expires, and when the second expired key value expires, the second expired key value will be deleted from the preset key value database, wherein the update interval is the time interval for updating the expired key value in the preset key value database, and the expiration time interval is the time interval required for the expired key value to expire from just being updated.

[0065] Exemplarily, the second expired key value that is periodically updated by the second service is obtained from the preset key value database; if the second expired key value is successfully obtained, then after a preset time interval, the second expired key value that is periodically updated by the second service is obtained again from the preset key value database, wherein the preset interval time is greater than the expiration interval time of the second expired key value; if the second expired key value is successfully obtained again, it is determined that the second expired key value is continuously obtained successfully, and then it is determined that the second service is still periodically updating the second expired key value, so the second service is in normal operation; if the second expired key value is failed to be obtained or the second expired key value is failed to be obtained again, it is determined that the second expired key value is continuously obtained unsuccessfully, and then it is determined that the second service is not periodically updating the second expired key value, so the second service is not in normal operation, that is, the second service stops running.

[0066] In another practicable manner, the second service maintains the second expired key value by updating the second expired key value in each preset basic time unit of the preset first time line. The first service obtains the second expired key value from the preset key value database in each preset basic time unit of the preset second time line to detect whether the second service is operating normally.

[0067] The method of detecting whether the second service is running normally includes:

[0068] The first service detects whether it fails to obtain the second expiration key value from the preset key value database within each preset basic time unit of the preset second time line, wherein the second service writes the second expiration key value into the preset key value database within each preset basic time unit of the preset first time line; if it is detected that the second expiration key value fails to be obtained, it is determined that the second service is not operating normally, and if the second expiration key value fails to be obtained, it is determined that the second service is operating normally. The expiration interval of the second expiration key value can be set to be slightly larger than a preset basic time unit. For example, assuming that the first service always obtains the second expiration key value at the beginning of a preset basic time unit, the timing of the second service writing the second expiration key value within a preset basic time unit is not restricted, and a preset basic time unit is 1s, then the expiration time interval of the second expiration key value can be set to 1.2s, or 1.5s, but not more than 2 seconds.

[0069] An embodiment of the present application provides a method for a backup service in a dual-machine hot standby system to detect whether a main service is operating normally. First, the second expired key value regularly updated by the second service is continuously obtained from the preset key value database, wherein the interval time of continuous acquisition is greater than the expiration interval time of the second expired key value; therefore, if the continuous acquisition of the second expired key value is successful, it proves that the second service is still regularly updating the second expired key value in the preset key value database, and the second service is in a normal operating state; if the continuous acquisition of the second expired key value fails, it proves that the second expired key value is deleted by the preset key value database due to expiration, so the second service does not regularly update the second expired key value normally, and the second service is in an abnormal operating state, that is, the second service stops running. Therefore, the purpose of judging whether the main service is operating normally based on the expired key value in the preset key value database is achieved, and the judgment process is not affected by the network between the first service and the second service. Even if the network connection between the main service and the backup service jitters or is disconnected, the backup service can still accurately detect whether the main service has stopped running, thereby improving the accuracy of the backup service in detecting the operating state of the main service, and laying a foundation for accurate master-standby switching.

[0070] Embodiment 3

[0071] Further, based on the first and second embodiments of the present application, in another embodiment of the present application, the same or similar contents as those of the above-mentioned embodiment 1 can be referred to the above introduction, and will not be described in detail later. Figure 4 After the step of setting the first service as a standby service, the dual-machine hot standby optimization method further includes:

[0072] Step C10: if it is detected that a heartbeat loss or a long connection disconnection occurs between the first service and the second service, detecting whether a long connection request of the second service is received;

[0073] Step C20: if a long connection request of the second service is received, setting the first service as the primary service;

[0074] Step C30, establishing a long connection between the first service and the second service, so that after the second server determines that the second service is successfully connected to the first service, the second service is set as a backup service;

[0075] Step C40: if no long connection request of the second service is received, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally;

[0076] Step C50: if the second service does not operate normally, setting the first service as the main service;

[0077] Step C60: If the second service runs normally, apply to re-establish a long connection between the first service and the second service.

[0078] In this embodiment, it should be noted that the primary service and the backup service are connected via a persistent connection, and the primary service can send a heartbeat packet to the backup service via the persistent connection so that the backup service can detect whether the primary service is operating normally.

[0079] For example, if it is detected that a heartbeat loss or a long connection disconnection occurs between the first service and the second service, the local listening port is used to detect whether a long connection request for the second service is received; if a long connection request for the second service is received, it proves that the second service has been restarted, so the first service is set as the main service to ensure the normal operation of the network system and improve the efficiency of the main-standby switching. At the same time, the long connection request is responded to, and a long connection between the first service and the second service is established, so that the second server can determine that the second service is successfully connected to the first service, and then set the second service as the backup service to form a complete dual-machine hot standby system; if the long connection request for the second service is not received, the second service is obtained from the preset key-value database. The second expired key value that is regularly maintained is used to determine whether the second service is operating normally; if the second service is not operating normally, it is inferred that a fault has occurred on the second server where the second service is located, such as a power outage or a short circuit, and the first service is set as the main service to ensure the normal operation of the network system; if the second service is operating normally, when a heartbeat is lost, it is determined that a network connection jitter occurs between the first service and the second service, and the original long connection is disconnected, and an application is made to re-establish a long connection between the first service and the second service to build a complete dual-machine hot standby system; when a long connection is disconnected, it is determined that a network connection is disconnected between the first service and the second service, and an application is made to directly re-establish a long connection between the first service and the second service to build a complete dual-machine hot standby system. Among them, the specific implementation process of obtaining the second expired key value that is regularly maintained by the second service from the preset key value database to determine whether the second service is operating normally can refer to the specific contents of the above steps S31 to S33, which will not be repeated here.

[0080] An embodiment of the present application provides a method for master-slave switching in a dual-machine hot standby system when a network connection jitter or disconnection occurs. After the first service serves as a backup service, if it is detected that a heartbeat loss or a long connection disconnection occurs between the first service and the second service, it is detected whether a long connection request of the second service is received; if the long connection request of the second service is received, it proves that the second service has been restarted, and the first service is set as the main service to ensure the normal operation of the network system; and a long connection between the first service and the second service is established, so that after the second server determines that the second service has successfully connected to the first service, the second service is set as the backup service to restore the complete dual-machine hot standby system; if the long connection request of the second service is not received, the second expired key value in the preset key value database regularly maintained by the second service is obtained to determine whether the second service is operating normally; if the second service is not operating normally, it is inferred that a fault has occurred in the second server, so the first service is set as the main service to ensure the normal operation of the network system; if the second service is operating normally, an application is applied to re-establish the long connection between the first service and the second service to restore the complete dual-machine hot standby system. When the heartbeat packet is lost or the long connection is disconnected, it is achieved that the expired key value in the preset key-value database can be used to accurately detect whether a network connection failure has occurred between the second service and the first service or a failure has occurred on the server where the second service is located, and then the corresponding master-slave switching strategy is implemented, thereby avoiding the situation where the first service mistakenly judges that a failure has occurred on the second server due to a network failure between the primary and backup services. This provides a more accurate basis for the master-slave switching of the dual-machine hot standby system and improves the accuracy of the master-slave switching in the dual-machine hot standby system.

[0081] Embodiment 4

[0082] The present application embodiment provides a dual-machine hot standby optimization method, which is applied to the second server. In the first embodiment of the dual-machine hot standby optimization method of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 5 , the dual-machine hot standby optimization method includes:

[0083] Step E10, when the second service in the second server serves as the main service, the second expired key value in the preset key value database is regularly maintained, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is operating normally, so as to determine whether to set the first service as the main service or the backup service.

[0084] In this embodiment, it should be noted that when the second service in the second server serves as the main service, the second service will periodically maintain the second expired key value in the preset key value database, and monitor the first service according to the local listening port. If the long connection request sent by the first service is monitored through the local listening port, a long connection with the first service is established. When the first service fails to connect to the second service, it will obtain the second expired key value regularly maintained by the second service from the preset key value database to detect whether the second service is running normally. If the detection result is that the second service is running normally, the first service will be set as a backup service. If the detection result is that the second service is not running normally, the first service will be set as the main service. Among them, the specific implementation process of the first server obtaining the second expired key value regularly maintained by the second service from the preset key value database to detect whether the second service is running normally can refer to the specific implementation process of the above-mentioned step S30, which will not be repeated again.

[0085] Wherein, the step of regularly maintaining the second expired key value in the preset key value database comprises:

[0086] Step E11, writing the second expired key value into the preset key value database;

[0087] Step E12: regularly updating the second expiration key value, wherein the update interval of the second expiration key value is shorter than the expiration interval of the second expiration key value.

[0088] In one implementable manner, exemplarily, the second expired key value is written into the preset key value database, and the second expired key value in the preset key value database is periodically updated, wherein the update interval of the second expired key value is less than the expiration interval of the second expired key value, so as to ensure that the second expired key value will not be deleted in the preset key value database due to expiration. When the first service fails to connect to the second service, the first service will continuously obtain the second expired key value from the preset key value database, wherein the time interval for the first service to continuously obtain the second expired key value from the preset key value database is greater than the expiration time interval of the second expired key value. Therefore, when the second service is not operating normally, the first service may successfully obtain the second expired key value for the first time, and since the second service is not operating normally, the second expired key value will be deleted due to expiration, so the first service will fail to obtain the second expired key value for the second time, and then the first service successfully detects that the second service is not operating normally, and the first service will switch to the main service, thereby achieving the purpose of assisting the first service in detecting whether the second service is operating normally when the first service fails to successfully connect to the second service as the main service, providing an accurate basis for the first service to perform active-standby switching, and improving the accuracy of the active-standby switching of the first service.

[0089] In another practicable manner, the second service maintains the second expired key value by updating the second expired key value in each preset basic time unit of the preset first time line. The first service obtains the second expired key value from the preset key value database in each preset basic time unit of the preset second time line to detect whether the second service is running normally. For details, please refer to the specific contents of the above steps A11 to A12, which will not be repeated here.

[0090] The dual-machine hot standby optimization method further includes:

[0091] Step F10, when the second service does not run normally, restart the second service and connect the second service with the first service, wherein the first server sets the first service as the primary service;

[0092] Step F20, if the connection is successful, setting the second service as a backup service;

[0093] Step F30, if the connection fails, obtaining a first expired key value in a preset key value database regularly maintained by the first service to determine whether the first service is operating normally;

[0094] Step F40, if the first service is running normally, setting the second service as a standby service;

[0095] Step F50: If the first service does not run normally, the second service is set as the main service.

[0096] Exemplarily, when the second service is not running normally, the second service is restarted and a long connection request is sent to the first server to connect the second service with the first service, wherein the first server sets the first service as the main service; if the connection is successful, it proves that the first service is already running as the main service; if the connection fails, the first expired key value in the preset key value database regularly maintained by the first service is obtained to determine whether the first service is running normally; if the first service is running normally, it is inferred that the reason for the failure to connect the first service and the second service is network connection jitter or disconnection, and then the second service is set as a backup service, and the first service and the second service are attempted to be connected to restore the complete dual-machine hot standby system; if the first service is not running normally, it is inferred that the reason for the failure to connect the first service and the second service is a failure of the first server, and the second service is set as the main service to ensure the normal operation of the network system.

[0097] The embodiment of the present application provides a dual-machine hot standby optimization method, system, device and computer-readable storage medium. Compared with the technical means used in the prior art that the main service and the backup service perform mutual fault detection through heartbeat detection to perform main-backup switching, the second service as the main service in the embodiment of the present application will regularly maintain the second expired key value in the preset key value database when running. When the connection between the first service and the second service fails, the first server will obtain the second expired key value from the preset key value database; if the acquisition is successful, it is inferred that the reason for the connection failure at this time is probably the network connection jitter or disconnection, and the second service is running normally, and the first service can be used as a backup service to prevent multiple main services from competing for data; if the acquisition fails, it is inferred that the second server has a fault and caused the second service to stop running (not running normally), so the first service can be used as the main service to ensure that the network system can run normally. Therefore, it is achieved that the main service regularly maintains the expired key value to the preset key value database to assist the backup service in detecting the cause of the network failure between the main service and the backup service, that is, whether it is only the network jitter or disconnection, or the server where the main service is located has a fault. It can prevent the situation that when the main service is operating normally, the backup service mistakenly judges that the main service has stopped running due to network connection jitter or disconnection, and switches the backup service to the main service when the main service already exists. It can also prevent the situation that the dual-machine hot standby system is split into two independent individuals. Therefore, it overcomes the technical defect that when the main service is operating normally but the network connection between the main service and the backup service is jittering or disconnected, the backup service usually misjudges that the main service has failed and sets itself as the main service, causing the normally operating dual-machine hot standby system to be split into two independent individuals to compete for data, thereby affecting the normal operation of the network system. The accuracy of the switching of the main and backup services in the dual-machine hot standby system is improved.

[0098] Embodiment 5

[0099] The embodiment of the present application further provides a dual-machine hot standby optimization device, the dual-machine hot standby optimization device is applied to a first server, and the dual-machine hot standby optimization device includes:

[0100] A network connection module, configured to read a local configuration file through a first service, and connect the first service to a second service deployed on a second server according to second service information in the local configuration file;

[0101] A first active-standby switching module, configured to set the first service as a standby service if the connection is successful;

[0102] A key value acquisition module, used for acquiring a second expired key value in a preset key value database regularly maintained by the second service if the connection fails, so as to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server;

[0103] A second active-standby switching module, configured to set the first service as the primary service if the second service does not operate normally;

[0104] The third active-standby switching module is configured to set the first service as a standby service if the second service runs normally.

[0105] Optionally, the dual-machine hot standby optimization device is further used for:

[0106] If it is detected that a heartbeat loss or a long connection disconnection occurs between the first service and the second service, detecting whether a long connection request of the second service is received;

[0107] If a persistent connection request for the second service is received, setting the first service as the primary service;

[0108] Establishing a persistent connection between the first service and the second service, so that after the second server determines that the second service is successfully connected to the first service, the second service is set as a standby service;

[0109] If no long connection request of the second service is received, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally;

[0110] If the second service does not operate normally, setting the first service as the primary service;

[0111] If the second service runs normally, an application is made to re-establish a long connection between the first service and the second service.

[0112] Optionally, the key value acquisition module is further used to:

[0113] Continuously acquiring from the preset key value database a second expired key value that is periodically updated by the second service, wherein an interval of continuous acquisition is greater than an expiration interval of the second expired key value;

[0114] If the second expired key value is obtained successfully continuously, it is determined that the second service is running normally;

[0115] If the second expired key value is continuously obtained but fails, it is determined that the second service is not running normally.

[0116] Optionally, the dual-machine hot standby optimization device is further used for:

[0117] The first expired key value in the preset key value database is regularly maintained.

[0118] Optionally, the dual-machine hot standby optimization device is further used for:

[0119] Writing the first expired key value into the preset key value database;

[0120] The first expired key value is updated periodically, wherein an update interval of the first expired key value is less than an expiration interval of the first expired key value.

[0121] The dual-machine hot standby optimization device provided by the present application adopts the dual-machine hot standby optimization method in the above embodiment to solve the technical problem of low accuracy of master-slave service switching in the dual-machine hot standby system. Compared with the prior art, the beneficial effects of the dual-machine hot standby optimization device provided by the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided by the above embodiment, and other technical features in the dual-machine hot standby optimization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0122] Embodiment 6

[0123] The embodiment of the present application further provides a dual-machine hot standby optimization device, which is applied to a second server and includes:

[0124] A key value maintenance module is used to regularly maintain the second expired key value in a preset key value database when the second service in the second server serves as the main service, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is operating normally, so as to determine whether to set the first service as the main service or the backup service.

[0125] Optionally, the key value maintenance module is further used to:

[0126] Writing the second expired key value into the preset key value database;

[0127] The second expired key value is updated periodically, wherein an update interval of the second expired key value is less than an expiration interval of the second expired key value.

[0128] Optionally, the dual-machine hot standby optimization device is further used for:

[0129] When the second service does not run normally, restart the second service and connect the second service with the first service, wherein the first server sets the first service as the main service;

[0130] If the connection is successful, setting the second service as a backup service;

[0131] If the connection fails, obtaining a first expired key value in a preset key value database regularly maintained by the first service to determine whether the first service is operating normally;

[0132] If the first service is running normally, setting the second service as a standby service;

[0133] If the first service does not run normally, the second service is set as the main service.

[0134] The dual-machine hot standby optimization device provided by the present application adopts the dual-machine hot standby optimization method in the above embodiment to solve the technical problem of low accuracy of master-slave service switching in the dual-machine hot standby system. Compared with the prior art, the beneficial effects of the dual-machine hot standby optimization device provided by the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided by the above embodiment, and other technical features in the dual-machine hot standby optimization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0135] Embodiment 7

[0136] The embodiment of the present application also provides a dual-machine hot standby optimization system, the dual-machine hot standby optimization system comprising:

[0137] A first server, the first server is used to: read a local configuration file through a first service, and connect the first service and a second service deployed on a second server according to second service information in the local configuration file; if the connection is successful, set the first service as a standby service; if the connection fails, obtain a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server; if the second service is not running normally, set the first service as a primary service; if the second service is running normally, set the first service as a standby service;

[0138] A second server, the second server is used to: when the second service in the second server is used as the main service, regularly maintain the second expired key value in the preset key value database, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is running normally, so as to determine whether to set the first service as the main service or the backup service;

[0139] A third server is used to deploy the preset key-value database.

[0140] The dual-machine hot standby optimization system provided by the present application adopts the dual-machine hot standby optimization method in the above embodiment to solve the technical problem of low accuracy of master-slave service switching in the dual-machine hot standby system. Compared with the prior art, the beneficial effects of the dual-machine hot standby optimization system provided by the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided by the above embodiment, and other technical features of the dual-machine hot standby optimization system are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0141] Embodiment 8

[0142] An embodiment of the present application provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the dual-machine hot standby optimization method in the above-mentioned embodiment one.

[0143] Reference below Figure 6 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0144] like Figure 6 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.

[0145] Typically, the following systems can be connected to the I / O interface: input devices including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices including, for example, a magnetic tape, a hard disk, etc.; and communication devices. The communication device can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.

[0146] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0147] The electronic device provided by the present application adopts the dual-machine hot standby optimization method in the above embodiment to solve the technical problem of low accuracy of master-slave service switching in the dual-machine hot standby system. Compared with the prior art, the beneficial effects of the electronic device provided by the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided by the above embodiment, and other technical features in the electronic device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0148] It should be understood that the various parts of the present disclosure can be implemented with hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0149] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0150] Embodiment 9

[0151] This embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon, and the computer-readable program instructions are used to execute the dual-machine hot standby optimization method in the above-mentioned embodiment 1.

[0152] The computer-readable storage medium provided in the embodiment of the present application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, a system or a device or used in combination with it. The program code contained on the computer-readable storage medium can be transmitted with any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0153] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.

[0154] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: reads a local configuration file through a first service, and connects the first service and a second service deployed on a second server according to the second service information in the local configuration file; if the connection is successful, the first service is set as a backup service; if the connection fails, the second expired key value in a preset key value database regularly maintained by the second service is obtained to determine whether the second service is operating normally, wherein the preset key value database is deployed on a third server; if the second service is not operating normally, the first service is set as the main service; if the second service is operating normally, the first service is set as a backup service.

[0155] Alternatively, when the second service in the second server serves as the main service, the second expired key value in the preset key value database is regularly maintained, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is running normally, so as to determine whether to set the first service as the main service or the backup service.

[0156] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0157] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0158] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0159] The computer-readable storage medium provided by the present application stores computer-readable program instructions for executing the above-mentioned dual-machine hot standby optimization method, which solves the technical problem of low accuracy of active-standby service switching in a dual-machine hot standby system. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided in the above-mentioned embodiment, and will not be described in detail here.

[0160] Embodiment 10

[0161] The present application also provides a computer program product, including a computer program, which implements the steps of the dual-machine hot standby optimization method as described above when executed by a processor.

[0162] The computer program product provided by the present application solves the technical problem of low accuracy of active / standby service switching in a dual-machine hot standby system. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of the present application are the same as the beneficial effects of the dual-machine hot standby optimization method provided by the above embodiment, and will not be described in detail here.

[0163] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.

Claims

1. A dual-machine hot standby optimization method, It is characterized in that Applied to the first server, the dual-machine hot standby optimization method includes: Reading a local configuration file through the first service, and connecting the first service and a second service deployed on a second server according to second service information in the local configuration file; If the connection is successful, setting the first service as a backup service; If the connection fails, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally, wherein the preset key value database is deployed on a third server; If the second service does not operate normally, setting the first service as the primary service; If the second service runs normally, the first service is set as a backup service.

2. The dual-machine hot standby optimization method according to claim 1, It is characterized in that After setting the first service as a standby service, the dual-machine hot standby optimization method further includes: If it is detected that a heartbeat loss or a long connection disconnection occurs between the first service and the second service, detecting whether a long connection request of the second service is received; If a persistent connection request for the second service is received, setting the first service as the primary service; Establishing a persistent connection between the first service and the second service, so that after the second server determines that the second service is successfully connected to the first service, the second service is set as a standby service; If no long connection request of the second service is received, obtaining a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is operating normally; If the second service does not operate normally, setting the first service as the primary service; If the second service runs normally, an application is made to re-establish a long connection between the first service and the second service.

3. The dual-machine hot standby optimization method according to claim 1 or 2, It is characterized in that The step of obtaining the second expired key value in the preset key value database regularly maintained by the second service to determine whether the second service is operating normally includes: Continuously acquiring from the preset key value database a second expired key value that is periodically updated by the second service, wherein an interval of continuous acquisition is greater than an expiration interval of the second expired key value; If the second expired key value is obtained successfully continuously, it is determined that the second service is running normally; If the second expired key value is continuously obtained but fails, it is determined that the second service is not running normally.

4. The dual-machine hot standby optimization method according to claim 1 or 2, It is characterized in that After setting the first service as the primary service, the dual-machine hot standby optimization method further includes: The first expired key value in the preset key value database is regularly maintained.

5. The dual-machine hot standby optimization method as claimed in claim 4, It is characterized in that The step of regularly maintaining the first expired key value in the preset key value database comprises: Writing the first expired key value into the preset key value database; The first expired key value is updated periodically, wherein an update interval of the first expired key value is less than an expiration interval of the first expired key value.

6. A dual-machine hot standby optimization method, It is characterized in that Applied to the second server, the dual-machine hot standby optimization method includes: When the second service does not run normally, restart the second service and connect the second service with the first service, wherein the first server sets the first service as the main service; If the connection is successful, setting the second service as a backup service; If the connection fails, obtaining a first expired key value in a preset key value database regularly maintained by the first service to determine whether the first service is operating normally; If the first service is running normally, setting the second service as a standby service; If the first service does not run normally, setting the second service as the main service; When the second service in the second server serves as the main service, the second expired key value in the preset key value database is regularly maintained, wherein the first server obtains the second expired key value from the preset key value database to determine whether the second service is running normally, so as to determine whether to set the first service as the main service or the backup service.

7. The dual-machine hot standby optimization method according to claim 6, It is characterized in that The step of regularly maintaining the second expired key value in the preset key value database comprises: Writing the second expired key value into the preset key value database; The second expired key value is updated periodically, wherein an update interval of the second expired key value is less than an expiration interval of the second expired key value.

8. A dual-machine hot standby optimization system, It is characterized in that The dual-machine hot standby optimization system comprises: A first server, the first server is used to: read a local configuration file through a first service, and connect the first service and a second service deployed on a second server according to second service information in the local configuration file; if the connection is successful, set the first service as a standby service; if the connection fails, obtain a second expired key value in a preset key value database regularly maintained by the second service to determine whether the second service is running normally, wherein the preset key value database is deployed on a third server; if the second service is not running normally, set the first service as a primary service; if the second service is running normally, set the first service as a standby service; A second server, the second server is used to: when the second service is not operating normally, restart the second service, and connect the second service with the first service, wherein the first server sets the first service as the main service; if the connection is successful, the second service is set as the backup service; if the connection fails, the first expired key value in the preset key value database regularly maintained by the first service is obtained to determine whether the first service is operating normally; if the first service is operating normally, the second service is set as the backup service; if the first service is not operating normally, the second service is set as the main service; when the second service in the second server is used as the main service, the second expired key value in the preset key value database is regularly maintained, wherein the first server determines whether the second service is operating normally by obtaining the second expired key value from the preset key value database, so as to determine whether the first service is set as the main service or the backup service; A third server is used to deploy the preset key-value database.

9. An electronic device, It is characterized in that The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the steps of the dual-machine hot standby optimization method described in any one of claims 1 to 5 or 6 to 7.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a program for implementing a dual-machine hot standby optimization method, and the program for implementing a dual-machine hot standby optimization method is executed by a processor to implement the steps of the dual-machine hot standby optimization method as described in any one of claims 1 to 5 or 6 to 7.

Citation Information

Patent Citations

  • Cloud storage data synchronizing framework and implementing method thereof

    CN102882927A

  • Hierarchical indexing method based on distributed real-time database system (DRTDBS)

    CN105930345A