Memory leak detection method and device
By detecting the memory change rate difference or synchronization between the service process and the internal data structure, we can accurately determine memory leaks in distributed services, solve the problem of inaccurate detection in the existing technology, reduce the risk of memory leaks, and improve system stability. .
Patent Information
- Application Number
- CN202010621262.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2040-06-30
AI Technical Summary
Existing technology is difficult to accurately detect memory leaks in service processes in distributed services, resulting in increased potential risks and low detection accuracy.
By obtaining the memory usage value of the service process and internal data structure within the preset time period, calculate the change rate difference or determine whether the memory changes are synchronized. If it exceeds the preset interval or is out of sync, it is determined to be a memory leak and can be cleaned. Operate to verify leakage.
It achieves accurate detection of memory leaks in service processes, reduces risks caused by memory leaks, and improves the stability and performance of distributed services.
Smart Images

Figure CN111858317B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to computer technology, and in particular to a memory leak detection method, a distributed service testing method, a memory leak detection device, and a computer-readable storage medium. Background Art
[0002] With the continuous innovation of hardware technology, the cost-effectiveness of memory is gradually improving, the memory of servers is getting larger and larger, and memory is no longer a scarce resource in distributed services. In the future, the trend of full memory for distributed services will become more and more obvious. Full memory can effectively improve the performance of distributed services, but the potential risk of memory leaks will also increase.
[0003] Memory leak refers to the situation that the memory space dynamically requested in the program is not properly released after use, resulting in this part of the memory still being occupied and not being properly recovered by the system. Memory leak will cause a waste of system memory and may also lead to serious consequences such as slowing down the program running speed or even system crash.
[0004] In distributed services, you can view the actual memory usage of each server in the cluster. If a server actually uses too much memory, it is believed that this server may have a memory leak. This method of detecting memory leaks cannot locate the specific service process where the memory leak occurs. Alternatively, you can also view which service processes are running on the server and the actual memory usage of these service processes, and identify the service process with a relatively high actual memory usage as the service process with a memory leak. However, the excessive memory usage of a service process may also be related to other factors such as the load balancing algorithm used by the cluster, so the accuracy of this method of detecting memory leaks is not high.
[0005] Therefore, it is necessary to propose a solution that can detect memory leaks more accurately. Summary of the invention
[0006] The purpose of the present disclosure is to provide a solution that can accurately detect memory leaks to reduce the risks caused by memory leaks.
[0007] According to a first aspect of the present disclosure, a method for detecting a memory leak is provided, comprising:
[0008] Obtaining a used memory value of a service process and a used memory value of an internal data structure managed by the service process within a preset time period;
[0009] Based on the used memory value of the service process and / or the used memory value of the internal data structure, it is determined whether a memory leak occurs in the service process.
[0010] Optionally, obtaining the used memory value of the service process within a preset time period and the used memory value of the internal data structure managed by the service process includes: obtaining the used memory value of the service process at startup time and the used memory value of the internal data structure managed by the service process at startup time.
[0011] Optionally, judging whether memory leakage occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure includes:
[0012] Calculating a first change rate and a second change rate, wherein the first change rate is a change rate of a used memory value of the service process within the preset time period, and the second change rate is a change rate of a used memory value of the internal data structure within the preset time period;
[0013] determining whether a difference between the first change rate and the second change rate is within a preset first interval;
[0014] If not, it is determined that a memory leak occurs in the service process.
[0015] Optionally, judging whether memory leakage occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure includes:
[0016] Determine whether the changes of the used memory value of the service process and the used memory value of the internal data structure within the preset time period are synchronized;
[0017] If not synchronized, it is determined that a memory leak occurs in the service process.
[0018] Optionally, the obtaining of the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period includes:
[0019] Detecting whether the ratio of the memory usage value of the service process to the total memory value of the machine within a preset time period exceeds a preset ratio threshold;
[0020] If the preset ratio threshold is exceeded, a cleaning operation is performed on the internal data structure;
[0021] Obtain the used memory value of the service process and / or the used memory value of the internal data structure before and after the cleaning operation.
[0022] Optionally, judging whether memory leakage occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure includes:
[0023] Determine whether the memory usage value of the service process after the cleaning operation is less than the memory usage value of the service process before the cleaning operation;
[0024] If not, it is determined that a memory leak occurs in the service process.
[0025] Optionally, judging whether memory leakage occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure includes:
[0026] Calculate a first change value and a second change value, wherein the first change value is a difference between a memory value used by the service process before the cleaning operation and a memory value used by the service process after the cleaning operation, and the second change value is a difference between a memory value used by the internal data structure before the cleaning operation and a memory value used by the internal data structure after the cleaning operation;
[0027] Determining whether a difference between the first change value and the second change value is within a preset second interval;
[0028] If not, it is determined that a memory leak occurs in the service process.
[0029] According to a second aspect of the present disclosure, a distributed service testing method is provided. When the distributed service is put online for testing, any detection method disclosed in the first aspect of the present disclosure is used to detect whether a memory leak occurs in the service process of the distributed service.
[0030] According to a third aspect of the present disclosure, a memory leak detection device is provided, comprising an acquisition module and a judgment module;
[0031] The acquisition module is used to acquire the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period;
[0032] Therefore, the judgment module is used to judge whether the memory of the service process is leaked based on the used memory value of the service process and / or the used memory value of the internal data structure.
[0033] According to a fourth aspect of the present disclosure, a memory leak detection device is provided, comprising a processor and a memory, wherein the memory is used to store computer-readable instructions, and when the instructions are executed by the processor, any one of the detection methods of the first aspect of the present disclosure is implemented.
[0034] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided, on which computer-readable instructions are stored, and when the instructions are executed by a processor, any detection method of the first aspect of the present disclosure is implemented.
[0035] The memory leak detection method provided by the embodiment of the present disclosure can accurately determine whether a service process has a memory leak based on the memory usage of the service process and / or the memory usage of the internal data structure managed by the service process, thereby reducing the risks caused by memory leaks in the service process.
[0036] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0038] Figure 1 A flowchart of a memory leak detection method provided by an embodiment of the present disclosure;
[0039] FIG. 2( a ) is a schematic diagram of a memory usage value of a service process and a memory usage value of an internal data structure managed by the service process within a preset time period provided by an embodiment of the present disclosure;
[0040] FIG2( b) is a schematic diagram of a memory usage value of a service process and a memory usage value of an internal data structure managed by the service process within a preset time period provided by another embodiment of the present disclosure;
[0041] Figure 3 is a block diagram of a memory leak detection system provided by an embodiment of the present disclosure;
[0042] Figure 4 is a block diagram of a memory leak detection device provided by an embodiment of the present disclosure;
[0043] Figure 5 It is a block diagram of a memory leak detection device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0044] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0045] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0046] Technologies, methods, and apparatuses known to persons of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, such technologies, methods, and apparatuses should be considered part of the specification.
[0047] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0048] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0049] <Memory leak detection method>
[0050] Memory leak means that the memory space dynamically requested in the program is not properly released after use, resulting in this part of the memory still being occupied and not being properly recovered by the system. Memory leak will cause a waste of system memory, which may lead to serious consequences such as slowing down the program running speed or even system crash.
[0051] The embodiments of the present disclosure are intended to provide a solution for detecting memory leaks, so as to reduce the problems caused by memory leaks.
[0052] The use of memory by a service process includes many aspects, such as the memory used by the internal data structure managed by the service process, the cache provided by the operating system to the service process, the index node generated by the service process when opening the file, the temporary variables allocated within the service process, etc. The use of memory by the internal data structure managed by the service process is one of the more important aspects. Especially for distributed services, the proportion of memory actually used by the internal data structure managed by the service process can even reach more than 80% of the total memory actually used by the service process. That is to say, under normal circumstances, during the operation of the service process, the development and change of the used memory value of the service process and the used memory value of the internal data structure managed by the service process should be similar. The disclosed embodiment can use the used memory value of the service process and / or the used memory value of the internal data structure managed by the service process to determine whether the service process has a memory leak.
[0053] See also Figure 1 As shown, according to an embodiment of the present disclosure, a memory leak detection method is provided. The detection method includes steps S102 and S103.
[0054] S102: Obtain a used memory value of a service process and a used memory value of an internal data structure managed by the service process within a preset time period.
[0055] The internal data structures of a service process refer to the process information data used to characterize the service process entity, which includes the service process's identification, description, status and related pointers.
[0056] S104: Based on the used memory value of the service process and / or the used memory value of the internal data structure, determine whether a memory leak occurs in the service process.
[0057] When a service process is started, the memory usage of the service process and the memory usage of the internal data structure managed by the service process will change significantly. Using the memory value data at the startup time, it will be easier to detect whether the memory of the service process is leaking. In a specific example, in step S102, the memory usage value of the service process at the startup time and the memory usage value of the internal data structure managed by the service process at the startup time are obtained.
[0058] The memory leak detection method provided by the embodiment of the present disclosure can accurately determine whether a service process has a memory leak based on the memory usage of the service process and / or the memory usage of the internal data structure managed by the service process, thereby reducing the risks caused by memory leaks in the service process.
[0059] The above memory leak detection method is further explained below with four specific examples.
[0060] <Example 1>
[0061] Step S102 may include steps S202 - S206 .
[0062] S202, calculating a first change rate and a second change rate, wherein the first change rate is a change rate of the used memory value of the service process within a preset time period, and the second change rate is a change rate of the used memory value of the internal data structure within a preset time period.
[0063] S204: Determine whether the difference between the first change rate and the second change rate is within a preset first interval.
[0064] S206: If not, determine whether memory leakage occurs in the service process.
[0065] That is to say, within the same time period, the change rate of the service process's used memory value and the change rate of the internal data structure managed by the service process should be similar. If the difference between the two change rates is too large, it indicates that the service process has a memory leak.
[0066] Referring to FIG2(a), the horizontal axis of FIG2(a) is time, and the vertical axis is the used memory value. FIG2(a) shows the used memory value of the service process and the used memory value of the internal data structure managed by the service process during the period from time t1 to time t2. As can be seen from FIG2(a), during the period from time t1 to time t2, the used memory value of the service process increases from 30 units to 130 units, and the first change rate is calculated to be 3.33. During the period from time t1 to time t2, the used memory value of the internal data structure managed by the service process increases from 20 units to 50 units, and the second change rate is calculated to be 1.50. The difference between the first change rate and the second change rate is 1.83, and the preset first interval is (-0.5, +0.5). It can be seen that the difference between the first change rate and the second change rate is not within the first interval, and it is determined that the memory of the service process is leaked.
[0067] The memory leak detection method provided in Example 1 can accurately detect whether a service process has a memory leak by comparing the actual memory usage of the service process with the actual memory usage of the internal data structure managed by the service process, thereby reducing the risk caused by memory leaks.
[0068] The memory leak detection method shown in Example 1 is applicable to distributed services. After the service is officially launched, it can monitor whether the service process has memory leaks during operation, discover memory leaks in time and solve memory leaks in time, thereby reducing the risks caused by memory leaks.
[0069] The memory leak detection method shown in Example 1 can be applied to the online testing phase before the distributed service is officially launched, to detect whether the service process of the distributed service may cause memory leaks, which is helpful to identify hidden dangers before the distributed service is officially launched and reduce the risk of memory leaks after the distributed service is officially launched.
[0070] <Example 2>
[0071] Step S102 may include steps S302 - S304 .
[0072] S302: Determine whether the changes of the used memory value of the service process and the used memory value of the internal data structure are synchronized within a preset time period.
[0073] S304: If there is no synchronization, determine whether memory leakage occurs in the service process.
[0074] Referring to FIG2(b), the horizontal axis of FIG2(b) is time, and the vertical axis is the used memory value. FIG2(b) shows the used memory value of the service process and the used memory value of the internal data structure managed by the service process during the period from time t1 to time t4. As can be seen from FIG2(b), during the period from time t1 to time t4, the value of the memory actually used by the service process first increases (time t1-time t3), and then decreases (time t3-time t4), and the turning point of the used memory value of the service process is t3. During the period from time t1 to time t4, the value of the memory actually used by the internal data structure managed by the service process first increases (time t1-time t2), and then decreases (time t2-time t4), and the turning point of the internal data structure managed by the service process is t2. Calculate the time length between the turning point t2 and the turning point t3. If the time length exceeds the preset time length threshold, it means that the changes of the used memory value of the service process and the used memory value of the internal data structure managed by the service process during the period from t1 to time t4 are not synchronized.
[0075] The memory leak detection method provided in Example 2 can accurately detect whether a service process has a memory leak by comparing the actual memory usage of the service process and the changes in the actual memory usage of the internal data structure managed by the service process within the same time period, thereby reducing the risks caused by memory leaks.
[0076] The memory leak detection method shown in Example 2 is applicable to distributed services. After the service is officially launched, it can monitor whether the service process has memory leaks during operation, discover memory leaks in time and solve memory leaks in time, thereby reducing the risks caused by memory leaks.
[0077] The memory leak detection method shown in Example 2 can be applied to the online testing phase before the distributed service is officially launched, to detect whether the service process of the distributed service may cause memory leaks, which is helpful to identify hidden dangers before the distributed service is officially launched and reduce the risk of memory leaks after the distributed service is officially launched.
[0078] <Example 3>
[0079] Step S102 includes steps S1022 - S1026 .
[0080] S1022: Detect whether the ratio of the memory usage value of the service process to the total memory value of the machine within a preset time period exceeds a preset ratio threshold.
[0081] S1024: If the ratio exceeds a preset threshold, clean up the internal data structure.
[0082] If the proportion of memory actually used by a service process to the total memory of the machine reaches a preset ratio threshold within a preset time period, such as 1 minute, it is necessary to perform a cleanup operation on the internal data structure managed by it. In other words, if the proportion of memory actually used by a service process to the total memory of the machine is too high, it means that the service process occupies too much memory, and it is necessary to perform a memory leak detection on the service process. The preset ratio threshold can be set by a technician based on actual experience, or determined based on data statistics of the same type of service processes, or set based on the results of simulation experiments. The preset ratio threshold is, for example, 50%.
[0083] S1026. Obtain the used memory value of the service process and / or the used memory value of the internal data structure before and after the cleaning operation.
[0084] Step S202 includes steps S502-S504.
[0085] S502: Determine whether the memory usage value of the service process after the cleanup operation is less than the memory usage value of the service process before the cleanup operation.
[0086] S504: If not, determine whether memory leakage occurs in the service process.
[0087] That is to say, after the cleanup operation, the value of the memory actually used by the service process should be reduced. If the value of the memory actually used by the service process does not decrease after the cleanup operation, it can be determined that the service process has a memory leak.
[0088] The memory leak detection method shown in Example 3 can accurately detect whether a memory leak occurs in the service process by analyzing the change in the value of the memory actually used by the service process after clearing and deleting the memory data structure, thereby reducing the risk caused by memory leaks.
[0089] The memory leak detection method shown in Example 3 can be applied to the online testing phase before the distributed service is officially launched, to detect whether the service process of the distributed service may cause memory leaks, which is helpful to identify hidden dangers before the distributed service is officially launched and reduce the risk of memory leaks after the distributed service is officially launched.
[0090] <Example 4>
[0091] Step S102 includes steps S1022 - S1026 .
[0092] S1022: Detect whether the ratio of the memory value used by the service process to the memory value of the entire machine exceeds a preset ratio threshold.
[0093] S1024: If the ratio exceeds a preset threshold, clean up the internal data structure.
[0094] If the proportion of memory actually used by a service process to the entire machine memory reaches a preset ratio threshold, the above cleaning operation is performed. In other words, if the proportion of memory actually used by a service process to the entire machine memory is too high, it means that the service process occupies too much memory, and memory leak detection needs to be performed on the service process. The preset ratio threshold can be set by technicians based on actual experience, or determined based on data statistics of the same type of service processes, or set based on the results of simulation experiments. The preset ratio threshold is, for example, 50%.
[0095] S1026. Obtain the used memory value of the service process and / or the used memory value of the internal data structure before and after the cleaning operation.
[0096] Step S202 includes steps S602-S606.
[0097] S602. Calculate a first change value and a second change value, wherein the first change value is the difference between the memory value used by the service process before the cleanup operation and the memory value used by the service process after the cleanup operation, and the second change value is the difference between the memory value used by the internal data structure before the cleanup operation and the memory value used by the internal data structure after the cleanup operation.
[0098] S604: Determine whether the difference between the first change value and the second change value is within a preset second interval.
[0099] S606: If not, determine whether memory leakage occurs in the service process.
[0100] That is to say, after the cleanup operation, the decrease in the value of memory actually used by the service process and the decrease in the value of memory actually used by the internal data structure managed by the service process should be similar. If the difference between the two is too large, it means that the memory of the service process is leaking.
[0101] For example, before the cleaning operation, the used memory value of the service process is 100 units, and the used memory value of the internal data structure managed by the service process is 80 units. After the cleaning operation, the used memory value of the service process is 90 units, and the used memory value of the internal data structure managed by the service process is 20 units. The first change value is calculated to be 10 units, the second change value is 60 units, and the difference between the first change value and the second change value is -50. The preset second interval is (-10, +10), and the difference between the first change value and the second change value is not within the range of the second interval, so it is determined that the memory of the service process is leaking.
[0102] The memory leak detection method shown in Example 4 can accurately detect whether a memory leak occurs in the service process by analyzing the changes in the value of the memory actually used by the service process and the internal data structure managed by the service process after cleaning and deleting the memory data structure, thereby reducing the risk caused by memory leaks.
[0103] The memory leak detection method provided in Example 4 can be applied to the online testing phase before the distributed service is officially launched, to detect whether the service process of the distributed service may cause memory leaks, which is helpful to identify hidden dangers before the distributed service is officially launched and reduce the risk of memory leaks after the distributed service is officially launched.
[0104] The embodiments of the present disclosure further provide a distributed service testing method. When performing an online test on a distributed service, the detection method disclosed in any of the aforementioned embodiments is used to detect whether a service process of the distributed service will cause a memory leak.
[0105] <Memory leak test system>
[0106] By using the aforementioned memory leak detection method, an embodiment of the present disclosure provides a memory leak testing system. Figure 3 A memory leak testing system in which embodiments of the present disclosure may be implemented is shown.
[0107] The system under test 100 may be a distributed system, and the distributed services provided by the system include multiple service processes. Figure 3 Schematic diagram showing service process A1, service process A2, and service process A3.
[0108] The memory leak test system includes a data collector corresponding to each service process. Figure 3 Data collector C1, data collector C2, and data collector C3 are shown in FIG.
[0109] The memory leak test system further includes a test monitoring platform 200 , and the test monitoring platform 200 includes a human interaction module 201 and a test analysis module 202 .
[0110] The test monitoring platform 200 may be, for example, a server, which may include a processor, a memory, an interface device, a communication device, a display device, and an input device. The processor is used to execute a computer program. The computer program may be written in an instruction set of an architecture such as x86, Arm, RISC, MIPS, SSE, etc. The memory may include, for example, ROM (read-only memory), RAM (random access memory), a non-volatile memory such as a hard disk, etc. The interface device may include, for example, a USB interface, a serial interface, etc. The communication device 1140 may be capable of wired or wireless communication, for example. The display device may include a touch screen, a liquid crystal display screen. The input device may include, for example, a touch screen, a keyboard, etc. In the embodiment of the present disclosure, the human-computer interaction module 201 may be composed of a display device and an input device, and the test analysis module 201 may be composed of a processor and a memory, and the memory is used to store computer-readable instructions, and the instructions are used to control the processor to operate to support the memory leak detection method of any embodiment of the present disclosure. The technician may design instructions according to the disclosed scheme of the embodiment of the present disclosure. How the instructions control the processor to operate is well known in the art, so it will not be described in detail here.
[0111] The data collector is connected to the API (Application Programming Interface) of the corresponding service process, and collects the used memory value of the service process and the used memory value of the internal data structure managed by the service process according to the preset collection period through the API of the service process, and provides the used memory value of the service process and the used memory value of the internal data structure managed by the service process together with the collection time to the test monitoring platform 200. The preset collection period can be set by the technician according to actual experience, and the preset collection period is, for example, 10 seconds, that is, the collection is performed every 10 seconds.
[0112] The following takes the test of service process A1 as an example to illustrate the working process of the memory leak test system of this embodiment:
[0113] The data collector C1 collects the memory used value of the service process A1 and the memory used value of the internal data structure of the service process A1 according to the preset collection cycle, and provides the memory used value of the service process A1 and the memory used value of the internal data structure managed by the service process A1 and the corresponding collection time to the test monitoring platform 200.
[0114] The test analysis module 202 of the test monitoring platform 200 can determine whether a memory leak occurs in the service process according to the used memory value of the service process and / or the used memory value of the internal data structure managed by the service process within a preset time period.
[0115] The test analysis module 202 can also calculate the proportion of the memory used by service process A1 to the total machine memory. When the proportion of the memory used by service process A1 exceeds a preset proportion threshold, the internal data structure of service process A1 is cleaned up by calling the memory data deletion interface of service process A1.
[0116] The specific strategy for the test analysis module 202 to determine whether the memory of the service process A1 is leaked based on the used memory value of the service process A1 and / or the used memory value of the internal data structure managed by the service process A1 can refer to the memory leak detection method provided in the above embodiment.
[0117] Technicians can also set the test analysis strategy of the test analysis module 202 through the human-computer interaction module 201, such as setting a specific detection algorithm, setting specific parameters (including but not limited to the aforementioned collection cycle, preset time period, duration threshold, first interval, second interval, ratio threshold), etc.
[0118] When the test analysis module 202 determines that a memory leak occurs in a service process, it can alert the technician through the human-computer interaction module 201 to indicate that there is a risk of memory leakage.
[0119] The test monitoring platform 200 can provide the human-computer interaction module 201 with a curve showing how the service process's memory usage changes over time, a curve showing how the internal data structure managed by the service process uses memory, and memory leak detection results, and present them to technical personnel.
[0120] The memory leak testing system provided by the embodiments of the present disclosure can accurately determine whether a service process has a memory leak based on the memory usage of the service process and / or the memory usage of the internal data structure managed by the service process, thereby reducing the risks caused by memory leaks in the service process.
[0121] The memory leakage testing system provided by the embodiments of the present disclosure can be applied to an online testing scenario before a distributed service is officially launched, to detect whether the service process of the distributed service may cause a memory leakage, which is helpful to identify hidden dangers before the distributed service is officially launched, and reduce the risk of memory leakage after the distributed service is officially launched.
[0122] <Memory leak detection device>
[0123] See also Figure 4 As shown, according to an embodiment of the present disclosure, a memory leak detection device 10 is provided. The memory leak detection device 10 includes an acquisition module 11 and a judgment module 12.
[0124] The acquisition module 11 is used to acquire the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period.
[0125] The judgment module 12 is used to judge whether the memory of the service process is leaked based on the used memory value of the service process and / or the used memory value of the internal data structure.
[0126] In a specific example, the acquisition module 11 obtains the used memory value of the service process within a preset time period and the used memory value of the internal data structure managed by the service process, including: obtaining the used memory value of the service process at the startup time and the used memory value of the internal data structure managed by the service process at the startup time.
[0127] In a specific example, the judgment module 12 judges whether the memory of the service process is leaked based on the used memory value of the service process and / or the used memory value of the internal data structure, including: calculating a first change rate and a second change rate, the first change rate being the change rate of the used memory value of the service process within the preset time period, and the second change rate being the change rate of the used memory value of the internal data structure within the preset time period; determining whether the difference between the first change rate and the second change rate is within a preset first interval; if not, judging that the memory of the service process is leaked.
[0128] In a specific example, the judgment module 12 judges whether a memory leak occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure, including: judging whether the changes in the used memory value of the service process and the used memory value of the internal data structure within the preset time period are synchronized; if they are not synchronized, judging that a memory leak occurs in the service process.
[0129] In a specific example, the acquisition module 11 obtains the used memory value of the service process within a preset time period and the used memory value of the internal data structure managed by the service process, including: detecting whether the ratio of the used memory value of the service process to the total machine memory value exceeds a preset ratio threshold; if it exceeds the preset ratio threshold, performing a cleanup operation on the internal data structure; obtaining the used memory value of the service process and / or the used memory value of the internal data structure before and after the cleanup operation.
[0130] In a specific example, the judgment module 12 judges whether a memory leak occurs in the service process based on the used memory value of the service process and / or the used memory value of the internal data structure, including: determining whether the used memory value of the service process after the cleanup operation is less than the used memory value of the service process before the cleanup operation; if not, judging that a memory leak occurs in the service process.
[0131] In a specific example, the judgment module 12 judges whether the memory of the service process is leaked based on the used memory value of the service process and / or the used memory value of the internal data structure, including: calculating a first change value and a second change value, the first change value being the difference between the used memory value of the service process before the cleaning operation and the used memory value of the service process after the cleaning operation, and the second change value being the difference between the used memory value of the internal data structure before the cleaning operation and the used memory value of the internal data structure after the cleaning operation; determining whether the difference between the first change value and the second change value is within a preset second interval; if not, judging that the memory of the service process is leaked.
[0132] See also Figure 5 As shown, according to an embodiment of the present disclosure, a memory leak detection device 40 is provided. The memory leak detection device 40 includes a processor 42 and a memory 41, wherein the memory 41 is used to store computer-readable instructions, and when the instructions are executed by the processor 42, the detection method disclosed in any of the above embodiments is implemented.
[0133] In the disclosed embodiment, the detection device may be a server, or an electronic device such as a desktop computer, a laptop computer, a mobile phone, a tablet computer, a workstation, etc.
[0134] <Computer Readable Storage Medium>
[0135] According to another embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the instructions are executed by a processor, the detection method disclosed in any of the aforementioned embodiments is implemented.
[0136] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and equipment embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0137] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0138] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0139] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0140] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0141] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0142] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0143] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0144] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0145] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of an instruction, and the module, a program segment or a part of an instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0146] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the marketplace, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present disclosure is defined by the appended claims.
Claims
1. A memory leak detection method, It is characterized in that include: Obtaining a used memory value of a service process and a used memory value of an internal data structure managed by the service process within a preset time period, wherein the internal data structure managed by the service process refers to process information data used to characterize a service process entity, including an identification, description, status, and related pointers of the service process; Based on the used memory value of the service process and the used memory value of the internal data structure, it is determined whether a memory leak occurs in the service process.
2. The method according to claim 1, It is characterized in that The obtaining of the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period includes: obtaining the used memory value of the service process and the used memory value of the internal data structure managed by the service process at the startup time.
3. The method according to claim 1, It is characterized in that The determining whether memory leakage occurs in the service process based on the used memory value of the service process and the used memory value of the internal data structure includes: Calculating a first change rate and a second change rate, wherein the first change rate is a change rate of a used memory value of the service process within the preset time period, and the second change rate is a change rate of a used memory value of the internal data structure within the preset time period; determining whether a difference between the first change rate and the second change rate is within a preset first interval; If not, it is determined that a memory leak occurs in the service process.
4. The method according to claim 1, It is characterized in that The determining whether memory leakage occurs in the service process based on the used memory value of the service process and the used memory value of the internal data structure includes: Determine whether the changes of the used memory value of the service process and the used memory value of the internal data structure within the preset time period are synchronized; If not synchronized, it is determined that a memory leak occurs in the service process.
5. The method according to claim 1, It is characterized in that The obtaining of the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period includes: Detecting whether the ratio of the memory usage value of the service process to the total memory value of the machine within a preset time period exceeds a preset ratio threshold; If the preset ratio threshold is exceeded, a cleaning operation is performed on the internal data structure; The used memory value of the service process and the used memory value of the internal data structure before and after the cleaning operation are obtained.
6. The method according to claim 5, It is characterized in that The determining whether memory leakage occurs in the service process based on the used memory value of the service process and the used memory value of the internal data structure includes: Determine whether the memory usage value of the service process after the cleaning operation is less than the memory usage value of the service process before the cleaning operation; If not, it is determined that a memory leak occurs in the service process.
7. The method according to claim 5, It is characterized in that The determining whether memory leakage occurs in the service process based on the used memory value of the service process and the used memory value of the internal data structure includes: Calculate a first change value and a second change value, wherein the first change value is a difference between a memory value used by the service process before the cleaning operation and a memory value used by the service process after the cleaning operation, and the second change value is a difference between a memory value used by the internal data structure before the cleaning operation and a memory value used by the internal data structure after the cleaning operation; Determining whether a difference between the first change value and the second change value is within a preset second interval; If not, it is determined that a memory leak occurs in the service process.
8. A distributed service testing method, It is characterized in that When the distributed service is put on-line for testing, the detection method described in any one of claims 1 to 7 is used to detect whether a memory leak occurs in the service process of the distributed service.
9. A memory leak detection device, It is characterized in that Including acquisition module and judgment module; The acquisition module is used to acquire the used memory value of the service process and the used memory value of the internal data structure managed by the service process within a preset time period, wherein the internal data structure managed by the service process refers to process information data used to characterize the service process entity, including the identification, description, status and related pointers of the service process; Therefore, the judging module is used to judge whether the memory of the service process is leaked based on the used memory value of the service process and the used memory value of the internal data structure.
10. A memory leak detection device, It is characterized in that The method comprises a processor and a memory, wherein the memory is used to store computer-readable instructions, and when the instructions are executed by the processor, the detection method according to any one of claims 1 to 7 is implemented.
11. A computer-readable storage medium, It is characterized in that Computer-readable instructions are stored thereon, and when the instructions are executed by a processor, the detection method according to any one of claims 1 to 7 is implemented.
