Connection leakage analysis method and device, electronic equipment and storage medium
By analyzing the call stack signature of the database connection and decompiling the source code, the database connection leakage problem was solved, the root cause of the connection leakage was accurately located, and the system stability and performance were improved.
Patent Information
- Application Number
- CN202510708935.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-10-14
- Estimated Expiration
- 2045-05-29
AI Technical Summary
Existing technologies make it difficult to accurately locate the root cause of database connection leaks, leading to connection resource exhaustion and performance bottlenecks.
By obtaining the call stack information of the potential leaked connection, generating a call stack signature, decompiling the bytecode of the relevant class to analyze the source code, and determining the code location that causes the connection leak.
Accurately locate code locations where connections are not closed to avoid resource exhaustion, improve application stability and operational efficiency, and reduce manual troubleshooting time.
Smart Images

Figure CN120780740A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a connection leakage analysis method, device, electronic device, and storage medium. Background Art
[0002] With the advent of the internet and big data, databases have become a core component of many applications. Applications frequently interact with databases to store and retrieve data. To improve performance and efficiency, many applications use database connection pools to manage the creation and release of database connections.
[0003] A database connection pool is a technical component used to efficiently manage database connections. It creates and maintains a certain number of connections in advance for application reuse, thereby reducing the overhead of establishing and closing connections, improving performance, and optimizing resource utilization.
[0004] However, when using the database connection pool, connection leaks may occur, leading to connection resource exhaustion or performance bottlenecks. Connection leaks refer to the application not properly releasing the database connection after use, resulting in the connection resources not being recycled and reused.
[0005] Therefore, how to accurately locate the root cause of the connection leakage problem is an issue that needs to be solved urgently. Summary of the Invention
[0006] The embodiments of the present application provide a connection leakage analysis method, device, electronic device, and storage medium to accurately locate the root cause of the connection leakage problem, thereby improving the stability and performance of the system.
[0007] In a first aspect, an embodiment of the present application provides a method for analyzing connection leaks, the method comprising:
[0008] Obtaining connection data for each potential leak connection, wherein the connection usage duration of each potential leak connection is greater than a usage duration threshold, and the connection data includes: call stack information;
[0009] Generate a call stack signature for each potential leaked connection based on the call stack information of each potential leaked connection, and determine a suspicious call stack signature from the obtained call stack signatures;
[0010] Extract multiple classes of call stack information corresponding to the suspicious call stack signature, decompile the bytecodes corresponding to the multiple classes, and obtain the source code of the multiple classes;
[0011] Based on the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature, the source code analysis result is determined. The source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
[0012] In an optional embodiment, the connection data further includes: a connection identifier, a connection acquisition time, a connection usage duration, and thread information.
[0013] In an optional embodiment, generating a call stack signature for each potential leak connection based on the call stack information of each potential leak connection includes:
[0014] For each potentially leaked connection, perform the following operations:
[0015] Normalize the call stack information of a potential leaked connection;
[0016] Core information is extracted from call stack information of a potential leaked connection, and a call stack signature of the potential leaked connection is generated based on the core information.
[0017] In an optional embodiment, normalizing call stack information of a potential leaked connection includes:
[0018] Irrelevant stack frames in call stack information of a potential leaked connection are filtered, wherein the irrelevant stack frames are stack frames that are irrelevant to the application code.
[0019] In an optional embodiment, determining a suspicious call stack signature from each obtained call stack signature includes:
[0020] Determining a suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity measurement value of a time distribution of multiple potential leaked connections corresponding to each call stack signature;
[0021] Based on the suspicious values of each call stack signature, suspicious call stack signatures whose suspicious values meet preset suspicious conditions are screened out from each call stack signature.
[0022] In an optional embodiment, determining the suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity metric of the time distribution of multiple potential leaked connections corresponding to each call stack signature includes:
[0023] For each call stack signature, perform the following operations: obtain and analyze a time series of a call stack signature to obtain a uniformity measurement value of the time distribution corresponding to the call stack signature, where the time series includes time points of multiple potential leaked connections corresponding to the call stack signature;
[0024] The number of occurrences of each call stack signature and the corresponding time distribution uniformity measurement value are normalized and weighted summed to obtain the suspicious value of each call stack signature.
[0025] In an optional embodiment, the bytecodes corresponding to the plurality of classes are decompiled to obtain source codes of the plurality of classes, including:
[0026] filtering irrelevant classes in the plurality of classes; and / or, screening the plurality of classes belonging to upper stack frames from the plurality of classes; wherein the irrelevant classes are classes irrelevant to the connection leakage event, and the upper stack frames are stack frames whose stack frame depths in the call stack information corresponding to the suspicious call stack signature satisfy a preset depth condition;
[0027] The bytecodes corresponding to the plurality of classes are decompiled by a decompilation tool to obtain source codes of the plurality of classes.
[0028] In an optional embodiment, before determining the source code analysis result based on the suspicious call stack signature, the source codes of the plurality of classes, and the connection data corresponding to the suspicious call stack signature, the method further includes:
[0029] filtering irrelevant codes in the source codes of the plurality of classes, wherein the irrelevant codes are codes irrelevant to the core business logic.
[0030] In an optional embodiment, the source code analysis result is determined based on the suspicious call stack signature, the source codes of the plurality of classes, and the connection data corresponding to the suspicious call stack signature, including:
[0031] inputting the suspicious call stack signature, the source codes of the plurality of classes, and the connection data corresponding to the suspicious call stack signature into a code analysis model to obtain a source code analysis result output by the code analysis model, wherein the source code analysis result includes an exception report including the class, the method, and the line number causing the connection leakage, and the corresponding code segment when the code causing the connection leakage exists.
[0032] In an optional embodiment, the method further includes:
[0033] inputting the running state and the source code analysis result into an optimization model to obtain a configuration optimization suggestion output by the optimization model when the running state of the connection pool is abnormal or the source code analysis result indicates that the code causing the connection leakage exists.
[0034] In an optional embodiment, the method further includes:
[0035] determining that the running state of the connection pool is abnormal when the usage rate of the connection pool is greater than a usage rate threshold or the time length required by the application program to obtain a connection from the connection pool is greater than an acquisition time length threshold.
[0036] In a second aspect, the embodiments of the present application further provide an analysis device for connection leakage, the device including:
[0037] an acquisition module, configured to acquire connection data of each potential leak connection, wherein the connection usage time of each potential leak connection is greater than a usage time threshold, and the connection data includes call stack information;
[0038] a first processing module, configured to generate a call stack signature of each potential leaked connection based on the call stack information of each potential leaked connection, and determine a suspicious call stack signature from the obtained call stack signatures;
[0039] a second processing module, configured to extract multiple classes of call stack information corresponding to the suspicious call stack signature, decompile bytecodes corresponding to the multiple classes, and obtain source codes of the multiple classes;
[0040] An analysis module is used to determine a source code analysis result based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, wherein the source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
[0041] In an optional embodiment, the connection data further includes: a connection identifier, a connection acquisition time, a connection usage duration, and thread information.
[0042] In an optional embodiment, when generating the call stack signature of each potential leak connection based on the call stack information of each potential leak connection, the first processing module is further configured to:
[0043] For each potentially leaked connection, perform the following operations:
[0044] Normalize the call stack information of a potential leaked connection;
[0045] Core information is extracted from call stack information of a potential leaked connection, and a call stack signature of the potential leaked connection is generated based on the core information.
[0046] In an optional embodiment, when normalizing call stack information of a potential leaked connection, the first processing module is further configured to:
[0047] Irrelevant stack frames in call stack information of a potential leaked connection are filtered, wherein the irrelevant stack frames are stack frames that are irrelevant to the application code.
[0048] In an optional embodiment, when a suspicious call stack signature is determined from the obtained call stack signatures, the first processing module is further configured to:
[0049] Determining a suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity measurement value of a time distribution of multiple potential leaked connections corresponding to each call stack signature;
[0050] Based on the suspicious values of each call stack signature, suspicious call stack signatures whose suspicious values meet preset suspicious conditions are screened out from each call stack signature.
[0051] In an optional embodiment, when determining the suspicious value of each call stack signature based on the number of occurrences of each call stack signature and the uniformity metric value of the time distribution of multiple potential leaked connections corresponding to each call stack signature, the first processing module is further configured to:
[0052] For each call stack signature, perform the following operations: obtain and analyze a time series of a call stack signature to obtain a uniformity measurement value of the time distribution corresponding to the call stack signature, where the time series includes time points of multiple potential leaked connections corresponding to the call stack signature;
[0053] The number of occurrences of each call stack signature and the corresponding time distribution uniformity measurement value are normalized and weighted summed to obtain the suspicious value of each call stack signature.
[0054] In an optional embodiment, when decompiling the bytecodes corresponding to the multiple classes to obtain the source codes of the multiple classes, the second processing module is further configured to:
[0055] Filtering irrelevant classes from the multiple classes; and / or, filtering out multiple classes belonging to upper-layer stack frames from the multiple classes; wherein the irrelevant classes are classes unrelated to the connection leakage event, and the upper-layer stack frames are stack frames whose stack frame depth in the call stack information corresponding to the suspicious call stack signature meets a preset depth condition;
[0056] The bytecodes corresponding to multiple classes are decompiled through decompilation tools to obtain the source codes of multiple classes.
[0057] In an optional embodiment, before determining the source code analysis result based on the suspicious call stack signature, the source codes of the multiple classes, and the connection data corresponding to the suspicious call stack signature, the second processing module is further configured to:
[0058] Filter irrelevant code from the source code of multiple classes, where irrelevant code is code that is irrelevant to the core business logic.
[0059] In an optional embodiment, when determining the source code analysis result based on the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature, the analysis module is further configured to:
[0060] The suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature are input into the code analysis model to obtain the source code analysis results output by the code analysis model. Among them, when the source code analysis result is that there is code that causes connection leakage, the source code analysis result includes: an exception report, and the exception report includes: the class, method and line number that causes the connection leakage, as well as the corresponding code snippet.
[0061] In an optional embodiment, the apparatus further includes a configuration optimization module, and the configuration optimization model is used to:
[0062] When the running status of the connection pool is abnormal or the source code analysis result shows that there is code that causes connection leakage, the running status and source code analysis results are input into the optimization model to obtain the configuration optimization suggestions output by the optimization model.
[0063] In an optional embodiment, the configuration optimization model is further used to:
[0064] When the usage of the connection pool is greater than the usage threshold, or the time required for the application to obtain a connection from the connection pool is greater than the acquisition time threshold, it is determined that the operation status of the connection pool is abnormal.
[0065] In a third aspect, an embodiment of the present application further provides an electronic device, including:
[0066] processor; and
[0067] Memory for storing programs,
[0068] The program includes instructions, and when the instructions are executed by the processor, the processor executes the connection leakage analysis method as described in the first aspect.
[0069] In a fourth aspect, an embodiment of the present application further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the connection leakage analysis method as described in the first aspect.
[0070] In a fifth aspect, the present application provides a computer program product, which, when called by a computer, enables the computer to execute the steps of the connection leakage analysis method as described in the first aspect.
[0071] The beneficial effects of this application are as follows:
[0072] In the connection leakage analysis method provided in the embodiment of the present application, after obtaining the connection data of each potential leak connection, the call stack signature of each potential leak connection can be generated based on the call stack information of each potential leak connection, and the suspicious call stack signature can be determined from the obtained call stack signatures; multiple classes of call stack information corresponding to the suspicious call stack signature are extracted, and the bytecodes corresponding to the multiple classes are decompiled to obtain the source code of the multiple classes; based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, the source code analysis result is determined, and the source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code. In this way, by analyzing the connection data and source code of the potential leak connection, it is possible to accurately locate the code location of the unclosed connection, that is, locate the location of the code that causes the connection leakage, and obtain the root cause of the connection pool leakage problem, thereby effectively avoiding performance degradation or system failure caused by exhaustion of connection pool resources, significantly improving the stability and operation efficiency of the application, and avoiding manual troubleshooting, and being able to obtain the location of the code that causes the connection leakage in a more timely manner.
[0073] In addition, other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or may be understood by practicing the present application. The objectives and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described here are used to provide a further understanding of the present application, constitute a part of the present application, and do not constitute an improper limitation of the present application. In the drawings:
[0075] Figure 1 A schematic diagram of an optional system architecture applicable to the embodiments of the present application;
[0076] Figure 2 A schematic diagram of an implementation flow of a connection leakage analysis method provided in an embodiment of the present application;
[0077] Figure 3 A logical diagram for determining a potential leaking connection provided in an embodiment of the present application;
[0078] Figure 4 A logical diagram of a connection leakage analysis provided in an embodiment of the present application;
[0079] Figure 5 A schematic structural diagram of a connection leakage analysis device provided in an embodiment of the present application;
[0080] Figure 6 FIG. 1 shows a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0081] Embodiments of the present application will be described in more detail with reference to the drawings. While the present application is susceptible to various modifications and alternative forms, specific embodiments thereof are shown by way of example in the drawings and will herein be described in detail. It should be understood, however, that the drawings are not intended to limit the present application to the particular embodiments disclosed, but on the contrary, the intention is to cover all modifications, equivalents and alternatives falling within the spirit and scope of the present application as defined by the appended claims. It should be understood that the present application is not limited in scope to the particular embodiments disclosed herein, which are intended as examples only, but the present application should be construed to include all embodiments falling within the spirit and scope of the present application.
[0082] It should be understood that the various steps described in the method embodiments of the present application can be performed in different order and / or in parallel. Additionally, the method embodiments can include additional steps and / or omit performing the steps shown. The scope of the present application is not limited in this regard.
[0083] The term "comprises" and variations thereof herein are used to mean including, but not limited to. The term "based on" means "based, at least in part, on". The term "one embodiment" means "at least one embodiment". The term "another embodiment" means "at least one additional embodiment". The term "some embodiments" means "at least some embodiments". Related terms are defined as follows: "consisting of means "hearing only those members specifically identified". "Consisting essentially of means that the composition or process can include additional ingredients or steps, but only if no additional essential properties are thereby conferred. "Comprising" means "including, but not limited to".
[0084] It should be noted that the terms "one", "multiple", "a number of", etc. used in the present application are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise explicitly stated in the context, they should be understood as "one or more".
[0085] The names of the messages or information exchanged between the plurality of devices in the embodiments of the present application are used only for illustrative purposes, and are not intended to limit the scope of the messages or information.
[0086] Some terms in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0087] (1) Java Agent: This is a mechanism provided by the Java Virtual Machine (JVM) that allows the bytecode of an application to be modified or enhanced through an agent when the application starts. This mechanism is often used to implement various types of code injection, performance monitoring, logging, aspect-oriented programming (AOP), and other functions.
[0088] (2) Bytecode Manipulation: Java Agents allow developers to intercept and modify the bytecode of a class during the class loading process of an application. This requires analyzing, modifying, and regenerating the bytecode. To achieve this, bytecode manipulation libraries such as ASM and ByteBuddy are typically used. These libraries provide a high-level Application Programming Interface (API), making operations at the bytecode level relatively easy.
[0089] (3) Database connection pool: It is a technology used to efficiently manage database connections. It creates and maintains a certain number of connections in advance for application reuse to reduce the overhead of connection establishment and closing, improve performance and optimize resource utilization.
[0090] (4) Large Language Model (LLM): This is a significant technological breakthrough in the field of artificial intelligence in recent years. Based on deep learning and neural network architecture, it generates complex language models through massive data training. Its core advantage lies in its powerful language understanding and generation capabilities, enabling it to handle a variety of tasks in natural language processing (NLP), such as text generation, translation, and question answering. By learning patterns and relationships from large amounts of text, large models can generate coherent and accurate text content and have demonstrated broad application potential in multiple fields.
[0091] With the advent of the internet and big data, databases have become a core component of many applications. Applications frequently interact with databases to store and retrieve data. To improve performance and efficiency, many applications use database connection pools to manage the creation and release of database connections.
[0092] A database connection pool is a technical component used to efficiently manage database connections. It creates and maintains a certain number of connections in advance for application reuse, thereby reducing the overhead of establishing and closing connections, improving performance, and optimizing resource utilization.
[0093] However, during the use of the database connection pool, connection leakage may occur, leading to connection resource exhaustion or performance bottlenecks, especially in high-concurrency scenarios. Connection leakage refers to the fact that an application does not properly release a database connection after using it, resulting in the connection resource not being recycled and reused.
[0094] Existing monitoring tools are generally difficult to effectively detect and locate the root cause of connection leakage, and the stability and performance of the system are poor.
[0095] Therefore, in the embodiments of the present application, a connection leakage analysis method and device, an electronic device and a storage medium are provided. Connection data of each potential leakage connection is obtained, wherein the connection usage time of each potential leakage connection is greater than a usage time threshold, and the connection data includes call stack information. Then, based on the call stack information of each potential leakage connection, a call stack signature of each potential leakage connection is generated, and a suspicious call stack signature is determined from the obtained call stack signatures. The call stack information corresponding to the suspicious call stack signature is extracted, the bytecodes corresponding to the multiple classes are decompiled, and the source code of the multiple classes is obtained. Finally, based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, a source code analysis result is determined, which indicates whether there is code causing connection leakage and the location of the code. In this way, by analyzing the connection data and the source code of the potential leakage connection, the location of the code that does not close the connection can be accurately located, i.e., the location of the code causing connection leakage is located, and the root cause of the connection pool leakage problem is obtained. Therefore, performance degradation or system failure caused by connection pool resource exhaustion can be effectively avoided, the stability and running efficiency of the application program are significantly improved, and manual troubleshooting is avoided, so that the location of the code causing connection leakage can be obtained more timely.
[0096] In particular, the preferred embodiments of the present application are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application, and the embodiments and features of the embodiments can be combined with each other without conflict.
[0097] Reference is made to Figure 1As shown, it is an optional system architecture diagram applicable to the embodiments of the present application, which can include: terminal devices (101a, 101b) and a server 102. The terminal devices (101a, 101b) and the server 102 can interact information through a communication network, wherein the communication network can adopt a communication mode including a wireless communication mode and a wired communication mode. For example, the terminal devices (101a, 101b) can access the network through a cellular mobile communication technology and communicate with the server 102. The cellular mobile communication technology includes, for example, a 5th generation mobile communication (5th generation mobile networks, 5G) technology or a next generation mobile communication technology. Alternatively, the terminal devices (101a, 101b) can access the network through a short-range wireless communication mode and communicate with the server 102. The short-range wireless communication mode includes, for example, a wireless fidelity (wireless fidelity, Wi-Fi) technology.
[0098] The embodiments of the present application do not limit the number of communication devices involved in the above system architecture, for example, the above system architecture can include more terminal devices, or can include fewer terminal devices, or can also include other network devices. For example, Figure 1 As shown, only the terminal devices (101a, 101b) and the server 102 are described as an example, and the above communication devices and their respective functions are briefly introduced below.
[0099] The terminal devices (101a, 101b) and the server 102 can communicate through a communication network.
[0100] In an optional implementation, the communication network can be a wired network or a wireless network. Therefore, the terminal devices (101a, 101b) and the server 102 can be directly or indirectly connected through wired or wireless communication mode. For example, the terminal devices (101a, 101b) can be indirectly connected with the server 102 through a wireless access point, or the terminal devices (101a, 101b) can be directly connected with the server 102 through the Internet, which is not limited in the present application.
[0101] For example, the terminal devices (101a, 101b) can include but are not limited to: mobile phones, tablet computers, notebook computers, desktop computers, e-book readers, smart voice interaction devices, smart home appliances, vehicle-mounted terminals, etc.; various clients can be installed on the terminal devices, which can be application programs (such as browsers, game software, etc.), or web pages, applets, etc.
[0102] Server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0103] It is worth mentioning that the server 102 in the embodiment of the present application can obtain the connection data of each potential leak connection; then, based on the call stack information of each potential leak connection, generate a call stack signature for each potential leak connection, and determine the suspicious call stack signature from the obtained call stack signatures; extract multiple classes of call stack information corresponding to the suspicious call stack signature, decompile the bytecodes corresponding to the multiple classes, and obtain the source code of the multiple classes; finally, based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, determine the source code analysis result, and the source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
[0104] Optionally, a pre-trained large language model can be deployed on server 102. In this way, after obtaining the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature, server 102 can input the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature into the large language model to analyze the source code and thereby determine the source code analysis result.
[0105] The following describes the connection leakage analysis method provided by the exemplary embodiment of the present application in combination with the above-mentioned system architecture and with reference to the accompanying drawings. It should be noted that the above-mentioned system architecture is only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0106] See Figure 2 As shown, it is a schematic diagram of the implementation process of a connection leakage analysis method provided by an embodiment of the present application. The execution subject takes the server as an example. The specific implementation process of the method is as follows:
[0107] S20: Obtain connection data of each potential leak connection.
[0108] Among them, the connection usage duration of each potential leaked connection is greater than the usage duration threshold, and the connection data includes: call stack information, and the connection data also includes: connection identifier, connection acquisition time, connection usage duration and thread information, etc. This is not limited in the embodiments of the present application.
[0109] In this embodiment of the present application, the connection usage duration of each connection is obtained, and the following operations are performed for each connection: if the connection usage duration of a connection is greater than the usage duration threshold, the connection is determined to be a potential leak connection, that is, the connection is considered to have a risk of leakage. At this time, the connection data of the connection is also reported to the monitoring system and stored in a log file or distributed storage system.
[0110] Exemplarily, the connection usage duration is determined based on the connection acquisition time and the connection return time, and the usage duration threshold is 10 seconds, which is not limited in the embodiments of the present application.
[0111] Optionally, in an embodiment of the present application, each connection may be monitored in real time. If a connection is not returned within a usage time threshold, the connection is determined to be a potential leak connection.
[0112] For example, if a connection is not returned within 10 seconds after being acquired, the connection is determined to be a potential leaked connection.
[0113] Optionally, in an embodiment of the present application, the connection usage time of each connection is determined by monitoring the acquisition and return of the connection, and specifically the following operations are performed:
[0114] S200: When acquiring a connection, a unique connection identifier is generated, and the connection identifier is bound to the current thread information, call stack information and acquisition time, and stored in the corresponding connection pool open record storage.
[0115] In an embodiment of the present application, during the deployment phase of the application, an integrated bytecode embedding tool (such as ASM and ByteBuddy, etc.) dynamically modifies the bytecode of the application and installs a Java Agent, thereby inserting monitoring code at key locations for obtaining and returning database connections.
[0116] Exemplarily, a monitoring code is embedded in a database connection acquisition method (eg, getConnection()) to record the connection acquisition time, call stack information, a unique identifier of the connection, and current thread information.
[0117] S201: When returning a connection, the return time of the connection is recorded, and the corresponding acquisition record is searched through the connection identifier. Based on the return time and acquisition time of the connection, the connection usage time is calculated.
[0118] Exemplarily, a monitoring code is embedded in a connection return method (eg, close() or returnConnection()) to record the time of connection return.
[0119] Furthermore, in an embodiment of the present application, when returning a connection, after calculating the connection usage time, the corresponding data in the connection pool opening record storage is cleared.
[0120] In this way, through dynamic bytecode embedding and real-time monitoring, database connection leaks can be automatically detected, connection pool exhaustion can be prevented, and the risk of system failure can be reduced.
[0121] See Figure 3 , which is a logic diagram for determining a potential leak connection provided in an embodiment of the present application.
[0122] S21: Generate a call stack signature for each potential leaked connection based on the call stack information of each potential leaked connection, and determine a suspicious call stack signature from the obtained call stack signatures.
[0123] Optionally, in an embodiment of the present application, a possible embodiment is provided for generating a call stack signature for each potential leaked connection based on the call stack information of each potential leaked connection. Specifically, the following operations are performed:
[0124] For each potentially leaked connection, perform the following operations:
[0125] S210: Normalize call stack information of a potential leaked connection.
[0126] In the embodiment of the present application, the normalization process includes but is not limited to the following processes: filtering irrelevant stack frames in the call stack information of a potential leaked connection.
[0127] The irrelevant stack frames are stack frames that are irrelevant to the application code.
[0128] For example, stack frames related to a connection pool framework or a bytecode embedding tool (eg, a proxy class of java.sql.DriverManager or ByteBuddy) are removed from call stack information of a potential connection leak, and only stack frames related to the application code are retained.
[0129] In this way, the normalization process is performed to ensure that the call stack signature is accurately and deterministically generated, thereby determining that the call stack signature can be called.
[0130] S211: Extract core information from call stack information of a potential leaked connection, and generate a call stack signature of the potential leaked connection based on the core information.
[0131] The core information includes but is not limited to: class name, method name, and line number.
[0132] For example, extract the class name, method name, and line number from the call stack to generate a unique call stack signature: com.example.MyService.getData:42.
[0133] Optionally, the present application provides a possible embodiment for determining suspicious call stack signatures from the obtained call stack signatures, which specifically performs the following operations:
[0134] S212: Determine the suspicious value of each call stack signature based on the number of occurrences of each call stack signature and the uniformity measure value of the time distribution of the plurality of potential leakage connections corresponding to each call stack signature.
[0135] In the present application, the suspicious value of each call stack signature is determined by performing the following operations:
[0136] S2120: For each call stack signature, the following operations are performed: obtain and analyze the time series of a call stack signature to obtain the uniformity measure value of the time distribution corresponding to the call stack signature.
[0137] The time series includes the time points of the plurality of potential leakage connections corresponding to the call stack signature, which are determined by the connection acquisition time.
[0138] In the present application, the time interval standard deviation and time span in a time series are calculated, and based on the time interval standard deviation and time span, the uniformity measure value of the time distribution corresponding to a call stack signature is determined.
[0139] The calculation formula of the uniformity measure value of the time distribution corresponding to the aforementioned call stack signature can be specifically represented as follows:
[0140]
[0141] where σ i represents the time interval standard deviation, ∈ represents a small constant to prevent division by zero, ∈ = 10 -6 , span i represents the time span of the time series corresponding to the i-th call stack signature, span max represents the maximum time span in the time span of the time series corresponding to each call stack signature, span i = t ni -t1, t ni is the last time point in the time series corresponding to the i-th call stack signature, t1 is the first time point in the time series corresponding to the i-th call stack signature.
[0142] where σ i The calculation formula of σ
[0143]
[0144] Where Δt j =t j+1 -t j ,
[0145] S2121: Normalize and weight the obtained number of occurrences of each call stack signature and the corresponding time distribution uniformity measurement value to obtain the suspicious value of each call stack signature.
[0146] In the embodiment of the present application, the calculation formula of the suspicious value of the i-th call stack signature can be specifically expressed as follows:
[0147]
[0148] Among them, n i is the number of occurrences of the i-th call stack signature, n max is the maximum number of occurrences of each call stack signature, D max is the maximum value of the uniformity measurement value of the time distribution corresponding to each call stack signature, w1 is the weight of the number of occurrences, w2 is the weight of the uniformity of the time distribution, w1 can be 0.7, w2 can be 0.3, and this is not limited in the embodiment of the present application.
[0149] S213: Based on the suspicious values of the call stack signatures, suspicious call stack signatures whose suspicious values meet a preset suspicious condition are screened out from the call stack signatures.
[0150] In an embodiment of the present application, the suspicious values of each call stack signature are sorted from large to small to obtain a sorted call stack signature list, and the call stack signature with the largest suspicious value is preferentially selected as the suspicious call stack signature.
[0151] In addition, it is worth noting that in the embodiment of the present application, after analyzing the first call stack signature in the call stack signature list as a suspicious call stack signature, the other call stack signatures in the call stack signature list can also be analyzed in sequence as suspicious call stack signatures.
[0152] In this way, by comprehensively considering the uniformity of time distribution and the number of occurrences, the suspicious call stack signature can be accurately determined.
[0153] For example, assume there are 3 call stack signatures, call stack signature 1: n1 = 10, time series T1 = {1, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8}; call stack signature 2: n2 = 9, time series T2 = {1, 11, 21, 31, 41, 51, 61, 71, 81}; call stack signature 3: n3 = 8, time series T3 = {1, 3, 6, 10, 15, 22, 30, 40}.
[0154] The interval of time series T1 is {0.2, 0.2, ..., 0.2}, σ 1= 0, span1=2.8-1=1.8, D1=(1 / (0+10 -6 ))*(1.8 / 80)≈10 6 *0.0225=22500.
[0155] The interval of time series T2 is {10, 10, ..., 10}, σ2 = 0, span2 = 81-1 = 80, D2 = (1 / (0+10 -6 ))*(80 / 80)=10 6 .
[0156] The intervals of the time series T3 are {2, 3, 4, 5, 7, 8, 10}, σ3≈2.927, span3=40-1=39, D3≈(1 / 2.927)*(39 / 80)≈0.166.
[0157] Among them, n max =10, D max =10 6 , then the suspicious value S1 of call stack signature 1 is 0.7*(10 / 10)+0.3*(22500 / 10 6 )=0.70675, the suspicious value S2 of call stack signature 2=0.7*(9 / 10)+0.3*(10 6 / 10 6 )=0.93, the suspicious value S3 of call stack signature 3=0.7*(8 / 10)+0.3*(0.166 / 10 6 )≈0.56. The final sorted list of call stack signatures is: [call stack signature 2, call stack signature 1, call stack signature 3].
[0158] Furthermore, in an embodiment of the present application, after obtaining the suspicious call stack signature, an alarm is sent through the monitoring system (in the form of alarm, such as email, Slack, and enterprise WeChat, etc.), and / or the information associated with the suspicious call stack signature is stored in a distributed storage system for subsequent query.
[0159] Furthermore, in an embodiment of the present application, a flame graph or call chain graph corresponding to the suspicious call stack signature is generated to intuitively display the leaked code path.
[0160] S22: extracting multiple classes of call stack information corresponding to the suspicious call stack signature, decompiling bytecodes corresponding to the multiple classes, and obtaining source codes of the multiple classes.
[0161] Exemplarily, multiple classes of call stack information corresponding to the suspicious call stack signature are extracted, such as com.example.MyService.
[0162] In the embodiment of the present application, a Java Agent is loaded when the application is started, and the bytecodes (.class files) of multiple classes are obtained through the Instrumentation API.
[0163] Optionally, in an embodiment of the present application, a possible embodiment is provided for decompiling the bytecodes corresponding to multiple classes to obtain the source codes of the multiple classes. Specifically, the following operations are performed:
[0164] S220: Filter the multiple classes to obtain the filtered multiple classes.
[0165] In this way, the amount of bytecode data can be reduced and efficiency can be improved.
[0166] Optionally, in the embodiment of the present application, the screening process includes the following two processes:
[0167] Processing 1: Filter irrelevant classes from multiple classes to obtain multiple filtered classes.
[0168] The irrelevant class is a class that is not related to the connection leakage event.
[0169] In the embodiment of the present application, classes unrelated to the connection leakage event are filtered out from the multiple classes to obtain multiple filtered classes.
[0170] For example, filter out authoritative Java classes from multiple classes.
[0171] Process 2: Filter out multiple classes belonging to the upper stack frame from multiple classes.
[0172] The upper stack frame is a stack frame whose stack frame depth in the call stack information corresponding to the suspicious call stack signature meets a preset depth condition.
[0173] For example, if the depth condition is 10, the upper stack frames are the first 10 stack frames from top to bottom in the call stack information corresponding to the suspicious call stack signature.
[0174] In addition, it is worth noting that in the embodiment of the present application, one of the two processes can be selected, or the two processes can be combined, and this is not limited in the embodiment of the present application.
[0175] Optionally, in an embodiment of the present application, a possible embodiment is provided for combining the two processes to filter multiple classes and obtain multiple filtered classes. Specifically, the following operations are performed: irrelevant classes are filtered out from the multiple classes to obtain multiple filtered classes; stack frames containing irrelevant classes in the call stack information corresponding to the suspicious call stack signature are filtered out; and then, from the filtered multiple classes, multiple classes belonging to upper-level stack frames are filtered out. Since the stack frames containing irrelevant classes in the call stack information corresponding to the suspicious call stack signature are filtered out at this time, the upper-level stack frames are stack frames whose depths meet a preset depth condition among the stack frames that do not contain irrelevant classes.
[0176] For example, assuming that the order of stack frames from top to bottom in the call stack information corresponding to the suspicious call stack signature is: stack frame 1, stack frame 2, stack frame 3, stack frame 4, stack frame 5, stack frame 6, stack frame 7, stack frame 8, stack frame 9, stack frame 10, stack frame 11, stack frame 12, stack frame 13, stack frame 14, stack frame 15, assuming that the depth condition is 10, stack frame 2, stack frame 7 and stack frame 9 contain irrelevant classes, then the upper stack frames are: stack frame 1, stack frame 3, stack frame 4, stack frame 5, stack frame 6, stack frame 8, stack frame 10, stack frame 11, stack frame 12, stack frame 13, and from the filtered multiple classes, multiple classes belonging to the upper stack frames are screened out.
[0177] In this way, the accuracy of multiple classes used for decompilation can be guaranteed, and the amount of bytecode data can be reduced, thereby improving efficiency.
[0178] S221: Decompile the bytecodes corresponding to the multiple classes using a decompilation tool to obtain source codes of the multiple classes.
[0179] Among them, the decompilation tools are: CFR, JD-Core or FernFlower, etc.
[0180] In the embodiment of the present application, a decompilation tool that supports modern Java features (such as Lambda and Stream) is selected to ensure the readability of the source code.
[0181] Furthermore, in an embodiment of the present application, after the source codes of multiple classes are obtained, in order to improve the simplicity of the source codes, irrelevant codes in the source codes of the multiple classes may be filtered.
[0182] Among them, irrelevant code is code that is irrelevant to the core business logic.
[0183] Exemplarily, irrelevant codes (eg, bridge methods) in the source codes of multiple classes are removed, and codes related to the core business logic are retained.
[0184] Furthermore, in an embodiment of the present application, the decompiled source code can also be associated with the class name and call stack signature and stored in a temporary database or file system.
[0185] S23: Determine a source code analysis result based on the suspicious call stack signature, source codes of multiple classes, and connection data corresponding to the suspicious call stack signature.
[0186] Among them, the source code analysis results are used to indicate whether there is code that causes connection leakage and the location of the code. Since there may be multiple potential leakage connections corresponding to the same call stack signature, the connection data corresponding to the suspicious call stack signature can be the connection data of multiple potential leakage connections.
[0187] In an embodiment of the present application, the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature are input into the code analysis model to obtain the source code analysis results output by the code analysis model.
[0188] When the source code analysis result indicates that there is code that causes a connection leak, the source code analysis result includes an exception report, which includes the class, method, and line number that caused the connection leak, as well as a corresponding code snippet.
[0189] In addition, it is worth noting that the code analysis model in the embodiment of the present application is a large language model, for example, Grok3 or other large language models that can be used for code analysis.
[0190] Exemplarily, in an embodiment of the present application, a code analysis model is called to perform context analysis on the source code of multiple classes to obtain source code analysis results. The input of the code analysis model is: suspicious call stack signatures (such as method names and line numbers), source codes of multiple classes, and connection data corresponding to the suspicious call stack signatures (such as connection identifiers and connection acquisition times). The analysis logic of the code analysis model is: 1. Search for operations related to database connections (such as getConnection(), close()); 2. Check the resource management mode to identify missing close() calls or improper exception handling (such as try-catch swallowing exceptions); 3. Analyze the call chain to confirm whether the connection is not released due to asynchronous tasks, thread pools, or loop logic. The code analysis model is called to output the existence of code that causes connection leakage and output an exception report. The exception report includes: the class, method, and line number that causes the connection leakage (such as MyService.getData:42), as well as the corresponding code snippet.
[0191] In this way, automated analysis of call stack information and decompiled source code can accurately locate the code location of unclosed connections, reducing manual troubleshooting time.
[0192] Furthermore, in an embodiment of the present application, after obtaining the source code analysis results, an alarm is sent through the monitoring system (in the form of alarm, such as email, Slack, and enterprise WeChat, etc.), and / or the source code analysis results are stored in a distributed storage system for subsequent query.
[0193] Furthermore, in an embodiment of the present application, the operating status of the connection pool can also be monitored to detect whether there may be connection pool performance problems or connection leakage risks. When the operating status of the connection pool is abnormal, the connection pool may have connection pool performance problems or connection leakage risks.
[0194] In this way, when analyzing connection leaks, we not only consider the abnormal code in the source code, but also the operating status of the connection pool itself. We conduct a comprehensive connection leak analysis, prevent the connection pool from being exhausted, and reduce the risk of system failure.
[0195] Specifically, in an embodiment of the present application, when the usage rate of the connection pool is greater than the usage rate threshold, or the time required for the application to obtain a connection from the connection pool is greater than the acquisition time threshold, it is determined that the operating status of the connection pool is abnormal.
[0196] Among them, the usage rate of the connection pool = the number of connections currently in use / the maximum number of connections, the usage rate threshold can be 90%, and the acquisition time threshold can be 5 seconds, which is not limited in the embodiment of the present application.
[0197] In addition, it is worth noting that when it is determined that the operating status of the connection pool is abnormal, an alarm will be triggered and the status information of the current connection pool will be recorded. For example, when the time required for the application to obtain a connection from the connection pool is greater than the acquisition time threshold, the thread information, call stack information and current connection pool status information of the connection will be recorded.
[0198] Among them, the status information includes: the number of connections currently in use, the number of idle connections, the maximum number of connections in the connection pool, and the time to obtain a connection. The number of connections currently in use is: the number of connections currently occupied by the application, the number of idle connections is: the number of connections currently in the idle state, the maximum number of connections in the connection pool is: the maximum number of connections allowed by the connection pool, and the connection acquisition time is: the average time and longest waiting time required for the application to obtain a connection from the connection pool.
[0199] In an embodiment of the present application, a monitoring function is integrated into the connection pool management module to collect status information of the connection pool in real time.
[0200] Furthermore, in an embodiment of the present application, when the operating status of the connection pool is abnormal or the source code analysis result shows that there is code that causes connection leakage, the operating status and source code analysis result are input into the optimization model to obtain configuration optimization suggestions output by the optimization model.
[0201] Among them, the optimized model is a large language model.
[0202] Exemplarily, in an embodiment of the present application, an optimization model is called to analyze and generate connection pool configuration optimization suggestions. The input of the optimization model is: source code analysis results or the operating status of the connection pool (e.g., the utilization rate of the connection pool is greater than 90% or the connection acquisition time is greater than 5 seconds). The analysis logic of the optimization model is: 1. If the utilization rate is greater than the utilization threshold, it is recommended to reduce the maximum number of connections or increase the idle connection recycling frequency; 2. If the connection acquisition time is greater than the time threshold, it is recommended to shorten the connection timeout or optimize the connection pool allocation strategy (e.g., prioritize the allocation of idle connections); 3. If the leak is concentrated in a specific business logic, it is recommended to add automatic closing logic in the source code (e.g., try-with-resources). The output of the optimization model is: 1. Specific configuration parameters (e.g., maxPoolSize=50, connectionTimeout=3000ms); 2. Optimization strategy (e.g., enabling the automatic leak detection mechanism of the connection pool); 3. Code repair suggestions (e.g., adding close() in a specific method or using try-with-resources).
[0203] In this way, configuration optimization and repair suggestions are generated based on the operating status and source code analysis results, automatic feedback is achieved, connection pool configuration optimization suggestions are intelligently generated, parameters are dynamically adjusted, resource waste is reduced, and database performance is improved.
[0204] Furthermore, in an embodiment of the present application, after obtaining configuration optimization suggestions, the source code analysis results and the configuration optimization suggestions are integrated into a comprehensive report for reference by the development and operation and maintenance teams.
[0205] The report includes: 1. The code location (class, method, line number, code snippet) that caused the connection leak; 2. Connection pool configuration optimization suggestions (parameter adjustment and policy improvement, etc.); and visualizations (such as a call chain diagram of the leaked code and a trend chart of the connection pool status). The comprehensive report is sent to the development and operations teams through the monitoring system (in the form of notifications such as email and Slack), and the comprehensive report is stored in a distributed storage system for subsequent query and audit.
[0206] In this way, the source code analysis results and configuration optimization suggestions are integrated to generate a comprehensive report, which supports visualization and report notifications, automatic configuration push and code repair, and shortens the problem response cycle.
[0207] See Figure 4 , which is a logical diagram of a connection leakage analysis provided in an embodiment of the present application.
[0208] Furthermore, based on the same technical concept, the embodiment of the present application provides a connection leakage analysis device, which is used to implement the above method flow of the embodiment of the present application. Figure 5 As shown, the connection leakage analysis device 500 may include: an acquisition module 501, a first processing module 502, a second processing module 503, an analysis module 504, and a configuration optimization module 505, wherein:
[0209] The acquisition module 501 is configured to acquire connection data of each potential leak connection, wherein the connection usage time of each potential leak connection is greater than a usage time threshold, and the connection data includes call stack information;
[0210] A first processing module 502 is configured to generate a call stack signature for each potential leak connection based on the call stack information of each potential leak connection, and determine a suspicious call stack signature from the obtained call stack signatures;
[0211] The second processing module 503 is configured to extract multiple classes of call stack information corresponding to the suspicious call stack signature, decompile the bytecodes corresponding to the multiple classes, and obtain the source code of the multiple classes;
[0212] The analysis module 504 is used to determine the source code analysis result based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature. The source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
[0213] In an optional embodiment, the connection data further includes: a connection identifier, a connection acquisition time, a connection usage duration, and thread information.
[0214] In an optional embodiment, when generating the call stack signature of each potential leak connection based on the call stack information of each potential leak connection, the first processing module 502 is further configured to:
[0215] For each potentially leaked connection, perform the following operations:
[0216] Normalize the call stack information of a potential leaked connection;
[0217] Core information is extracted from call stack information of a potential leaked connection, and a call stack signature of the potential leaked connection is generated based on the core information.
[0218] In an optional embodiment, when normalizing call stack information of a potential leaked connection, the first processing module 502 is further configured to:
[0219] Irrelevant stack frames in call stack information of a potential leaked connection are filtered, wherein the irrelevant stack frames are stack frames that are irrelevant to the application code.
[0220] In an optional embodiment, when a suspicious call stack signature is determined from the obtained call stack signatures, the first processing module 502 is further configured to:
[0221] Determining a suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity measurement value of a time distribution of multiple potential leaked connections corresponding to each call stack signature;
[0222] Based on the suspicious values of each call stack signature, suspicious call stack signatures whose suspicious values meet preset suspicious conditions are screened out from each call stack signature.
[0223] In an optional embodiment, when determining the suspicious value of each call stack signature based on the number of occurrences of each call stack signature and the uniformity metric value of the time distribution of multiple potential leaked connections corresponding to each call stack signature, the first processing module 502 is further configured to:
[0224] For each call stack signature, perform the following operations: obtain and analyze a time series of a call stack signature to obtain a uniformity measurement value of the time distribution corresponding to the call stack signature, where the time series includes time points of multiple potential leaked connections corresponding to the call stack signature;
[0225] The number of occurrences of each call stack signature and the corresponding time distribution uniformity measurement value are normalized and weighted summed to obtain the suspicious value of each call stack signature.
[0226] In an optional embodiment, when decompiling the bytecodes corresponding to the multiple classes to obtain the source codes of the multiple classes, the second processing module 503 is further configured to:
[0227] Filtering irrelevant classes from the multiple classes; and / or, filtering out multiple classes belonging to upper-layer stack frames from the multiple classes; wherein the irrelevant classes are classes unrelated to the connection leakage event, and the upper-layer stack frames are stack frames whose stack frame depth in the call stack information corresponding to the suspicious call stack signature meets a preset depth condition;
[0228] The bytecodes corresponding to multiple classes are decompiled through decompilation tools to obtain the source codes of multiple classes.
[0229] In an optional embodiment, before determining the source code analysis result based on the suspicious call stack signature, the source codes of multiple classes, and the connection data corresponding to the suspicious call stack signature, the second processing module 503 is further configured to:
[0230] Filter irrelevant code from the source code of multiple classes, where irrelevant code is code that is irrelevant to the core business logic.
[0231] In an optional embodiment, when determining the source code analysis result based on the suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature, the analysis module 504 is further configured to:
[0232] The suspicious call stack signature, the source code of multiple classes, and the connection data corresponding to the suspicious call stack signature are input into the code analysis model to obtain the source code analysis results output by the code analysis model. Among them, when the source code analysis result is that there is code that causes connection leakage, the source code analysis result includes: an exception report, and the exception report includes: the class, method and line number that causes the connection leakage, as well as the corresponding code snippet.
[0233] In an optional embodiment, the apparatus further includes a configuration optimization module, and the configuration optimization model 505 is used to:
[0234] When the running status of the connection pool is abnormal or the source code analysis result shows that there is code that causes connection leakage, the running status and source code analysis results are input into the optimization model to obtain the configuration optimization suggestions output by the optimization model.
[0235] In an optional embodiment, the configuration optimization model 505 is further used to:
[0236] When the usage of the connection pool is greater than the usage threshold, or the time required for the application to obtain a connection from the connection pool is greater than the acquisition time threshold, it is determined that the operation status of the connection pool is abnormal.
[0237] Based on the description of the above method embodiment and apparatus embodiment, the exemplary embodiments of the present invention further provide an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, and when executed by the at least one processor, the computer program causes the electronic device to perform a method according to an embodiment of the present invention.
[0238] An embodiment of the present application further provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute a method according to an embodiment of the present application.
[0239] An embodiment of the present application further provides a computer program product, including a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute the method according to the embodiment of the present application.
[0240] See Figure 6As shown, the structural block diagram of the electronic device 600 that can be used as the server or client of the present application will now be described, which is an example of a hardware device that can be applied to various aspects of the present application. The electronic device is intended to represent various forms of digital electronic computer equipment, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0241] like Figure 6 As shown, the electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the device 600 can also be stored in the RAM 603. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0242] Multiple components within electronic device 600 are connected to I / O interface 605, including an input unit 606, an output unit 607, a storage unit 608, and a communication unit 609. Input unit 606 can be any type of device capable of inputting information into electronic device 600. Input unit 606 can receive input numeric or character information and generate key input signals related to user settings and / or function control of the electronic device. Output unit 607 can be any type of device capable of presenting information and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. Storage unit 608 may include, but is not limited to, a magnetic disk or an optical disk. Communication unit 609 allows electronic device 600 to exchange information / data with other devices via computer networks such as the Internet and / or various telecommunication networks and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth device, a WiFi device, a Worldwide Interoperability for Microwave Access (WiMax) device, a cellular communication device, and / or the like.
[0243] The computing unit 601 can be various general-purpose and / or specialized processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above. For example, in some embodiments, the above-mentioned connection leakage-based analysis method can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 600 via the ROM 602 and / or the communication unit 609. In some embodiments, the computing unit 601 can be configured to perform the above-mentioned connection leakage analysis method by any other appropriate means (e.g., by means of firmware).
[0244] The program code for implementing the methods of the present application can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow charts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0245] In the context of the present application, a machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a RAM, a ROM, an erasable programmable read-only memory (EPROM) or a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0246] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., a magnetic disk, an optical disk, a memory, a programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0247] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) or a liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0248] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0249] Computer systems may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The client and server relationship arises through computer programs running on the respective computers and having a client-server relationship to each other.
[0250] Furthermore, it should be understood that what is disclosed above is merely a preferred embodiment of the present application and certainly cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope covered by the present application.
Claims
1. A method for analyzing connection leakage, characterized in that: include: Acquire connection data of each potential leak connection, wherein the connection usage time of each potential leak connection is greater than a usage time threshold, and the connection data includes: call stack information; Generating call stack signatures of each potential leaked connection based on the call stack information of each potential leaked connection, and determining a suspicious call stack signature from the obtained call stack signatures; Extracting multiple classes of call stack information corresponding to the suspicious call stack signature, decompiling bytecodes corresponding to the multiple classes, and obtaining source codes of the multiple classes; Based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, a source code analysis result is determined, where the source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
2. The method according to claim 1, wherein The connection data also includes: a connection identifier, a connection acquisition time, a connection usage time, and thread information.
3. The method according to claim 1, wherein Generating the call stack signature of each potential leak connection based on the call stack information of each potential leak connection includes: For each potential leak connection, perform the following operations: Normalize the call stack information of a potential leaked connection; Core information is extracted from the call stack information of the potential leaked connection, and a call stack signature of the potential leaked connection is generated based on the core information.
4. The method according to claim 3, wherein The normalization of call stack information of a potential leaked connection includes: Irrelevant stack frames in the call stack information of the potential leaked connection are filtered, wherein the irrelevant stack frames are stack frames irrelevant to the application code.
5. The method according to claim 1, wherein Determining a suspicious call stack signature from the obtained call stack signatures includes: Determining a suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity metric value of a time distribution of a plurality of potential leaked connections corresponding to each call stack signature; Based on the suspicious values of the call stack signatures, suspicious call stack signatures whose suspicious values meet preset suspicious conditions are screened out from the call stack signatures.
6. The method according to claim 5, wherein The determining of the suspicious value of each call stack signature based on the number of occurrences of each call stack signature and a uniformity metric value of the time distribution of multiple potential leaked connections corresponding to each call stack signature includes: For each call stack signature, the following operations are performed: obtaining and analyzing a time series of a call stack signature to obtain a uniformity metric value of a time distribution corresponding to the call stack signature, wherein the time series includes time points of multiple potential leaked connections corresponding to the call stack signature; The obtained number of occurrences of each call stack signature and the corresponding uniformity measurement value of the time distribution are normalized and weighted summed to obtain the suspicious value of each call stack signature.
7. The method according to claim 1, wherein Decompiling the bytecodes corresponding to the multiple classes to obtain the source codes of the multiple classes includes: Filtering irrelevant classes from the multiple classes; and / or, filtering out multiple classes belonging to upper-layer stack frames from the multiple classes; wherein the irrelevant classes are classes unrelated to the connection leakage event, and the upper-layer stack frames are stack frames whose stack frame depth in the call stack information corresponding to the suspicious call stack signature meets a preset depth condition; Decompile the bytecodes corresponding to the multiple classes using a decompilation tool to obtain source codes of the multiple classes.
8. The method according to claim 1, wherein Before determining the source code analysis result based on the suspicious call stack signature, the source codes of the multiple classes, and the connection data corresponding to the suspicious call stack signature, the method further includes: Irrelevant codes in the source codes of the multiple classes are filtered, wherein the irrelevant codes are codes that are irrelevant to the core business logic.
9. The method according to claim 2, wherein Determining a source code analysis result based on the suspicious call stack signature, the source codes of the multiple classes, and connection data corresponding to the suspicious call stack signature includes: The suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature are input into a code analysis model to obtain a source code analysis result output by the code analysis model, wherein when the source code analysis result is that there is code that causes connection leakage, the source code analysis result includes: an exception report, and the exception report includes: the class, method and line number that causes the connection leakage, and the corresponding code snippet.
10. The method according to claim 1, wherein The method further comprises: When the running state of the connection pool is abnormal or the source code analysis result shows that there is code that causes connection leakage, the running state and the source code analysis result are input into the optimization model to obtain the configuration optimization suggestion output by the optimization model.
11. The method according to claim 10, wherein: The method further comprises: When the usage rate of the connection pool is greater than a usage rate threshold, or the time required for the application to obtain a connection from the connection pool is greater than an acquisition time threshold, it is determined that the operation state of the connection pool is abnormal.
12. A device for analyzing connection leakage, characterized in that: include: an acquisition module, configured to acquire connection data of each potential leak connection, wherein the connection usage time of each potential leak connection is greater than a usage time threshold, and the connection data includes call stack information; a first processing module, configured to generate a call stack signature of each potential leaked connection based on the call stack information of each potential leaked connection, and determine a suspicious call stack signature from the obtained call stack signatures; a second processing module, configured to extract multiple classes of call stack information corresponding to the suspicious call stack signature, decompile bytecodes corresponding to the multiple classes, and obtain source codes of the multiple classes; An analysis module is used to determine a source code analysis result based on the suspicious call stack signature, the source code of the multiple classes, and the connection data corresponding to the suspicious call stack signature, wherein the source code analysis result is used to indicate whether there is code that causes connection leakage and the location of the code.
13. An electronic device comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 11.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable a computer to execute the method according to any one of claims 1-11.
Citation Information
Patent Citations
Database connection leakage positioning method and device, equipment and readable storage medium
CN110245508A
Method and device for determining object for calling stack frame, equipment and medium
CN112925717A
Java program performance analysis method and device, storage medium and computer equipment
CN116541304A
Connection leakage detection method and system for Duid database connection pool
CN116737818A
Connection processing method, device, equipment, medium and product
CN118803008A