Container state judgment method and system in cloud computing
By recording the resource occupancy of the container process, calculating the resource ratio and slope, and adjusting the execution time and content of the survival probe, the problem of container probe detection frequency and performance balance in cloud computing is solved, and timely detection of container status and resource saving are achieved. .
Patent Information
- Application Number
- CN202410926768.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-09-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In cloud computing, frequent container probe detection may cause performance overhead. How to balance the frequency of probe detection and system performance to ensure the monitoring and maintenance of container health status.
By recording the resource occupancy of the program process and the survival probe process in the container, calculating the resource ratio and slope, adjusting the execution time and content of the survival probe, and using a fuzzy control algorithm to determine the new execution time and content to balance the probe detection Frequency and comprehensiveness.
It effectively saves container resources, avoids intrusion into the code in the container, ensures timely detection of container status and maintenance of health status, and avoids the problem of faults not being discovered in time due to too frequent or too low-frequency probe detection.
Smart Images

Figure CN118708440A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing, and in particular to a method and system for determining container status in cloud computing. Background Art
[0002] With the rapid development of container technology, containerized applications have been widely used in software development and deployment. Containers enable applications to run in different environments in a consistent manner by providing an isolated operating environment. In the Kubernetes environment, ensuring the health and stable operation of containers is one of the core tasks of operation and maintenance management. In order to monitor and maintain the health of containers, Kubernetes provides a variety of probe mechanisms, such as survival probes, readiness probes, and startup probes. These probes periodically check the status of containers to ensure that containers can be discovered and handled in a timely manner when problems occur. As an important type of probe, Exec probes check the health of containers by executing specified commands in containers. The working principle of Exec probes is to run a predefined command and determine whether the container is in a normal state based on the exit status code of the command. If the command is successfully executed and returns 0, it means that the container is healthy; otherwise, it means that there may be problems with the container. For resource-sensitive applications, frequent probe detection may cause additional performance overhead. How to balance the frequency of probe detection and system performance is also an issue that needs to be considered. Summary of the invention
[0003] In order to solve the above problem, the present invention provides a method for determining the state of a container in cloud computing, the method comprising the following steps: Record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; Calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last time the survival probe was executed to the current situation, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to the preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; The liveness probe is executed at the new execution time of the liveness probe, and the container status is determined based on the execution time of the liveness probe and the returned status.
[0004] Preferably, determining the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
[0005] Preferably, the determining of the container status based on the survival probe execution time and the returned status is specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
[0006] Preferably, the probe type is an Exec probe, the first execution command includes checking the disk status, memory status and container port status, and the second execution command includes detecting the process status in the container.
[0007] Preferably, the container and Pod management process on the host machine will send a request to the container runtime through CRI, wherein the request includes the command to be executed by the survival probe; when the container receives the request, it starts a Shell process, which interprets and runs each line of command. After the command is executed, the Shell process returns the exit status code and execution time.
[0008] In addition, the present invention also provides a container status judgment system in cloud computing, the system comprising the following modules: An information collection module is used to record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; The probe execution time determination module is used to calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last execution of the survival probe to the current situation, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to a preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; The container status judgment module is used to execute the survival probe at the new execution time of the survival probe, and determine the container status based on the survival probe execution time and the returned status.
[0009] Preferably, determining the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
[0010] Preferably, the determining of the container status based on the survival probe execution time and the returned status is specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
[0011] Preferably, the probe type is an Exec probe, the first execution command includes checking the disk status, memory status and container port status, and the second execution command includes detecting the process status in the container.
[0012] Preferably, the container and Pod management process on the host machine will send a request to the container runtime through CRI, wherein the request includes the command to be executed by the survival probe; when the container receives the request, it starts a Shell process, which interprets and runs each line of command. After the command is executed, the Shell process returns the exit status code and execution time.
[0013] In addition, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described above is implemented.
[0014] Detecting the survival status of containers plays a great role in the stability of cloud computing, but too frequent detection will waste resources, and too low a detection frequency may result in the inability to promptly detect faulty containers. The container status judgment method provided by the present invention has the following advantages: 1. Through the process identification number of the program in the container on the host machine, the performance monitoring tool on the host machine obtains the resource occupancy of the process, and the periodic adjustment process of the survival probe will not occupy the resources of the container, thereby avoiding intrusion into the code in the container; 2. By adjusting the execution cycle of the survival probe, the resources of the container are saved; 3. By adjusting the execution content of the survival probe, a balance is achieved between the execution cycle and the comprehensiveness of detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 This is a flow chart of Embodiment 1; Figure 2 This is a schematic diagram of the survival probe for the first execution command; Figure 3This is a schematic diagram of the survival probe for the second execution command; Figure 4 This is a structural diagram of the second embodiment. DETAILED DESCRIPTION
[0016] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0017] It should be noted that, in the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art in the present application. The terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application.
[0018] It should be noted that, in the embodiments of the present application, words such as "first" and "second" are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order. Features limited to "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way. If the present application uses the user's personal information or usage records during use, a prompt will be issued to the user to collect the user's personal information or usage records with the user's permission. If there is a conflict with laws and regulations during the production and use of the present application, it shall be produced and used within the scope permitted by laws and regulations.
[0019] Based on the implementations in this application, all other implementations obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0020] In the first embodiment, if Figure 1 As shown, the present invention provides a method for determining the state of a container in cloud computing, the method comprising the following steps: Step 1: Record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; A program in a container, such as a web service, has a process in the container. You can view the process ID Pid of the program in the container by running the ps command in the container. There is also a program ID pid on the host. From the perspective of the host, the two are actually the same process. For example, the process ID pid of a web service process in the container is 5, and the process ID of the web service process on the host is 67.
[0021] The resource usage of program processes and survival probe processes can be collected by using container performance monitoring tools such as scripts running on the host. For example, running ps -p 67 -o %cpu,%mem on the host can view the CPU and memory usage of process number 67 on the host.
[0022] Step 2: Calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last time the survival probe was executed to the current state, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to the preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; When performing container orchestration, in order to prevent the container from occupying too many resources and causing other containers and the host machine to fail to operate normally, the container resources will be limited, such as limiting the use of CPU and memory, and calculating the ratio of the resources occupied by the program process to the container resource limit. The resources occupied by the program process here are the resource occupancy viewed on the host machine. Then calculate the change of the ratio from the last time the survival probe was executed to the current situation, and perform a straight line fitting on the change. If the slope of the straight line is positive, it indicates that the resources occupied by the program process are increasing and the load of the container is also increasing. At this time, it is necessary to increase the interval of the survival probe execution to reduce the occupation of resources by the survival probe. However, the interval cannot be too large, otherwise, if the container fails, it cannot be discovered in time. Based on this, the ratio of the time used in the last survival probe execution process to the preset value is further calculated, and the new execution time and the execution content of the survival probe are determined based on this ratio and the slope, so as to achieve a balance between container survival detection and container load. In one embodiment, the new execution time and the execution content of the survival probe are determined based on the ratio and the slope, specifically: a fuzzy control algorithm is used to determine the new execution time, and the execution content of the survival probe is determined according to the new execution time. A larger slope or a value greater than 0 indicates that the program has more content to process, a larger ratio indicates that the survival probe takes longer to execute, which also indicates that the load is heavy. In this case, the execution interval should be appropriately increased. In a more specific embodiment, the fuzzy control rule is: the larger the slope, the larger the ratio, and the longer the interval from the last execution time of the survival probe; the slope is close to 0, the ratio is close to 1, and the interval from the last execution time of the survival probe is moderate; the smaller the slope, the smaller the ratio, and the smaller the interval from the last execution time of the survival probe.
[0023] After determining the interval between the survival probe and the last execution time, determine the execution content of the survival probe based on the interval. The larger the interval, the more complex the execution content of the survival probe, and the more complex the execution content, the more content is detected. The above slope is close to 0, and the ratio is close to 1. The interval method is used for judgment. For example, between [-0.5, 0.5] is close to 0, and between [0.5, 1.5] is close to 1. The execution time of the survival probe can also be determined by detecting the existence time of the survival probe process on the host machine.
[0024] In another embodiment, the determining of the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
[0025] For example, if the ratio is 0.7, the slope is 2, and the weights of the ratio and the slope are 0.6 and 0.4 respectively, the weighted sum is 1.22. If the interval corresponding to the interval [1,2] where 1.22 is located is 10s, then the survival probe of this time is executed 10s after the last execution. Further, if the execution interval 10s is greater than the threshold 8s, the survival probe of the first execution command is used, otherwise the survival probe of the second execution command is used. Among them, the complexity of the first execution command is greater than the complexity of the second execution command, and the complexity represents the content of the detection. The complexity of the first execution command is greater than the complexity of the second execution command, that is, the first execution command detects more items of the container than the second execution command. Among them, the first execution command checks whether there is a process in the container, and the second execution command detects other container conditions such as memory in addition to the above functions. Preferably, the probe type is an Exec probe, the first execution command includes checks on the disk status, memory status and container port status, and the second execution command includes detection of the process status in the container.
[0026] Figure 2 shows a liveness probe executing the first execution command, Figure 3 A survival probe that executes the second execution command is shown. The survival probe of the first execution command will detect port 80. If it is inaccessible, it returns status code 1. At the same time, it determines the CPU load and memory usage. If the CPU load and memory usage are greater than 80, it returns status code 1. The survival probe of the second execution command will only detect whether port 80 is available. If it is unavailable, it returns status code 1.
[0027] Step three: execute the survival probe at the new execution time of the survival probe, and determine the container status based on the survival probe execution time and the returned status.
[0028] When the new execution time is reached, the survival probe is run in the container, and the execution time and returned status of the survival probe are returned to the external monitoring program or the container and Pod management process, such as the kubelet process. In one embodiment, the container status is determined based on the survival probe execution time and returned status, specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
[0029] In a specific embodiment, the container and Pod management process on the host machine will send a request to the container runtime through CRI, and the request includes the command to be executed by the survival probe; when the container receives the request, it starts a Shell process, and the Shell process interprets and runs each line of command. After the command is executed, the Shell process returns the exit status code and execution time.
[0030] In a second embodiment, the present invention further provides a system for determining container status in cloud computing, such as Figure 4 As shown, the system includes the following modules: An information collection module is used to record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; The probe execution time determination module is used to calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last execution of the survival probe to the current situation, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to a preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; The container status judgment module is used to execute the survival probe at the new execution time of the survival probe, and determine the container status based on the survival probe execution time and the returned status.
[0031] Preferably, determining the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
[0032] Preferably, the determining of the container status based on the survival probe execution time and the returned status is specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
[0033] Preferably, the probe type is an Exec probe, the first execution command includes checking the disk status, memory status and container port status, and the second execution command includes detecting the process status in the container.
[0034] Preferably, the container and Pod management process on the host machine will send a request to the container runtime through CRI, wherein the request includes the command to be executed by the survival probe; when the container receives the request, it starts a Shell process, which interprets and runs each line of command. After the command is executed, the Shell process returns the exit status code and execution time.
[0035] In a third embodiment, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in the first embodiment is implemented.
[0036] It should be noted that a part of the electronic device of the above embodiment can also be implemented by a computer. In this case, a program for implementing the control function can be recorded in a computer-readable recording medium, and the program recorded in the recording medium can be read into a computer system and executed to implement it.
[0037] It should be noted that the "computer system" mentioned here refers to a computer system built into an electronic device, and uses a computer system including hardware such as an OS and peripheral devices. In addition, "computer-readable recording medium" refers to removable media such as floppy disks, magneto-optical disks, ROMs, CD-ROMs, and storage devices such as hard disks built into computer systems.
[0038] Furthermore, "computer-readable recording media" may include: media that dynamically store programs for a short period of time, such as communication lines when sending programs via networks such as the Internet or communication lines such as telephone lines; and media that store programs for a fixed period of time, such as volatile memories inside computer systems that serve as servers or clients in this case. In addition, the above-mentioned program may be a program for realizing a part of the above-mentioned functions, or a program that can realize the above-mentioned functions by combining with a program already recorded in a computer system.
[0039] In addition, the electronic device in the above-mentioned embodiment can also be implemented as a collection (device group) composed of multiple devices. Each device constituting the device group can have a part or all of the functions or functional blocks of the electronic device in the above-mentioned embodiment. As a device group, it is sufficient to have all the functions or functional blocks of the electronic device.
[0040] Those skilled in the art should recognize that the above embodiments are only used to illustrate the present application and are not intended to be limiting of the present application. As long as they are within the spirit and scope of the present application, appropriate changes and modifications to the above embodiments are within the scope of protection claimed in the present application.
Claims
1. A method for determining container status in cloud computing, characterized in that: The method comprises the following steps: Record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; Calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last time the survival probe was executed to the current situation, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to the preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; The liveness probe is executed at the new execution time of the liveness probe, and the container status is determined based on the execution time of the liveness probe and the returned status.
2. The method according to claim 1, characterized in that The determining of the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically as follows: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
3. The method according to any one of claims 1 to 2, characterized in that: The container status is determined based on the survival probe execution time and the returned status, specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
4. The method according to claim 2, characterized in that The probe type is an Exec probe, the first execution command includes checking the disk status, memory status, and container port status, and the second execution command includes detecting the process status in the container.
5. The method according to any one of claims 1 to 3, characterized in that: The container and Pod management process on the host will send a request to the container runtime through CRI, and the request includes the command to be executed by the survival probe; when the container receives the request, it starts a Shell process, which interprets and runs each line of command. After the command is executed, the Shell process returns the exit status code and execution time.
6. A container status judgment system in cloud computing, characterized in that: The system includes the following modules: An information collection module is used to record the process identification numbers of the program process and the survival probe process in the container on the host machine, and the container performance monitoring tool running on the host machine collects the resources occupied by the program process and the survival probe process according to the process identification numbers; The probe execution time determination module is used to calculate the ratio of the resources occupied by the program process to the container resource limit, obtain the change of the ratio from the last execution of the survival probe to the current situation, perform a straight line fit on the change to obtain the slope of the straight line, calculate the ratio of the time used in the last survival probe execution process to a preset value, and determine the new execution time and execution content of the survival probe based on the ratio and the slope; The container status judgment module is used to execute the survival probe at the new execution time of the survival probe, and determine the container status based on the survival probe execution time and the returned status.
7. The system according to claim 6, characterized in that The determining of the new execution time and the execution content of the survival probe based on the ratio and the slope is specifically as follows: Calculating a weighted sum of the ratio and the slope, and determining a new execution time according to the interval in which the weighted sum is located; If the survival probe execution interval is greater than a threshold, a survival probe of a first execution command is used, otherwise a survival probe of a second execution command is used; wherein the complexity of the first execution command is greater than the complexity of the second execution command.
8. The system according to any one of claims 6 to 7, characterized in that: The container status is determined based on the survival probe execution time and the returned status, specifically: When the returned status is success, the range of the probe execution time is further determined according to the execution content of the survival probe. If the survival probe execution time is within the range, the container status is healthy; if the survival probe execution time is not within the range, the container status is sub-healthy; when the returned status is failure, the container status is faulty.
9. The system according to claim 7, characterized in that The probe type is an Exec probe, the first execution command includes checking the disk status, memory status, and container port status, and the second execution command includes detecting the process status in the container.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 5.
