CN-121996356-A - Container management method, apparatus, computer device, computer readable storage medium, and computer program product
Abstract
The present application relates to a container management method, apparatus, computer device, computer readable storage medium and computer program product. The method comprises the steps of monitoring the memory use condition of a first container instance where a target application program operates, determining the number of candidate available container resources corresponding to the target application program if the memory use condition is detected to meet a preset abnormal condition, setting the first container instance to an isolation state and creating a second container instance if the number of candidate available container resources meets the preset number condition, wherein the isolation state represents that the receiving of a new service request is stopped, forwarding historical processing data of the first container instance and the new service request aiming at the first container instance to the second container instance so that the second container instance processes the new service request, and deleting the first container instance. By adopting the method, the memory overflow risk of the container can be effectively treated on the basis of ensuring user experience.
Inventors
- LIU ZHIXIANG
- HUANG YUMING
- Wu Dilin
- LI RUICHUAN
- CHEN YAN
Assignees
- 金蝶软件(中国)有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260129
Claims (10)
- 1. A method of container management, the method comprising: monitoring the memory use condition of a first container instance in which a target application program operates; If the memory use condition is detected to meet a preset abnormal condition, determining the number of candidate available container resources corresponding to the target application program; If the number of the candidate available container resources meets a preset number condition, setting the first container instance to be in an isolation state and creating a second container instance, wherein the isolation state characterizes that the receiving of the new service request is stopped; Forwarding historical processing data of the first container instance and the new service request for the first container instance to the second container instance to cause the second container instance to process the new service request; Deleting the first container instance.
- 2. The method of claim 1, wherein the target application has a memory state detection interface built therein, and wherein the monitoring the memory usage of the first container instance in which the target application is running comprises: periodically detecting the memory usage amount of the target application program through the memory state detection interface; and if the memory usage condition is detected to meet the preset abnormal condition, determining the number of the candidate available container resources corresponding to the target application program comprises the following steps: Comparing the memory use quantity with the preset memory quantity of the target application program through the memory state detection interface to determine whether the memory use condition represents the preset abnormal condition; If the memory service condition represents the preset abnormal condition, modifying a response state code of the memory state detection interface from a first state code representing normal to a second state code representing isolatable through the memory state detection interface; and periodically calling the memory state detection interface to acquire the response state code, and if the response state code is the second state code, the number of times of meeting a preset number of times threshold value, determining that the memory use condition of the first container instance meets the preset abnormal condition.
- 3. The method according to claim 1, wherein determining the number of available container resources candidate for the target application if the memory usage is detected to satisfy a preset exception condition comprises: Inquiring the network address of the first container instance to obtain the identity of the first container instance; determining an application instance group to which the target application program belongs according to the identity of the first container instance; counting the total number of container instances in the application instance group which are currently in a serviceable state; and determining the quantity of the candidate available container resources according to the total number of the container instances and the quantity of the first container instances.
- 4. The method of claim 3, wherein the predetermined number of conditions includes a number of the candidate available container instances being greater than or equal to 1, and wherein if the number of candidate available container resources satisfies the predetermined number of conditions, setting the first container instance to an isolated state and creating a second container instance comprises: If the number of the available container instances meets the preset number condition, modifying the label information of the first container instance so as to enable the first container instance to be separated from the container control of the application instance group; the second container instance is created based on the desired number of instances of the set of application instances.
- 5. The method of claim 2, wherein after setting the first container instance to an isolated state and creating a second container instance if the number of candidate available container resources satisfies a preset number condition, the method comprises: Executing a memory dump operation for the target application program; in response to completion of the memory dump operation, modifying, by the target application, the response state code of the memory state detection interface from the second state code to a third state code indicative of completion of a memory dump; the deleting the first container instance includes: periodically inquiring a response state code of the memory state detection interface; Deleting the first container instance if the response status code is detected to change from the second status code to the third status code; And/or deleting the first container instance if the response status code is detected not to be changed into the third status code within the preset duration.
- 6. The method according to claim 5, wherein the method is based on a pre-configured script program, and the script program is loaded into a system corresponding to the first container instance by means of a storage volume mount when the first container instance is started; The preset duration is smaller than the termination grace time corresponding to the first container instance, and the termination grace time is used for defining the maximum waiting interval between the request of initiating to delete the first container instance and the termination operation of the first container instance.
- 7. A container management device, the device comprising: the monitoring module is used for monitoring the memory use condition of the first container instance where the target application program runs; The determining module is used for determining the number of candidate available container resources corresponding to the target application program if the memory use condition is detected to meet a preset abnormal condition; the setting module is used for setting the first container instance to be in an isolation state and creating a second container instance if the number of the candidate available container resources meets the preset number condition, wherein the isolation state characterizes that the receiving of the new service request is stopped; a forwarding module, configured to forward historical processing data of the first container instance and the new service request for the first container instance to the second container instance, so that the second container instance processes the new service request; And the deleting module is used for deleting the first container instance.
- 8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when the computer program is executed.
- 9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
- 10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
Description
Container management method, apparatus, computer device, computer readable storage medium, and computer program product Technical Field The present application relates to the field of container technology, and in particular, to a container management method, apparatus, computer device, computer readable storage medium, and computer program product. Background With the popularity of cloud computing and microservice architecture, containerization technology has become a core standard for modern application deployment and operation. In the related art, an application running in a container generally configures an upper memory use limit to prevent a single application from consuming host node resources without limitation, and a runtime crash caused by memory exhaustion may cause a service transient interruption and a user experience damage. When the memory overflow risk of the containerized application is processed, the problem of passive service interruption is solved, and therefore user experience is affected. Disclosure of Invention In view of the foregoing, it is desirable to provide a container management method, apparatus, computer device, computer-readable storage medium, and computer program product that can secure a user experience. In a first aspect, the present application provides a container management method, the method comprising: monitoring the memory use condition of a first container instance in which a target application program operates; If the memory use condition is detected to meet a preset abnormal condition, determining the number of candidate available container resources corresponding to the target application program; If the number of the candidate available container resources meets a preset number condition, setting the first container instance to be in an isolation state and creating a second container instance, wherein the isolation state characterizes that the receiving of the new service request is stopped; Forwarding historical processing data of the first container instance and the new service request for the first container instance to the second container instance to cause the second container instance to process the new service request; Deleting the first container instance. In some embodiments, the target application program is provided with a memory state detection interface, and the monitoring of the memory use condition of the first container instance where the target application program operates includes: periodically detecting the memory usage amount of the target application program through the memory state detection interface; and if the memory usage condition is detected to meet the preset abnormal condition, determining the number of the candidate available container resources corresponding to the target application program comprises the following steps: Comparing the memory use quantity with the preset memory quantity of the target application program through the memory state detection interface to determine whether the memory use condition represents the preset abnormal condition; If the memory service condition represents the preset abnormal condition, modifying a response state code of the memory state detection interface from a first state code representing normal to a second state code representing isolatable through the memory state detection interface; and periodically calling the memory state detection interface to acquire the response state code, and if the response state code is the second state code, the number of times of meeting a preset number of times threshold value, determining that the memory use condition of the first container instance meets the preset abnormal condition. In some embodiments, if the memory usage is detected to meet a preset exception condition, determining the number of available container resources candidate corresponding to the target application includes: Inquiring the network address of the first container instance to obtain the identity of the first container instance; determining an application instance group to which the target application program belongs according to the identity of the first container instance; counting the total number of container instances in the application instance group which are currently in a serviceable state; and determining the quantity of the candidate available container resources according to the total number of the container instances and the quantity of the first container instances. In some embodiments, the preset number of conditions includes that the number of the candidate available container instances is greater than or equal to 1, and the setting the first container instance to the isolated state and creating a second container instance if the number of the candidate available container resources satisfies the preset number of conditions includes: If the number of the available container instances meets the preset number condition, modifying the label information of the first co