A method and device for running a resident process, an electronic device, and a storage medium

By identifying the target process that successfully acquires the lock within a resident process and keeping it alive, while monitoring and pulling other processes, the problem of business interruption is solved, and the continuity and concurrency security of business services are achieved.

CN115904668BActive Publication Date: 2026-11-20SHENZHEN FUTU NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211653677.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-21
Publication Date
2026-11-20
Estimated Expiration
2042-12-21

AI Technical Summary

Technical Problem

In existing technologies, the failure of commonly used processes due to various reasons leads to business service interruptions, lack of data sensitivity and management effectiveness, and affects the performance of data systems.

Method used

By acquiring lock requests from multiple resident processes, the target resident process that successfully acquires the lock is identified. The lock is then kept alive by the lock-keeping process, which continuously monitors other resident processes. Processes that fail to acquire the lock continue to pull the lock so that they can switch immediately if the target process crashes.

Benefits of technology

It ensured uninterrupted business services, improved data sensitivity and management efficiency, and guaranteed the concurrent security of multiple resident processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115904668B_ABST
    Figure CN115904668B_ABST
Patent Text Reader

Abstract

The application discloses a method and device for running a resident process, an electronic device and a storage medium. The method comprises the following steps: acquiring locking applications of multiple resident processes after the multiple resident processes are started, the locking applications carrying application information; determining a target resident process with a successful locking application according to the application information of the multiple resident processes, so as to execute a corresponding preset service through the target resident process; keeping alive the lock through a lock alive process matched with the target resident process during a process in which the target resident process continuously survives; and continuously pulling other resident processes except the target resident process from the multiple resident processes, so that the other resident processes continue to apply for locking. The application determines the target resident process with a successful locking application from the multiple resident processes, keeps alive the lock to execute the corresponding preset service while ensuring the concurrent safety of the multiple resident processes, and continuously pulls the other resident processes, so that the preset service can be continuously provided externally.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for running a resident process, an electronic device, and a storage medium. Background Technology

[0002] To achieve disaster recovery functions such as preventing business interruptions during the provision of business services by the equipment, the current common practice is to use resident processes corresponding to the business to achieve uninterrupted external business services. However, due to various reasons, the commonly used processes may crash, causing business services to be interrupted. Summary of the Invention

[0003] To address the aforementioned technical problems, embodiments of this application provide a method and apparatus for running a resident process, an electronic device, a computer-readable storage medium, and a computer program product.

[0004] According to one aspect of the embodiments of this application, a method for running a resident process is provided, comprising: obtaining locking requests issued by multiple resident processes for a lock after startup, wherein the locking requests carry application information; determining a target resident process that has successfully acquired a lock based on the application information of each of the multiple resident processes, so as to execute a corresponding preset business through the target resident process; keeping the lock alive through a lock keep-alive process that matches the target resident process while the target resident process remains alive; and continuously pulling other resident processes among the multiple resident processes that have not successfully acquired a lock, except for the target resident process, so that the other resident processes can continue to apply for a lock.

[0005] According to one aspect of the embodiments of this application, a running apparatus for resident processes includes: an acquisition unit, configured to acquire locking requests issued by multiple resident processes for a lock after startup, the locking requests carrying application information; a locking unit, configured to determine a target resident process that has successfully acquired a lock based on the application information of each of the multiple resident processes, so as to execute a corresponding preset business through the target resident process; a keep-alive unit, configured to keep the lock alive by using a lock keep-alive process that matches the target resident process while the target resident process remains alive; and a pull-up unit, further configured to continuously pull up other resident processes among the multiple resident processes that have not successfully acquired a lock, excluding the target resident process, so that the other resident processes can continue to apply for a lock.

[0006] According to one aspect of the embodiments of this application, an electronic device includes: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the aforementioned method for running a resident process.

[0007] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, on which computer-readable instructions are stored, which, when executed by a computer's processor, cause the computer to perform the running method of a resident process as described above.

[0008] According to one aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the resident process operation method provided in the various optional embodiments described above.

[0009] In the technical solution provided in the embodiments of this application, after obtaining the locking requests issued by multiple resident processes after their startup, the target resident process that successfully acquires the lock is determined based on the application information contained in each of the lock requests. This allows the target resident process to execute the corresponding preset service; that is, only the resident process that acquires the lock can run, enabling the preset service to be executed. While the target resident process remains alive, a lock keep-alive process matching the target resident process keeps the lock alive. The lock keep-alive process refreshes the expiration time of the lock acquired by the target resident process before it expires, ensuring that the resident process that has acquired the lock continues to hold it as long as it does not exit. Furthermore, for other resident processes that have not successfully acquired the lock (excluding the target resident process), other resident processes are continuously pulled to allow them to continue applying for the lock. If the current target resident process crashes, other resident processes of the same type can be immediately started to ensure uninterrupted external service. In this way, after identifying the target resident process that has successfully acquired the lock from multiple resident processes, the lock is kept alive to execute the corresponding preset business, ensuring the concurrent safety of multiple resident processes. Furthermore, while monitoring the status of the target resident process, other resident processes are managed. By continuously pulling data from other resident processes, a new target resident process can be identified in a timely manner after the target resident process crashes, improving data sensitivity and enabling the continuous provision of preset business to the outside world.

[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0011] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:

[0012] Figure 1 This is a schematic diagram of the system structure for implementing the persistent process operation method provided in this application;

[0013] Figure 2 This is a flowchart illustrating an exemplary embodiment of this application of a method for running a resident process;

[0014] Figure 3 This is a flowchart illustrating an exemplary embodiment of the present application showing a method for two servers to implement resident processes.

[0015] Figure 4 yes Figure 2 A flowchart of step S202 in an exemplary embodiment shown in the illustrated example;

[0016] Figure 5 yes Figure 4 The flowchart of step S401 in the illustrated embodiment is shown in an exemplary embodiment;

[0017] Figure 6 This is a flowchart in an exemplary embodiment of determining a new target persistent process by continuously pulling other persistent processes after the target persistent process exits;

[0018] Figure 7 This is a flowchart illustrating an exemplary embodiment of the present application of a method for two servers to implement resident processes after the current lock is released;

[0019] Figure 8 yes Figure 6 A flowchart of step S602 in an exemplary embodiment shown in the illustrated example;

[0020] Figure 9 yes Figure 8 A flowchart of step S802 in an exemplary embodiment shown in the illustrated example;

[0021] Figure 10 Is Figure 9 A flowchart of an exemplary embodiment following step S903 of the illustrated embodiment, which determines that the target resident process corresponding to the current locking information is alive;

[0022] Figure 11This is a flowchart illustrating the steps of other resident processes requesting locks in the running method of a resident process as shown in an exemplary embodiment of this application;

[0023] Figure 12 yes Figure 2 A flowchart of step S203 in an exemplary embodiment shown in the illustrated example;

[0024] Figure 13 Is Figure 12 A flowchart of steps following step S1202 in an exemplary embodiment;

[0025] Figure 14 yes Figure 13 A flowchart of step S1304 in an exemplary embodiment shown in the illustrated example;

[0026] Figure 15 This is a flowchart illustrating the steps of managing the lock-keeping process in an exemplary embodiment of the running method of a resident process according to this application.

[0027] Figure 16 This is a block diagram illustrating a running apparatus for a resident process, as shown in an exemplary embodiment of this application;

[0028] Figure 17 This is a schematic diagram of the structure of a computer system suitable for implementing the electronic devices of the present application embodiments. Detailed Implementation

[0029] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0030] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0031] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0032] In this application, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0033] In related technologies, to achieve disaster recovery functions such as preventing business interruptions during the provision of services by equipment, persistent processes corresponding to the business are often used to ensure uninterrupted external business services. For example, persistent processes periodically poll relevant tasks so that if one persistent process crashes for various reasons, another persistent process of the same type can start to ensure uninterrupted external services. However, due to the lack of data sensitivity in the system, the management efficiency of persistent processes is often very low, preventing other persistent processes of the same type from starting immediately, thus affecting the performance of the data system.

[0034] To address the above-mentioned problems, embodiments of this application propose a method and apparatus for running a resident process, an electronic device, and a computer-readable storage medium, which will be described in detail below.

[0035] Please refer to the following first. Figure 1 , Figure 1 This is a schematic diagram of the system structure for implementing the resident process operation method provided in this application. The system includes modules such as a locking module 101, a lock keeping module 102, and a process launch module 103.

[0036] After receiving lock requests carrying application information from multiple resident processes after they start, the locking module 101 is configured to successfully complete the locking process based on the application information of each of the multiple resident processes and determine the target resident process that has successfully acquired the lock, so that the corresponding preset business can be executed through the target resident process; the lock keep-alive module 102 is configured to keep the lock alive through the lock keep-alive process that matches the target resident process while the target resident process continues to live; the process start-up module 103 is configured to continuously pull other resident processes that have not successfully acquired the lock from among the multiple resident processes, except for the target resident process, so that the other resident processes can continue to apply for the lock, and if the lock is successfully acquired, the locking module 101 and the lock keep-alive module 102 are called again.

[0037] Figure 2 This is a flowchart illustrating a method for running a resident process, as shown in an exemplary embodiment of this application. This method can be applied to... Figure 1 The implementation environment shown can be used in other implementation environments, and this embodiment does not limit this.

[0038] like Figure 2As shown, in an exemplary embodiment, the method for running the resident process may include steps S201 to S204, which are described in detail below:

[0039] Step S201: Obtain the lock requests issued by multiple resident processes after they start.

[0040] Among them, multiple resident processes are of the same type. After multiple resident processes are started, only one resident process needs to run to implement the corresponding preset business. Therefore, after multiple resident processes are started, the system will obtain the locking requests of multiple resident processes and determine one resident process to lock based on the locking requests.

[0041] Step S202: Based on the application information of each of the multiple resident processes, determine the target resident process that has been successfully locked, so as to execute the corresponding preset business through the target resident process.

[0042] Each of the multiple resident processes carries its own lock request information. Locking is performed on the multiple resident processes based on the request information. The resident process that successfully acquires the lock becomes the target resident process. In this way, the corresponding preset business can be executed by running the target resident process, avoiding the situation where multiple resident processes are running at the same time and ensuring the concurrency safety of multiple resident processes in a distributed environment.

[0043] It should be noted that in the embodiments provided in this application, in order to achieve the above steps, a distributed lock is set up, allowing resident processes of the same type to compete for the lock. Only the process that ultimately acquires the lock can run, thus satisfying the requirement that only one instance of the same type of process can run at a time. Distributed locks are characterized by high efficiency and fast locking speed. Furthermore, the distributed lock uses the distributed caching framework Redis (RemoteDictionaryServer), which can use its setnx (lock) command to determine the target resident process and lock it, ensuring mutual exclusion. That is, only the target resident process will be locked. In addition, as long as most Redis nodes are running normally, the locking operation can be performed, providing good fault tolerance.

[0044] Step S203: While the target resident process continues to exist, the lock is kept alive by the lock keep-alive process that matches the target resident process.

[0045] To prevent deadlocks caused by process crashes and lock expiration, the distributed caching framework Redis sets a lock release timer after acquiring a lock on a target persistent process. The lock is released when the timer expires. Therefore, to ensure that a target persistent process that has acquired a lock continues to hold it as long as it doesn't exit, this application provides a lock keep-alive process. While the target persistent process remains alive, the lock is kept alive by a lock keep-alive process matched to the target persistent process. The lock keep-alive process continuously refreshes the lock holding time of the target persistent process before the lock is released, preventing other persistent processes from acquiring the lock when they are restarted, thus avoiding the possibility of two processes of the same type running simultaneously.

[0046] Step S204: Continuously pull other resident processes that have not successfully acquired the lock from multiple resident processes other than the target resident process, so that the other resident processes can continue to request the lock.

[0047] Once the target persistent process is identified, other persistent processes that have not successfully acquired the lock will be continuously retrieved from multiple persistent processes, excluding the target persistent process, so that these other persistent processes can continue to request the lock. In this way, the status of the target persistent process is monitored while other persistent processes are managed. This ensures that if the current target persistent process exits for any reason, other persistent processes of the same type can be started immediately to run, thus ensuring uninterrupted external business services.

[0048] In another embodiment provided in this application, multiple resident processes reside on different servers. Taking two resident processes and their corresponding servers A and B as an example, after the resident process on server A successfully acquires the lock, the resident process on server B is continuously pulled and continues to acquire the lock. Figure 3 As shown, Figure 3 This is a flowchart illustrating an exemplary embodiment of the present application of a method for running two servers implementing resident processes, which specifically includes:

[0049] For server A, step S301, start the resident process a;

[0050] Step S302: Issue a lock request;

[0051] Step S303, Locking successful, proceed to steps S304 and S305;

[0052] Step S304: Execute the corresponding preset service;

[0053] Step S305: Start the lock-keeping process that matches the resident process a;

[0054] Step S306: Switch the lock keep-alive process from hibernation to keep the resident process a alive;

[0055] For server B, in step S307, start resident process b; wherein, resident process a and resident process b are started simultaneously.

[0056] Step S308: Issue a lock request;

[0057] Step S309, locking failed, proceed to step S310;

[0058] In step S310, the resident process b exits and returns to step S307. Due to the lock acquisition failure, the lock keep-alive process in server B remains in a dormant state.

[0059] As can be seen from the above, in the method provided by the above embodiments, by using multiple resident processes to carry lock requests with application information, a target resident process with mutual exclusion is determined from multiple resident processes, and after locking is completed, the lock is kept alive to execute the corresponding preset business, which ensures the concurrent safety of multiple resident processes. In addition, while monitoring the status of the target resident process, other resident processes are managed. By continuously pulling other resident processes, a new target resident process is determined in a timely manner after the target resident process crashes, which improves data sensitivity and enables the continuous provision of preset business to the outside world.

[0060] Please see Figure 4 , Figure 4 yes Figure 2 The flowchart of step S202 in the illustrated embodiment is shown in an exemplary embodiment. For example... Figure 4 As shown, step S202 may specifically include steps S401 to S404, through which the target persistent process that has successfully acquired the lock is determined, as detailed below:

[0061] Step S401: Obtain the process information of each of the multiple resident processes, and construct multiple key-value pairs corresponding to the multiple resident processes based on the application information and process information.

[0062] After successfully locking the target persistent process, its relevant information is stored in the database. Since Redis is a key-value storage system, this application determines whether a persistent process is the target persistent process by checking if multiple key-value pairs corresponding to persistent processes exist in the database. Therefore, after multiple persistent processes start, the process information of each persistent process is obtained, and multiple key-value pairs corresponding to the multiple persistent processes are constructed based on the application information and process information.

[0063] In another embodiment of this social situation, the application information for the resident process includes a process startup instruction containing startup parameters and a process identifier, such as... Figure 5 As shown, Figure 5 yes Figure 4The flowchart of step S401 in the illustrated embodiment is shown in an exemplary embodiment. Step S401 may specifically include steps S501 to S503, through which multiple key-value pairs corresponding to multiple resident processes are constructed. A detailed description follows:

[0064] Step S501: Identify the startup parameters and process identifier contained in the process startup instruction of the resident process, and obtain the key value based on the startup parameters and process identifier.

[0065] Based on the request information and process information of the resident process, corresponding key-value pairs are constructed. The key-value pair is obtained by constructing the startup parameters and process identifier included in the request information. Specifically, the process startup command is in the format of "phpartisantest:get_price --market=1", where the process identifier of the resident process is "test:get_price", and "--market=1" is the startup parameter. After encrypting the startup parameter, the key-value pair is obtained based on the process identifier and the encrypted startup parameter. For example, if the encryption method is MD5, the encrypted startup parameter is "DDD297B0495F6C5E522ABE59EA002DFD". The key-value pair finally constructed by the resident process according to the process startup command corresponds to "test:get_price_DDD297B0495F6C5E522ABE59EA002DFD".

[0066] Step S502: Obtain the storage value corresponding to the key value based on the process information, startup parameters and process identifier of the resident process.

[0067] After obtaining the key-value pairs, the process information and application information, including startup parameters and process identifiers, are serialized into JSON. The storage value corresponding to the key-value pairs is then constructed based on the serialized string. The process information includes basic information about resident processes, such as the process address and process ID.

[0068] Step S503: Construct key-value pairs for resident processes based on key-value pairs and stored values ​​to obtain multiple key-value pairs corresponding to multiple resident processes.

[0069] After obtaining the key and the corresponding storage value of the resident process, a unique key-value pair for the resident process is constructed based on the key and the storage value, thereby obtaining multiple key-value pairs corresponding to multiple resident processes.

[0070] Step S402: Retrieve the stored reference key-value pairs from the database, compare the multiple key-value pairs with the preset reference key-value pairs respectively, and obtain the comparison results.

[0071] After obtaining multiple key-value pairs for multiple resident processes, each key-value pair is compared with a preset reference key-value pair to determine whether the key-value pair for the resident process already exists in the database. Specifically, comparing the multiple key-value pairs with their preset reference key-value pairs actually involves comparing each key-value pair with a reference key-value pair to obtain a comparison result. The comparison result can be characterized as either a match or an inconsistency. If they match, it means that the corresponding key-value pair is already stored in the database, and the lock acquisition request of the resident process corresponding to the key-value pair fails; if they do not match, it means that the lock acquisition request of the resident process corresponding to the key-value pair succeeds.

[0072] Step S403: When the comparison result indicates that there is no reference key-value pair matching the key-value pair in the database, the key-value pair is stored in the database to complete the locking process of the resident process corresponding to the key-value pair.

[0073] When the comparison result indicates that no matching reference key-value pair exists in the database, it means that the resident process corresponding to the key-value pair has successfully requested a lock. First, the key-value pair is stored in the database for locking processing of the resident process corresponding to the key-value pair. Then, based on the locking processing, the current locking parameters are obtained. Locking parameters may include, but are not limited to, locking time and releasing time. The locking parameters are entered into the storage value of the key-value pair to update the key-value pair. Finally, based on the updated key-value pair, the locking information is obtained, completing the locking of the resident process. The Redis database uses an HSet data storage structure, which is essentially a hash table. The key value of the HSet itself is xlock_key_map. Each key within the HSet is a string obtained by concatenating singal_case_x_lock_key_list with the key used by each resident process when acquiring a lock. The stored value is the key used by each resident process when acquiring a lock.

[0074] Step S404: Determine that the resident process corresponding to the key-value pair stored in the database is the target resident process that has successfully acquired the lock.

[0075] If the corresponding key-value pair can be stored in the database, it means that the lock request of the resident process corresponding to the key-value pair is successful. After the lock processing in step S403, it can be determined that the resident process corresponding to the key-value pair stored in the database is the target resident process that has successfully acquired the lock.

[0076] Thus, this embodiment determines whether a resident process is a target resident process for successful locking by judging whether the key-value pair of the resident process can be successfully stored in the database, thereby improving locking efficiency.

[0077] Please see Figure 6 , Figure 6 This is a flowchart in an exemplary embodiment of determining a new target resident process by continuously pulling other resident processes after the target resident process exits. For example... Figure 6 As shown, it may specifically include steps S601 to S603, which are described in detail below:

[0078] Step S601: When the target resident process exits, the matching lock keep-alive process is switched to a dormant state, and the lock request information of other resident processes that failed to acquire the lock (excluding the target resident process) is obtained.

[0079] After detecting the exit of the current target persistent process, the matching lock keep-alive process is switched to a dormant state. At this time, other persistent processes that failed to acquire the lock, besides the target persistent process, may have a chance to successfully acquire the lock due to their continuous restart. Therefore, after switching the matching lock keep-alive process to a dormant state, the lock request information of other persistent processes that failed to acquire the lock, besides the target persistent process, is obtained to determine whether the other persistent processes can successfully acquire the lock.

[0080] Step S602: Based on the locking request information of other resident processes, determine the new target resident process that has been successfully locked, so as to continue to execute the preset business through the new target resident process.

[0081] Since the current target resident process has exited, in order to ensure the continued execution of the preset business, one of the other resident processes must become the new target resident process. Therefore, based on the locking request information of the other resident processes, the new target resident process that has successfully locked is determined so that the preset business can continue to be executed through the new target resident process.

[0082] Step S603: Start a new lock keep-alive process that matches the new target resident process. While the new target resident process continues to exist, the lock is kept alive through the new lock keep-alive process.

[0083] After locking a new target persistent process, a default expiration time is set for the lock, which is released upon expiration. Therefore, to ensure that a newly acquired target persistent process can continuously hold the lock as long as it doesn't exit, a lock keep-alive process is provided. While the target persistent process remains alive, the lock keep-alive process, matched with the target persistent process, keeps the lock alive. The lock keep-alive process continuously refreshes the lock's expiration time before it expires, preventing other persistent processes from acquiring the lock when they are restarted, thus avoiding the possibility of two processes of the same type running simultaneously.

[0084] In this embodiment, after detecting the exit of the target resident process and switching the matching lock-keeping process to a dormant state, the new target resident process that has successfully acquired the lock is determined based on the lock application information of the other resident processes that failed to acquire the lock, in order to continue to execute the preset business through the new target resident process and ensure uninterrupted business.

[0085] The persistent process operation method provided in this application, after switching the matching lock keep-alive process to a dormant state, since the lock information of the lock keep-alive includes the lock release time, after the lock keep-alive process goes to sleep, the lock corresponding to the exited target persistent process may have been released or may not have been released.

[0086] If the lock corresponding to the exiting target persistent process has been released, the method for determining the new target persistent process from other persistent processes follows... Figure 2 The illustrated embodiment provides a method for running resident processes. For example, in another embodiment provided in this application, multiple resident processes reside on different servers. Taking two resident processes and their corresponding servers A and B as an example, after the resident process on server A successfully acquires a lock, the resident process on server B is continuously pulled and continues to acquire the lock; subsequently, the resident process on server A exits, and the corresponding lock release time is reached. Figure 7 As shown, Figure 7 This is a flowchart illustrating an exemplary embodiment of the present application of a method for two servers to implement resident processes after the current lock is released, which specifically includes:

[0087] For server A, step S701, start the resident process a;

[0088] Step S702: Issue a lock request;

[0089] Step S703, Locking successful, proceed to steps S704 and S705;

[0090] Step S704: Execute the corresponding preset service;

[0091] Step S705: Start the lock keep-alive process that matches the resident process a;

[0092] Step S706: Switch the lock keep-alive process from hibernation to keep the resident process a alive;

[0093] Step S707: Exit resident process a;

[0094] Step S708: Switch the lock keep-alive process to a dormant state. After the held lock is released, proceed to step S715.

[0095] For server B, in step S709, start the resident process b;

[0096] Step S710: Issue a lock request;

[0097] Step S711, locking failed, proceed to step S712;

[0098] Step S712, exit the resident process b;

[0099] Step S713: Start the resident process b; there may be multiple steps between step S713 and step S712 where the resident process b starts, fails to acquire a lock, and then exits.

[0100] Step S714: Issue a lock request;

[0101] Step S715, locking successful, proceed to steps S716 and S717;

[0102] Step S716: Execute the corresponding preset service;

[0103] Step S717: Start the lock keep-alive process that matches the resident process b;

[0104] Step S718: Switch the lock keep-alive process from hibernation to keep the resident process b alive.

[0105] If the lock corresponding to the exited target resident process has not been released, please refer to Figure 8 , Figure 8 yes Figure 6 The flowchart of step S602 in the illustrated embodiment is shown in an exemplary embodiment. Figure 8 As shown, step S602 may include steps S801 to S803, which are described in detail below:

[0106] Step S801: If the lock keep-alive process is in a dormant state and the current lock has not been released, then obtain the current locking information.

[0107] If the lock keep-alive process is in a dormant state and the current lock has not been released, it is necessary to determine whether other resident processes can inherit the current lock. Therefore, the current lock information is retrieved from the database.

[0108] Depend on Figure 4 As can be seen from step S403 in the embodiment, when storing locking information to the database, the locking information corresponds to the target resident process at that time. Therefore, when it is necessary to obtain the current locking information from the database, the current locking information can be obtained from the database through the key-value pairs or even the key-value pairs of other resident processes that failed to lock because the corresponding key-value pairs already exist in the database.

[0109] Step S802: Based on the current locking information and the locking request information of other resident processes, determine whether the current locking information needs to be updated.

[0110] After retrieving the current locking information from the database, the system also retrieves the locking request information of other resident processes. Based on the current locking information and the locking request information of other resident processes, it determines whether other resident processes can inherit the current lock. If they can inherit it, the current locking information needs to be updated; otherwise, the current locking information does not need to be updated.

[0111] Step S803: If it is necessary to update the current locking information, determine the other resident process to which the locking request information belongs as the new target resident process, and update the current locking information based on the process information of the new target resident process and the locking request information to complete the locking process of the new target resident process.

[0112] After determining that the current locking information needs to be updated, the other resident processes to which the locking request information belongs are identified as the new target resident processes. Then, based on the process information and locking request information of the new target resident processes, the current locking information is updated. Specifically, the contents of the current locking information can be processed using Redis's `SET` (remove) operation, and then the key-value pairs, process information, and locking request information of the new target resident processes are stored in the database to form the new locking information for the new target resident processes, thus completing the locking process for the new target resident processes.

[0113] As can be seen from the above, in the method provided in the above embodiments, when the lock corresponding to the exiting target persistent process has been released, the method for determining the new target persistent process from other persistent processes follows... Figure 2 The persistent process operation method provided in the illustrated embodiment determines a new target persistent process. If the lock corresponding to the exiting target persistent process is not released, it is necessary to determine whether other persistent processes can inherit the unreleased lock based on the current locking information and locking request information of other persistent processes. This determines whether the current locking information can be updated, thereby determining the target persistent process. By determining a new target persistent process and continuing to execute preset services through it, uninterrupted service is ensured.

[0114] Please see Figure 9 , Figure 9 yes Figure 8 The flowchart of step S802 in the illustrated embodiment is shown in an exemplary embodiment. Figure 9 As shown, step S802 may include steps S901 to S903, which are described in detail below:

[0115] Step S901: Identify the current address identifier in the current locking information.

[0116] Since the locking information is obtained from key-value pairs of the target resident process stored in the database, and the process information and request information, including startup parameters and process identifier, of the target resident process are serialized into JSON, the corresponding key-value storage value can be constructed based on the serialized string. The process information includes the address identifier and process ID of the resident process, among other basic information. Therefore, after obtaining the current locking information, the current address identifier can be obtained by analyzing and identifying the current locking information. It should be noted that the address identifier can represent the IP address of the server where the corresponding resident process and the lock keep-alive process reside.

[0117] Step S902: Obtain the process information of other resident processes, including other address identifiers, and determine whether the other address identifiers are consistent with the current address identifier.

[0118] After identifying the current address identifier, it is compared with other address identifiers included in the process information of other resident processes. That is, it is determined whether the server where the lock corresponding to the current locking information is located is the same as the server where other resident processes are located.

[0119] Step S903: If other address identifiers are consistent with the current address identifier, determine whether the target resident process corresponding to the current locking information is alive.

[0120] If other address identifiers are inconsistent with the current address identifier, other resident processes will need to wait for the lock to be released before they can successfully acquire the lock. Therefore, after determining that other address identifiers are consistent with the target address identifier, it indicates that other resident processes may inherit the lock corresponding to the currently acquired lock. However, the target resident process corresponding to the currently acquired lock may be restarted after exiting. Therefore, after determining that the address identifiers are consistent, it is necessary to determine whether the target resident process corresponding to the currently acquired lock is still alive.

[0121] Specifically, after a resident process becomes the target resident process and is locked, the process information and application information of the currently surviving resident process are saved to form a process file. The process ID included in the process information is used as the process file directory. The existence of the process file indicates that the corresponding resident process is alive. Therefore, this embodiment identifies the process ID included in the process information in the locking information, and searches for the existence of a corresponding process file directory using the process ID. If it exists, it determines whether the target resident process corresponding to the current locking information is alive; otherwise, it is not alive.

[0122] Step S904: If the target resident process corresponding to the current locking information is not alive, it is determined that the current locking information needs to be updated.

[0123] If the target resident process corresponding to the current locking information is not alive, in order to ensure the continuous execution of the preset business, it is determined that the current locking information needs to be updated to identify other resident processes to which the locking request information belongs as the new target resident process. The current locking information is then updated based on the process information of the new target resident process and the locking request information, thereby completing the locking process of the new target resident process.

[0124] In another exemplary embodiment provided in this application, if the target resident process corresponding to the current locking information is alive, besides the possibility that the original target resident process has been restarted, it could also be that a newly started resident process of another type has reused the process ID. Therefore, after determining that the target resident process corresponding to the current locking information is alive, it is necessary to further determine whether the type of the alive target resident process is legal. For example... Figure 10 As shown, Figure 10 Is Figure 9 This is a flowchart from an exemplary embodiment following step S903 of the illustrated embodiment, which determines that the target resident process corresponding to the current locking information is alive. (See flowchart for example.) Figure 10 As shown, the process may include steps S1001 to S1003, which are described in detail below:

[0125] Step S1001: If the target resident process corresponding to the current locking information is alive, then obtain the process startup instruction of the alive target resident process and identify the process startup instruction of the current locking information.

[0126] After determining that the target resident process corresponding to the current locking information is alive, in order to determine whether a newly started resident process of another type has reused the process ID, it is necessary to check whether the type of the alive target resident process is consistent with the type of the resident process corresponding to the current locking information. Since the application information includes a process startup instruction, which contains startup parameters and a process identifier, and the process identifier can represent the type of the corresponding resident process, this embodiment uses the startup instruction to represent the type of the corresponding resident process. Therefore, after determining that the target resident process corresponding to the current locking information is alive, the process startup instruction of the alive target resident process is obtained, and the process startup instruction of the current locking information is identified.

[0127] Step S1002: Determine whether the process startup instruction corresponding to the surviving target resident process is consistent with the process startup instruction of the current target locking information.

[0128] The process startup instruction corresponding to the surviving target resident process is determined to be consistent with the process startup instruction of the current target locking information. The result can be characterized as consistent or inconsistent. If consistent, it means that the surviving target resident process is indeed a resident process of the same type as the process stored in the current locking information. If inconsistent, it means that a newly started resident process of another type has reused the process number of the current locking information.

[0129] In step S1003, if there is a discrepancy, the surviving target resident process is exited, and the current locking information is updated.

[0130] If the process startup command of the surviving target resident process matches the process startup command of the current target locking information, it indicates that a newly started resident process of another type has reused the process ID of the current locking information. Therefore, the surviving target resident process exits, forcing an update to the current locking information. Specifically, the other resident processes whose locking request information belongs to are identified as the new target resident processes. Then, based on the process information and locking request information of the new target resident process, the current locking information is updated. Specifically, the contents of the current locking information can be processed using Redis's `SET` (remove) operation, and then the key-value pairs, process information, and locking request information of the new target resident process are stored in the database to form the new locking information for the new target resident process, thus completing the locking process for the new target resident process.

[0131] Therefore, using the method of the above embodiments, when the lock corresponding to the exited target resident process is not released, in the process of determining whether the current locking information needs to be updated, the method further determines whether the current locking information needs to be updated based on the address identifier and whether the target resident process corresponding to the current locking information is alive. Furthermore, when the process startup instruction reuses the process number of the current locking information in other types of newly started resident processes, the current locking information is forcibly updated so that it can continue to execute the preset business and ensure uninterrupted business.

[0132] like Figure 11 As shown, Figure 11 This is a flowchart illustrating the steps of other resident processes requesting locks in the running method of a resident process according to an exemplary embodiment of this application, which is described in detail below:

[0133] Step S1101: Obtain the current locking information;

[0134] Step S1102: Determine whether the address identifiers of other resident processes are consistent with the current address identifier of the current locking information. If they are consistent, proceed to step S1103; otherwise, proceed to step S1106.

[0135] Step S1103: Determine whether the target resident process corresponding to the current locking information is alive. If it is alive, proceed to step S1104; otherwise, proceed to step S1105.

[0136] Step S1104: Determine whether the process start instruction corresponding to the surviving target resident process is consistent with the process start instruction of the current target locking information. If they are consistent, proceed to step S1106; otherwise, proceed to step S1105.

[0137] Step S1105: Force update the current locking information and start the matching lock keep-alive process;

[0138] Step S1106, End.

[0139] Please see Figure 12 , Figure 12 yes Figure 2 The flowchart of step S203 in the illustrated embodiment is shown in an exemplary embodiment. Figure 12 As shown, it may include steps S1201 to S1202, which are described in detail below:

[0140] Step S1201: Obtain the key-value pair of the target resident process, and obtain the locking information of the target resident process based on the stored value in the key-value pair.

[0141] Process information includes process ID and address identifier. Therefore, when constructing the storage value corresponding to the key-value pair, the storage value corresponding to the key-value pair is obtained based on the startup parameters, process ID, and process ID and address identifier included in the process information.

[0142] The acquisition of locking information occurs after a resident process successfully acquires a lock. First, the key-value pair is stored in the database to process the locking of the corresponding resident process. Then, based on this locking process, the current locking parameters are obtained. These parameters may include, but are not limited to, the locking time and the lock release time. The locking parameters are then entered into the key-value pair's storage value to update the key-value pair. Finally, the locking information is obtained based on the updated key-value pair. Therefore, in this embodiment, the locking information of the target resident process includes an address identifier, i.e., the server where the target resident process resides.

[0143] Step S1202: Identify the address identifier corresponding to the stored value in the locking information, and obtain the lock keep-alive process that matches the address identifier to keep the lock alive.

[0144] The lock keep-alive process is bound to the server and will only keep locks on the server it resides in. Therefore, after identifying the target persistent process, we can identify the address identifier corresponding to the value stored in the lock information of the target persistent process and obtain the lock keep-alive process that matches the address identifier to keep the lock alive.

[0145] In another exemplary embodiment, after obtaining the lock keep-alive process that matches the target resident process, it is also necessary to detect the lock keep-alive process. For example... Figure 13 As shown, Figure 13 Is Figure 12 The flowchart of steps following step S1202 in the illustrated embodiment is shown in an exemplary embodiment. Figure 13 As shown, it may include steps S1301 to S1305, which are described in detail below:

[0146] Step S1301: Detect the number of times the lock-keep-alive process runs, compare the number of runs with a preset threshold, and obtain the comparison result.

[0147] The comparison result can be represented as the number of runs being less than or equal to a preset threshold, or as the number of runs being greater than a preset threshold. The preset threshold is set to prevent the lock-and-live process from freezing due to excessively long execution times. The preset threshold can be set according to user needs or device parameters; no restrictions are imposed here.

[0148] Step S1302: If the comparison result indicates that the number of runs is less than or equal to a preset threshold, then the lock is kept alive through the lock keep-alive process, and the lock's expiration time is updated.

[0149] If the comparison result indicates that the number of runs is less than or equal to the preset threshold, it means that the lock keep-alive operation has not exceeded the preset threshold. In this case, the lock is kept alive through the lock keep-alive process, and the lock's expiration time is updated.

[0150] Step S1303: If the comparison result indicates that the number of runs is greater than the preset threshold, then exit the lock-keeping process and initialize the number of runs.

[0151] If the comparison result indicates that the number of runs exceeds the preset threshold, it means that the lock-keep-alive process has exceeded the preset threshold. In order to prevent the lock-keep-alive process from running for too long and becoming seemingly dead, it is actively exited and the number of runs is initialized to ensure normal use next time.

[0152] Step S1304: Obtain the address identifier from the locking information of the target resident process, and obtain a new lock keep-alive process that matches the address identifier to keep the lock alive.

[0153] After the lock keep-alive process exits, in order to keep the lock of the target resident process alive, it is necessary to start the matching lock keep-alive process again. Since the lock keep-alive process is bound to the server, it will only keep the locks on the server it is on. Therefore, by identifying and obtaining the address identifier in the locking information of the target resident process, and obtaining a new lock keep-alive process that matches the address identifier, the lock can be kept alive.

[0154] Furthermore, before determining a new lock keep-alive process, it is necessary to further determine whether the lock needs to be kept alive through the lock keep-alive process at the current moment based on the lock release time. If not, the lock keep-alive process should be switched to a dormant state. When keep-alive is needed, a matching lock keep-alive process should be determined to reduce the system's operating burden.

[0155] In another exemplary embodiment provided in this application, the process for determining a new lock keep-alive process involves traversing all locking information stored in the database to obtain matching locking information. For example... Figure 14 As shown, Figure 14 yes Figure 13 The flowchart of step S1304 in the illustrated embodiment is shown in an exemplary embodiment. Step S1304 may include steps S1401 to S1402, which are described in detail below:

[0156] Step S1401: Obtain the locking information of the target resident process through the lock keep-alive process, and identify the address identifier in the locking information.

[0157] After the lock keep-alive process exits, it is restarted. After restarting, in order to keep the matching locks alive, the lock keep-alive process will retrieve all the stored locking information from the database. Since the lock keep-alive process is bound to the server, it will only keep the locks on the server it is on alive. Therefore, after retrieving all the stored locking information, it will identify the address identifier in the locking information.

[0158] It should be noted that the management of resident processes and lock-keep-alive processes in this application can be achieved through the process management tool supervisor. supervisor can directly control the start and exit of processes, and can monitor the status of processes, making it easier to manage processes.

[0159] Step S1402: When it is determined that the address identifier of the lock keep-alive process is consistent with the address identifier in the locking information, the keep-alive process is determined to be the new lock keep-alive process corresponding to the target resident process.

[0160] When the address identifier of the lock keep-alive process is determined to be consistent with the address identifier in the locking information, it indicates that the lock keep-alive process and the lock corresponding to the locking information are on the same server. Therefore, the lock keep-alive process can keep the lock corresponding to the locking information alive, and the keep-alive process is determined to be the new lock keep-alive process corresponding to the target resident process.

[0161] In addition, similar to the process of other resident processes requesting locks, after the lock keep-alive process determines that the address identifier of the lock keep-alive process is consistent with the address identifier in the lock information, it also needs to determine whether the target resident process corresponding to the lock information is alive, and it also needs to determine whether the process start instruction corresponding to the surviving target resident process is consistent with the process start instruction in the lock information. Only after determining that it is alive and the process start instruction is consistent does it need to keep the lock process alive through the lock keep-alive process.

[0162] Specifically, after a resident process becomes the target resident process and is locked, the process information and application information of the currently surviving resident process are saved to form a process file. The process ID included in the process information is used as the process file directory. The existence of the process file indicates that the corresponding resident process is alive. Therefore, this embodiment identifies the process ID included in the process information in the locking information, and searches for the existence of a corresponding process file directory using the process ID. If it exists, it determines whether the target resident process corresponding to the current locking information is alive; otherwise, it is not alive. After determining that it is alive, it is determined whether the process start instruction corresponding to the surviving target resident process is consistent with the process start instruction in the locking information. The determination result can be represented as consistent or inconsistent. If consistent, it means that the surviving target resident process is indeed a resident process of the same type as the process stored in the locking information. If inconsistent, it means that a newly started resident process of another type reuses the process ID in the locking information. In this case, the lock keep-alive process will not keep the current lock alive. The operation of the lock keep-alive process requires not only that the resident process and the lock are on the same server, but also that the process type of the resident process is consistent with and legal in the locking information.

[0163] Step S1305: Monitor the running status of the new lock keep-alive process in real time. After the new lock keep-alive process runs once, it enters a sleep state for a preset time length and increments the corresponding number of runs by one.

[0164] The lock keep-alive process is configured to continuously refresh the lock release time of the holding lock before the lock expires. Since the lock release time has a certain duration, the lock keep-alive process does not need to run continuously. Therefore, after the new lock keep-alive process runs once, it enters a sleep state for a preset time length. After the sleep state ends, it enters the next round of keep-alive. This is mainly to prevent excessively frequent access to Redis during the lock keep-alive process, which would overload Redis. Therefore, in this embodiment, the running status of the new lock keep-alive process is monitored in real time. After either the lock keep-alive process or the new lock keep-alive process runs once, it enters a sleep state for a preset time length, and the corresponding run count is incremented by one. Similarly, if the comparison result indicates that the run count is less than or equal to the preset threshold, the lock is kept alive by the lock keep-alive process without needing to determine the start of the lock keep-alive process. In this case, the running status of the lock keep-alive process also needs to be monitored in real time. After the lock keep-alive process runs once, it enters a sleep state for a preset time length, and the corresponding run count is incremented by one.

[0165] Thus, the technical solution of this embodiment of the application sets a preset threshold related to the number of times the lock keep-alive process runs. When the number of runs exceeds the preset threshold, the lock keep-alive process exits and the number of runs is initialized to prevent the lock keep-alive process from becoming dead due to running for too long. In addition, the running status of the lock keep-alive process or the new lock keep-alive process is monitored in real time. After the lock keep-alive process or the new lock keep-alive process runs once, it enters a sleep state for a preset time, which reduces the data operation burden of Redis.

[0166] like Figure 15 , Figure 15 This is a flowchart illustrating the steps of managing the lock-keeping process in an exemplary embodiment of the running method of a resident process, as detailed below:

[0167] Step S1501: Determine whether the number of times the lock-keep-alive process has run exceeds a preset threshold. If yes, proceed to step S1510; otherwise, proceed to step S1502.

[0168] Step S1502: Obtain the lock release time;

[0169] Step S1503: Determine whether it is necessary to keep the lock alive. If so, proceed to step S1504; otherwise, proceed to step S1509.

[0170] Step S1504: Retrieve locking information from the database;

[0171] Step S1505: Determine whether the address identifier of the lock keep-alive process is consistent with the address identifier in the lock information. If they are consistent, proceed to step S1506; otherwise, proceed to step S1503.

[0172] Step S1506: Determine whether the target resident process corresponding to the locking information is alive. If it is alive, proceed to step S1507; otherwise, proceed to step S1503.

[0173] Step S1507: Determine whether the process startup instruction corresponding to the surviving target resident process is consistent with the process startup instruction of the locking information. If they are consistent, proceed to step S1508; otherwise, proceed to step S1503.

[0174] Step S1508: Keep the lock alive through the lock keep-alive process;

[0175] Step S1509: Switch the lock-keep process to hibernation mode. After hibernation ends, proceed to step S1501.

[0176] Step S1510, End.

[0177] Figure 16This is a block diagram illustrating a resident process running device 1600, as shown in an exemplary embodiment of this application. Figure 16 As shown, the device includes:

[0178] The acquisition unit 1601 is used to acquire lock requests issued by multiple resident processes after they start, and the lock requests carry application information.

[0179] The locking unit 1602 is used to determine the target resident process that has been successfully locked based on the application information of multiple resident processes, so as to execute the corresponding preset business through the target resident process;

[0180] The keep-alive unit 1603 is used to keep the lock alive by using the lock keep-alive process that matches the target resident process while the target resident process continues to live.

[0181] The pull-up unit 1604 is used to continuously pull other resident processes that have not successfully acquired the lock, except for the target resident process, so that the other resident processes can continue to request the lock.

[0182] This device employs the persistent process operation method provided in this application. After the acquisition unit 1601 receives lock requests from multiple persistent processes after their startup, the locking unit 1602 determines the target persistent process that has successfully acquired the lock based on the request information contained in each of these requests. This allows the target persistent process to execute the corresponding preset service; that is, only the persistent process that has acquired the lock can run, enabling the preset service to be executed. During the continued existence of the target persistent process, the keep-alive unit 1603 also keeps the lock alive through a lock keep-alive process that matches the target persistent process. The lock keep-alive process can refresh the expiration time of the lock acquired by the target persistent process before it expires, ensuring that the persistent process that has acquired the lock continues to hold it as long as it does not exit. Unit 1604 continuously pulls other resident processes that have not successfully acquired a lock among multiple resident processes other than the target resident process, so that the other resident processes can continue to apply for locks. If the current target resident process crashes, it can immediately start other resident processes of the same type to run, so as to ensure uninterrupted external business services.

[0183] In another exemplary embodiment, the locking unit 1602 is further configured to obtain process information of each of the multiple resident processes, construct multiple key-value pairs corresponding to the multiple resident processes based on the application information and process information; obtain the stored reference key-value pairs from the database, compare the multiple key-value pairs with the preset reference key-value pairs respectively, and obtain the comparison result; when the comparison result indicates that there is no reference key-value pair matching the key-value pair in the database, store the key-value pair in the database to complete the locking process of the resident process corresponding to the key-value pair; and determine that the resident process corresponding to the key-value pair stored in the database is the target resident process that has been successfully locked.

[0184] In another exemplary embodiment, the locking unit 1602 is further configured to identify the startup parameters and process identifier contained in the process startup instruction of the resident process, obtain a key value based on the startup parameters and process identifier; obtain a storage value corresponding to the key value based on the process information of the resident process, the startup parameters and the process identifier; construct key-value pairs for the resident process based on the key value and the storage value, and obtain multiple key-value pairs corresponding to multiple resident processes.

[0185] In another exemplary embodiment, the keep-alive unit 1603 is further configured to obtain the storage value corresponding to the key value based on the startup parameters, process identifier, and process number and address identifier included in the process information; and keep the lock alive through the lock keep-alive process that matches the target resident process, including: obtaining the key-value pair of the target resident process, obtaining the locking information of the target resident process based on the storage value in the key-value pair; identifying the address identifier corresponding to the storage value in the locking information, and obtaining the lock keep-alive process that matches the address identifier to keep the lock alive.

[0186] In another exemplary embodiment, the pull-up unit 1604 is further configured to switch the matching lock keep-alive process to a dormant state when the target resident process exits, and obtain the lock application information of other resident processes that have not successfully acquired the lock among multiple resident processes other than the target resident process; determine a new target resident process that has successfully acquired the lock based on the lock application information of the other resident processes, so as to continue to execute the preset business through the new target resident process; start a new lock keep-alive process that matches the new target resident process, and keep the lock alive through the new lock keep-alive process while the new target resident process continues to exist.

[0187] In another exemplary embodiment, the pull-up unit 1604 is further configured to: if the lock keep-alive process is in a dormant state and the current lock has not been released, obtain the current locking information; determine whether the current locking information needs to be updated based on the current locking information and the locking request information of other resident processes; if the current locking information needs to be updated, determine the other resident process to which the locking request information belongs as the new target resident process, and update the current locking information based on the process information and locking request information of the new target resident process to complete the locking process of the new target resident process.

[0188] In another exemplary embodiment, the pull-up unit 1604 is further configured to identify the current address identifier in the current locking information; obtain other address identifiers included in the process information of other resident processes, and determine whether the other address identifiers are consistent with the current address identifier; if the other address identifiers are consistent with the current address identifiers, determine whether the target resident process corresponding to the current locking information is alive; if the target resident process corresponding to the current locking information is not alive, determine that the current locking information needs to be updated.

[0189] In another exemplary embodiment, the pull-up unit 1604 is further configured to, if the target resident process corresponding to the current locking information is alive, obtain the process start instruction of the alive target resident process and identify the process start instruction of the current locking information; determine whether the process start instruction corresponding to the alive target resident process is consistent with the process start instruction of the current target locking information; if they are inconsistent, exit the alive target resident process and update the current locking information.

[0190] In another exemplary embodiment, the device further includes:

[0191] The count detection module is used to detect the number of times the lock keep-alive process runs. It compares the number of runs with a preset threshold and obtains the comparison result. If the comparison result indicates that the number of runs is less than or equal to the preset threshold, the lock is kept alive through the lock keep-alive process, and the lock's expiration time is updated. If the comparison result indicates that the number of runs is greater than the preset threshold, the lock keep-alive process is exited, and the number of runs is initialized. It identifies and obtains the address identifier in the locking information of the target resident process and obtains a new lock keep-alive process that matches the address identifier to keep the lock alive. It monitors the running status of the lock keep-alive process or the new lock keep-alive process in real time. After the lock keep-alive process or the new lock keep-alive process runs once, it enters a sleep state for a preset time length and increments the corresponding number of runs by one.

[0192] In another exemplary embodiment, the count detection module is further configured to obtain the locking information of the target resident process through the lock keep-alive process and identify the address identifier in the locking information; when it is determined that the address identifier of the lock keep-alive process is consistent with the address identifier in the locking information, the keep-alive process is determined to be the new lock keep-alive process corresponding to the target resident process.

[0193] It should be noted that the persistent process running device and the persistent process running method provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the persistent process running device provided in the above embodiments can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not a limitation here.

[0194] Embodiments of this application also provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device enables the resident process running method provided in the above embodiments.

[0195] Figure 17 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 17 The computer system 1700 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0196] like Figure 17 As shown, the computer system 1700 includes a Central Processing Unit (CPU) 1701, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 1702 or programs loaded from storage portion 1708 into Random Access Memory (RAM) 1703. The RAM 1703 also stores various programs and data required for system operation. The CPU 1701, ROM 1702, and RAM 1703 are interconnected via a bus 1704. An Input / Output (I / O) interface 1705 is also connected to the bus 1704.

[0197] The following components are connected to I / O interface 1705: an input section 1706 including a keyboard, mouse, etc.; an output section 1707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1708 including a hard disk, etc.; and a communication section 1709 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1709 performs communication processing via a network such as the Internet. A drive 1710 is also connected to I / O interface 1705 as needed. Removable media 1711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1710 as needed so that computer programs read from them can be installed into storage section 1708 as needed.

[0198] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1709, and / or installed from removable medium 1711. When the computer program is executed by central processing unit (CPU) 1701, it performs various functions defined in the system of this application.

[0199] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0200] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0201] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.

[0202] Another aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned method for running a resident process. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not incorporated into the electronic device.

[0203] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the resident process operation method provided in the various embodiments described above.

[0204] The above are merely preferred embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for running a resident process, characterized in that, The method includes: The system retrieves lock requests issued by multiple resident processes after their startup, each request carrying request information; wherein the multiple resident processes are of the same type. Based on the application information of each of the multiple resident processes, the target resident process that has been successfully locked is determined, so that the corresponding preset business can be executed through the target resident process; During the continuous operation of the target resident process, the lock is kept alive by a lock keep-alive process that matches the target resident process. Specifically, the key-value pairs of the target resident process are obtained, and the locking information of the target resident process is obtained based on the stored values ​​in the key-value pairs. The process information of the resident process includes the process ID and address identifier. The address identifier corresponding to the stored value in the locking information is identified, and a lock keep-alive process matching the address identifier is obtained to keep the lock alive. The lock keep-alive process is bound to the server and only keeps locks on the server it resides on alive. The system continuously retrieves other persistent processes (excluding the target persistent process) that have not successfully acquired the lock, so that these other persistent processes can continue to request the lock; wherein... After acquiring a lock-keeping process that matches the target resident process: The number of times the lock keep-alive process runs is detected, and the number of runs is compared with a preset threshold to obtain a comparison result. If the comparison result indicates that the number of runs is less than or equal to the preset threshold, the lock is kept alive through the lock keep-alive process, and the lock's expiration time is updated. If the comparison result indicates that the number of runs is greater than the preset threshold, the lock keep-alive process is exited, and the number of runs is initialized. The address identifier in the locking information of the target resident process is obtained, and a new lock keep-alive process matching the address identifier is obtained to keep the lock alive. The running status of the new lock keep-alive process is monitored in real time. After the new lock keep-alive process runs once, it enters a sleep state for a preset time length, and the corresponding running count is incremented by one.

2. The method according to claim 1, characterized in that, The step of determining the target persistent process that has successfully acquired the lock based on the application information of the plurality of persistent processes includes: Obtain the process information of each of the multiple resident processes, and construct multiple key-value pairs corresponding to the multiple resident processes based on the application information and process information; Retrieve stored reference key-value pairs from the database, and compare each of the multiple key-value pairs with a preset reference key-value pair to obtain the comparison result; When the comparison result indicates that there is no reference key-value pair matching the key-value pair in the database, the key-value pair is stored in the database to complete the locking process of the resident process corresponding to the key-value pair. The persistent process corresponding to the key-value pair stored in the database is determined to be the target persistent process that has successfully acquired the lock.

3. The method according to claim 2, characterized in that, The application information includes a process startup instruction containing startup parameters and a process identifier; the construction of multiple key-value pairs corresponding to the multiple resident processes based on the application information and process information includes: Identify the startup parameters and process identifier contained in the process startup instruction of the resident process, and obtain a key value based on the startup parameters and the process identifier; The storage value corresponding to the key value is obtained based on the process information, startup parameters, and process identifier of the resident process. Based on the key value and the stored value, key-value pairs of the resident processes are constructed to obtain multiple key-value pairs corresponding to the multiple resident processes.

4. The method according to claim 3, characterized in that, The process information includes a process ID and an address identifier; obtaining the storage value corresponding to the key value based on the process information of the resident process, the startup parameters, and the process identifier includes: Based on the startup parameters, the process identifier, and the process number and address identifier included in the process information, the storage value corresponding to the key value is obtained; The step of keeping the lock alive through a lock keep-alive process that matches the target resident process includes: Obtain the key-value pair of the target persistent process, and obtain the locking information of the target persistent process based on the stored value in the key-value pair; Identify the address identifier corresponding to the stored value in the locking information, and obtain the lock keep-alive process that matches the address identifier to keep the lock alive.

5. The method according to claim 1, characterized in that, After continuously pulling the other persistent processes among the plurality of persistent processes that failed to acquire the lock (excluding the target persistent process), the method further includes: When the target persistent process exits, the matching lock keep-alive process is switched to a dormant state, and the lock request information of other persistent processes that failed to acquire the lock, excluding the target persistent process, is obtained. Based on the locking request information of the other resident processes, a new target resident process that has successfully locked the process is determined so that the preset service can continue to be executed through the new target resident process; A new lock keep-alive process matching the new target resident process is started. While the new target resident process remains alive, the lock is kept alive through the new lock keep-alive process.

6. The method according to claim 5, characterized in that, The step of determining the new target persistent process that has successfully acquired the lock based on the lock acquisition request information of the other persistent processes includes: If the lock keep-alive process is in a dormant state and the current lock has not been released, then obtain the current locking information; Based on the current locking information and the locking request information of the other resident processes, determine whether the current locking information needs to be updated; If it is necessary to update the current locking information, then other resident processes to which the locking request information belongs are identified as the new target resident processes, and the current locking information is updated based on the process information and locking request information of the new target resident processes to complete the locking process of the new target resident processes.

7. The method according to claim 6, characterized in that, The step of determining whether to update the current locking information based on the current locking information and the locking request information of other resident processes includes: Identify the current address identifier in the current locking information; Obtain other address identifiers, including process information of the other resident processes, and determine whether the other address identifiers are consistent with the current address identifier; If other address identifiers are consistent with the current address identifier, then determine whether the target resident process corresponding to the current locking information is alive; If the target resident process corresponding to the current locking information is not alive, then it is determined that the current locking information needs to be updated.

8. The method according to claim 7, characterized in that, The method further includes: If the target persistent process corresponding to the current locking information is alive, then obtain the process start instruction of the alive target persistent process, and identify the process start instruction of the current locking information; Determine whether the process startup instruction corresponding to the surviving target resident process is consistent with the process startup instruction of the current target locking information; If there is a discrepancy, the surviving target resident process will exit, and the current locking information will be updated.

9. The method according to claim 1, characterized in that, Obtaining a new lock keep-alive process that matches the address identifier includes: The locking information of the target resident process is obtained through the lock keep-alive process, and the address identifier in the locking information is identified. When the address identifier of the lock keep-alive process is determined to be consistent with the address identifier in the locking information, the lock keep-alive process is determined to be the new lock keep-alive process corresponding to the target resident process.

10. A device for running a resident process, characterized in that, include: The acquisition unit is used to acquire lock requests issued by multiple resident processes after they start, wherein the lock requests carry application information; wherein the multiple resident processes are of the same type; The locking unit is used to determine the target resident process that has been successfully locked based on the application information of the plurality of resident processes, so as to execute the corresponding preset business through the target resident process; The keep-alive unit is used to keep the lock alive by using a lock keep-alive process that matches the target resident process while the target resident process remains alive. Specifically, it obtains the key-value pair of the target resident process, retrieves the locking information of the target resident process based on the stored value in the key-value pair, and the process information of the resident process includes the process ID and address identifier. It identifies the address identifier corresponding to the stored value in the locking information and obtains the lock keep-alive process that matches the address identifier to keep the lock alive. The lock keep-alive process is bound to the server and only keeps locks alive on the server it resides on. The pull-up unit is used to continuously pull up other resident processes (excluding the target resident process) that have not successfully acquired the lock, so that these other resident processes can continue to request the lock; wherein... The operating device is also used to, after acquiring a lock keep-alive process that matches the target resident process: The number of times the lock keep-alive process runs is detected, and the number of runs is compared with a preset threshold to obtain a comparison result. If the comparison result indicates that the number of runs is less than or equal to the preset threshold, the lock is kept alive through the lock keep-alive process, and the lock's expiration time is updated. If the comparison result indicates that the number of runs is greater than the preset threshold, the lock keep-alive process is exited, and the number of runs is initialized. The address identifier in the locking information of the target resident process is obtained, and a new lock keep-alive process matching the address identifier is obtained to keep the lock alive. The running status of the new lock keep-alive process is monitored in real time. After the new lock keep-alive process runs once, it enters a sleep state for a preset time length, and the corresponding running count is incremented by one.

11. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the electronic device to implement the method of running a resident process as described in any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by the computer's processor, cause the computer to perform the method of running a resident process as described in any one of claims 1 to 9.

Citation Information

Patent Citations

  • Key value buffer memory implementation method and device

    CN105955971A

  • Resident process keep-alive system and method

    CN108845875A