Connection release method and device

By monitoring and managing connections in the database connection pool, destroying no longer needed agents and releasing corresponding connections, the resource waste caused by the Pooler process is solved and system performance and response speed is improved.

CN120029728APending Publication Date: 2025-05-23CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411698030.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

The Pooler process caches all used connection pools, even if some connection pools are not currently in use, resulting in waste of resources.

Method used

By obtaining the statement execution status of multiple target connections, destroying the no longer needed agents, reducing the counter value until the preset value is reached, and then the time difference is calculated based on the target time and current time of the agent. If the time difference is not less than the preset time difference value, release the corresponding connection.

Benefits of technology

Effectively release useless connections, avoid resource waste, reduce system load, and improve system performance and response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029728A_ABST
    Figure CN120029728A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of connection pools, and discloses a connection release method and device. The method comprises the following steps: acquiring a plurality of first target connections and an execution state of a statement corresponding to each first target connection; wherein the first target connection is used for representing a connection being used, and the first target connection corresponds to an agent; if the execution state of the target statement meets the target state, destroying an agent corresponding to a second target connection corresponding to the target statement, and reducing the current numerical value of the counter to obtain a target numerical value; wherein the current numerical value of the counter is used for indicating the number of the first target connections, and the target statement is any one of statements corresponding to each connection; if the target numerical value meets the preset numerical value, determining target time corresponding to the target agent; wherein the target agent is used for indicating the last destroyed agent; determining a time difference value based on the target time and the current time; and if the time difference is not smaller than the preset time difference, releasing the first target connection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of connection pools, and in particular to a method and device for releasing a connection. Background Art

[0002] The Pooler process is a background process responsible for connection pool management. Its core function is to cache all used connection pools and keep the connections in them updated (including creation and destruction). The connections in the connection pool are regarded as a reusable resource. By centrally managing these connections, the Pooler process can significantly reduce the overhead of creating and destroying database connections.

[0003] Currently, the Pooler process caches all used connection pools. Even if some connection pools are not currently used by the backend, the connections in them will be kept updated (created, destroyed). At the same time, the pooler also provides an interface that can close and release the specified connection pool through SQL instructions.

[0004] However, the Pooler process caches all used connection pools. Even if some connection pools are not currently used by the backend, they will continue to occupy system resources, resulting in resource waste. Summary of the invention

[0005] In view of this, the present invention provides a connection releasing method and device.

[0006] In a first aspect, the present invention provides a method for releasing a connection, the method comprising: obtaining multiple first target connections and the execution status of statements corresponding to each first target connection; wherein the first target connection is used to characterize the connection in use, and the first target connection corresponds to an agent; if the execution status of the target statement meets the target status, destroying the agent corresponding to the second target connection corresponding to the target statement, and reducing the current value of the counter to obtain the target value; wherein the current value of the counter is used to indicate the number of first target connections, and the target statement is any one of the statements corresponding to each connection; if the target value meets the preset value, determining the target time corresponding to the target agent; wherein the target agent is used to indicate the last agent to be destroyed; based on the target time and the current time, determining the time difference; if the time difference is not less than the preset time difference, releasing the first target connection.

[0007] The connection release method provided in this embodiment is that when the execution status of any statement meets the target status, the proxy corresponding to the statement is no longer needed, and the proxy is destroyed, which can release related system resources and avoid useless proxies occupying system resources.

[0008] At the same time, when the proxy is destroyed, the current value of the counter is reduced to obtain the target value. Until the target value meets the preset value, the target time of the last proxy to be destroyed is determined. According to the target time and the current time, the time difference is determined. If the time difference is not less than the preset time difference, the first target connection is released. That is, after all proxies are destroyed, the first target connections are in an unused state. When the time difference between the current time corresponding to the unused state of the first target connection and the target time corresponding to the target proxy is equal to or exceeds the preset time difference, all first target connections are released, which can reduce the overall load of the system while avoiding useless connections occupying system resources for a long time.

[0009] In one possible implementation, the method further includes: upon receiving a connection request, detecting whether a proxy corresponding to the connection request exists; if the proxy corresponding to the connection request exists, detecting whether a third target connection corresponding to the proxy exists in the connection pool; if a third target connection corresponding to the proxy exists in the connection pool, increasing the current value of the counter.

[0010] The connection release method provided in this embodiment, when receiving a connection request, first needs to verify whether the proxy corresponding to the connection request exists. When the proxy corresponding to the connection request exists, it is detected whether there is a third target connection corresponding to the proxy in the connection pool. If there is a third target connection corresponding to the proxy in the connection pool, the third target connection is used to process the corresponding statement. That is, the connection pool allows the system to reuse existing database connections instead of creating a new connection for each request. This can improve the performance and response speed of the system while reducing resource consumption. At the same time, if a new connection is reused in the connection pool, the current value of the counter needs to be increased to avoid all first target connections being released incorrectly.

[0011] In a possible implementation, the method further includes: if there is no third target connection corresponding to the proxy in the connection pool, initializing the value of the counter corresponding to the third target connection; creating a third target connection corresponding to the proxy, and increasing the value of the counter corresponding to the third target connection.

[0012] In the connection release method provided in this embodiment, if there is no third target connection corresponding to the proxy in the connection pool, it is necessary to initialize the value of the counter corresponding to the third target connection and create the third target connection, so that a new third target connection is created only when needed, which avoids over-allocation and waste of resources. This strategy of allocating resources on demand helps to improve the overall efficiency and performance of the system. In addition, initializing the counter value corresponding to the third target connection ensures that the system can accurately track the usage of the new connection.

[0013] In one possible implementation, the method further includes: obtaining the current database load and application requirements; adjusting the number of connections in the connection pool according to the current database load and application requirements within a preset time period; wherein the connections in the connection pool are used to characterize unused connections; and / or, detecting whether the connections in the connection pool meet preset conditions within a preset time period; if the connections in the connection pool do not meet the preset conditions, clearing the connections that do not meet the preset conditions; and / or, obtaining the idle time of the connections in the connection pool within a preset time period; if the idle time of the connections in the connection pool exceeds the preset idle time, clearing the connections whose idle time exceeds the preset idle time.

[0014] The connection release method provided in this embodiment adjusts the connection pool size according to the real-time load and demand, ensures that the system has sufficient connection resources when the load is high, and releases unnecessary connections when the load is low, thereby optimizing resource utilization. In addition, invalid or damaged connections are removed to prevent them from occupying resources and causing system instability. In addition, connections that have not been used for a long time are released to reduce resource waste.

[0015] In a possible implementation, the method further includes: when the target value is zero, the time difference is not less than a preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time, destroying the connection pool.

[0016] The connection release method provided in this embodiment, when the target value is zero, the time difference is not less than the preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time, it indicates that the connection pool has not been used for a long time, and the connection pool can be destroyed to avoid useless connection pools occupying system resources for a long time.

[0017] In a second aspect, the present invention provides a connection release device, which includes: an acquisition module, which is used to acquire multiple first target connections and the execution status of statements corresponding to each first target connection; wherein the first target connection is used to characterize the connection in use, and the first target connection corresponds to an agent; a processing module, which is used to destroy the agent corresponding to the second target connection corresponding to the target statement if the execution status of the target statement meets the target status, and reduce the current value of the counter to obtain the target value; wherein the current value of the counter is used to indicate the number of first target connections, and the target statement is any one of the statements corresponding to each connection; a first determination module, which is used to determine the target time corresponding to the target agent if the target value meets the preset value; wherein the target agent is used to indicate the last agent to be destroyed; a second determination module, which is used to determine the time difference based on the target time and the current time; a release module, which is used to release the first target connection if the time difference is not less than the preset time difference.

[0018] In one possible implementation, the device further includes: a first detection module, which is used to detect whether a proxy corresponding to a connection request exists when a connection request is received; a second detection module, which is used to detect whether a third target connection corresponding to the proxy exists in the connection pool if the proxy corresponding to the connection request exists; and an increase module, which is used to increase the current value of the counter if a third target connection corresponding to the proxy exists in the connection pool.

[0019] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the connection releasing method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0020] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to cause a computer to execute the connection releasing method of the first aspect or any corresponding embodiment thereof.

[0021] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the connection releasing method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0023] Figure 1 is a schematic flow chart of a method for releasing a connection according to an embodiment of the present invention;

[0024] Figure 2 is a flow chart of a method for releasing a connection provided in an embodiment of the present invention;

[0025] Figure 3 is a structural block diagram of a connection release device according to an embodiment of the present invention;

[0026] Figure 4 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0028] According to an embodiment of the present invention, an embodiment of a method for releasing a connection is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0029] In this embodiment, a connection release method is provided, which can be used for computer devices, such as computers, servers, etc. Figure 1 is a flow chart of a method for releasing a connection according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0030] Step S101, obtaining a plurality of first target connections and the execution status of a statement corresponding to each first target connection; wherein the first target connection is used to represent a connection in use, and the first target connection corresponds to a proxy.

[0031] It should be noted that a client connects to a database process, and multiple clients can connect to the same database through different processes; wherein, the first target connection can be used as a process, that is, a client communicates with the database through the first target connection to execute statements. For example: client A1 communicates with the database through the first target connection B1 and executes statements to query data; client A2 communicates with the database through the first target connection B2 and executes statements to add data. The first target connection can represent a connection in use, that is, a connection that is communicating with the database.

[0032] Each first target connection corresponds to an agent. The agent is used to maintain the backend database on each first target connection. The Agent contains a specific connection pool DatabasePool and the dn and cn arrays that have established connections; among them, CN: Coordinator: Coordinator Node (CN for short). Business access portal, responsible for data distribution and query planning, multiple nodes are located equally, and each node provides the same database view; functionally, CN only stores the global metadata of the system, and does not store actual business data. DN: Data Node (DN for short). In addition to storing shards of business data, each node is also functionally responsible for completing execution requests distributed by the coordinator node.

[0033] The execution status of the statement corresponding to each first target connection can represent the execution stage of the statement, that is, whether the statement has been executed, etc., which is not specifically limited here.

[0034] Step S102, if the execution status of the target statement meets the target status, destroy the proxy corresponding to the second target connection corresponding to the target statement, and reduce the current value of the counter to obtain the target value; wherein the current value of the counter is used to indicate the number of first target connections, and the target statement is any one of the statements corresponding to each connection.

[0035] The target state can represent the state of statement execution completion. The target statement is used to represent any one of the statements corresponding to each connection. When the execution state of a statement meets the target state, the statement is the target statement, and it represents that the statement has been executed, so the proxy corresponding to the statement is no longer needed, and the proxy corresponding to the second target connection corresponding to the target statement needs to be destroyed. Then the current value of the counter is reduced to obtain the target value to reflect the reduction in the number of valid or active connections after the proxy is destroyed. Among them, the current value of the counter is used to indicate the number of first target connections.

[0036] As an example, when a proxy corresponding to a second target connection corresponding to a target statement is destroyed, the current value of the counter may be reduced by 1. When a proxy corresponding to a second target connection corresponding to a target statement is destroyed, the current value of the counter may also be reduced by one time, etc., which is not specifically limited here and may be implemented by those skilled in the art.

[0037] Step S103, if the target value meets the preset value, determine the target time corresponding to the target agent; wherein the target agent is used to indicate the last agent to be destroyed.

[0038] The preset value may indicate a threshold value of the number of valid or active connections after the proxy is destroyed. The preset value may be zero or other values, which are not specifically limited here. Specifically, if the target value meets the preset value, it indicates that the first target connection no longer executes the statement. Then, the target time of the last proxy to be destroyed is determined.

[0039] Step S104, determining a time difference based on the target time and the current time.

[0040] The target time of the last proxy to be destroyed can be used as a fixed value, and the current time is a time value that changes with time; wherein, as time changes, the current time will become larger and larger, and the corresponding time difference will also become larger and larger.

[0041] Step S105: if the time difference is not less than the preset time difference, release the first target connection.

[0042] The preset time difference value can be set by the user. The preset time difference value can be 5s, 10s, etc., which is not specifically limited here. When the time difference value increases to not less than the preset time difference value, all first target connections are released.

[0043] The connection release method provided in this embodiment is that when the execution status of any statement meets the target status, the proxy corresponding to the statement is no longer needed, and the proxy is destroyed, which can release related system resources and avoid useless proxies occupying system resources.

[0044] At the same time, when the proxy is destroyed, the current value of the counter is reduced to obtain the target value. Until the target value meets the preset value, the target time of the last proxy to be destroyed is determined. According to the target time and the current time, the time difference is determined. If the time difference is not less than the preset time difference, the first target connection is released. That is, after all proxies are destroyed, the first target connections are in an unused state. When the time difference between the current time corresponding to the unused state of the first target connection and the target time corresponding to the target proxy is equal to or exceeds the preset time difference, all first target connections are released, which can reduce the overall load of the system while avoiding useless connections occupying system resources for a long time.

[0045] In a possible implementation, the method further includes:

[0046] Step a1: upon receiving a connection request, detecting whether a proxy corresponding to the connection request exists.

[0047] The connection request may be a connection request sent by a client; wherein the connection request is used to instruct the database corresponding to the connection request to connect. The connection request may be configured with a user name, a database name, and a connection to the database used by the user. When a connection request is received, it may be determined whether there is a proxy corresponding to the connection request according to the user name, the database name, and the connection to the database used by the user configured in the connection request.

[0048] Step a2: If a proxy corresponding to the connection request exists, check whether there is a third target connection corresponding to the proxy in the connection pool.

[0049] If the proxy corresponding to the connection request exists, it indicates that the user can use the database, and it is determined whether there is a third target connection corresponding to the proxy in the connection pool according to the connection of the database used by the user.

[0050] Step a3: if there is a third target connection corresponding to the proxy in the connection pool, increase the current value of the counter.

[0051] If there is a third target connection corresponding to the proxy in the connection pool, the communication between the client and the database can be established directly through the third target connection, and the statement can be executed. Wherein, each time a new connection is established, the current value of the counter needs to be increased.

[0052] As an example, when a new connection is established, the current value of the counter may be increased by 1.

[0053] The connection release method provided in this embodiment, when receiving a connection request, first needs to verify whether the proxy corresponding to the connection request exists. When the proxy corresponding to the connection request exists, it is detected whether there is a third target connection corresponding to the proxy in the connection pool. If there is a third target connection corresponding to the proxy in the connection pool, the third target connection is used to process the corresponding statement. That is, the connection pool allows the system to reuse existing database connections instead of creating a new connection for each request. This can improve the performance and response speed of the system while reducing resource consumption. At the same time, if a new connection is reused in the connection pool, the current value of the counter needs to be increased to avoid all first target connections being released incorrectly.

[0054] In a possible implementation, the method further includes:

[0055] Step b1: if the third target connection corresponding to the proxy does not exist in the connection pool, initialize the value of the counter corresponding to the third target connection.

[0056] Step b2: Create a third target connection corresponding to the proxy, and increase the value of the counter corresponding to the third target connection.

[0057] It can be seen from the above step a3 that if there is a third target connection corresponding to the proxy in the connection pool, the communication between the client and the database can be established directly through the third target connection, and the statement can be executed. In this embodiment, if there is no third target connection corresponding to the proxy in the connection pool, the third target connection needs to be recreated. Since the third target connection is a recreated connection, the value of the counter corresponding to the third target connection needs to be initialized so that the value of the counter corresponding to the third target connection is zero. When the new third target connection is created, the value of the counter corresponding to the third target connection is increased.

[0058] In the connection release method provided in this embodiment, if there is no third target connection corresponding to the proxy in the connection pool, it is necessary to initialize the value of the counter corresponding to the third target connection and create the third target connection, so that a new third target connection is created only when needed, which avoids over-allocation and waste of resources. This strategy of allocating resources on demand helps to improve the overall efficiency and performance of the system. In addition, initializing the counter value corresponding to the third target connection ensures that the system can accurately track the usage of the new connection.

[0059] In a possible implementation, the method further includes:

[0060] Step c1, obtain the current database load and application requirements.

[0061] Database load can refer to the number of tasks currently being processed by the database, resource usage (such as CPU, memory, I / O, etc.), and the length of the waiting queue. This information can be obtained through monitoring tools or APIs provided by the database management system. Application requirements can include the current and expected number of concurrent users of the application, request types (such as query, update, delete, etc.), request frequency, and the amount of resources required for each request.

[0062] Step c2, adjusting the number of connections in the connection pool according to the current database load and the requirements of the application program within a preset time period; wherein the connections in the connection pool are used to represent unused connections.

[0063] A connection pool can be a container for storing and reusing database connections. When an application needs to access a database, it requests a connection from the connection pool; when it is no longer needed, the connection is released back to the connection pool for use by other requests. Depending on the current database load and application requirements, the system can dynamically increase or decrease the number of connections in the connection pool. If the database load is high and the application requires more concurrent connections, the system can increase the size of the connection pool to meet the demand; conversely, if the database load is low and the application's concurrent requirements decrease, the system can reduce the size of the connection pool to free up resources.

[0064] The preset time period can be a time window used to trigger the adjustment operation. The system can regularly check the database load and application requirements during this time period and decide whether to adjust the size of the connection pool based on this information. The selection of the preset time period should be determined according to the characteristics and requirements of the system to ensure the timeliness and accuracy of the adjustment operation.

[0065] and / or;

[0066] Step c3: Detect whether the connections in the connection pool meet preset conditions within a preset time period.

[0067] Preconditions define the criteria that a connection should meet. For example, a connection might need to meet some of the following conditions:

[0068] Connections should be active, i.e. they should be able to successfully perform database operations without timing out. Connections should not have unhandled errors or exceptions. Connections should be used at a reasonable frequency to avoid occupying resources for a long time without being effectively used. The security of connections should be guaranteed, for example, they should use the latest encryption protocols and authentication mechanisms. The system can verify that the connection meets the preset conditions by executing specific test queries or operations. These tests can be lightweight to avoid a significant impact on database performance.

[0069] Step c4: if the connection in the connection pool does not meet the preset conditions, clear the connection that does not meet the preset conditions.

[0070] When the system detects that a connection does not meet the preset conditions, it removes the connection from the connection pool. This usually involves closing the connection and releasing the resources associated with it. Clearing out connections that do not meet the conditions helps free up occupied resources, which can be used by other healthy connections or new requests. This helps improve the overall performance and resource utilization of the system.

[0071] and / or;

[0072] Step c5: obtaining the idle time of the connections in the connection pool within a preset time period.

[0073] Idle time refers to the time from the last time a connection was used (i.e., the last database operation was completed) to the current time. In a possible implementation, in order to implement step c5, an efficient monitoring mechanism can be configured to track the usage of each connection. This usually involves updating its status information when the connection is allocated and released.

[0074] Step c6: if the idle time of the connection in the connection pool exceeds the preset idle time, clear the connection whose idle time exceeds the preset idle time.

[0075] The preset idle time is used to define the maximum time a connection can remain idle before it is considered "idle for too long". This value should be set according to the characteristics and needs of the system to ensure the best balance between resource utilization and system performance. When the system detects that a connection has been idle for more than the preset idle time, it will perform cleanup operations. Specifically, this may include closing the connection and releasing all resources associated with it. Cleaning up connections that have been idle for a long time helps reclaim occupied resources, which can be used by other connections that need them or new database operations. This helps improve the overall resource utilization and performance of the system.

[0076] The connection release method provided in this embodiment adjusts the connection pool size according to the real-time load and demand, ensures that the system has sufficient connection resources when the load is high, and releases unnecessary connections when the load is low, thereby optimizing resource utilization. In addition, invalid or damaged connections are removed to prevent them from occupying resources and causing system instability. In addition, connections that have not been used for a long time are released to reduce resource waste.

[0077] In a possible implementation, the method further includes: when the target value is zero, the time difference is not less than a preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time, destroying the connection pool.

[0078] If the reference counter of the connection pool is zero, and the time interval between the current time and the last proxy being destroyed and released is greater than the preset time difference set by the user, and the idle time of the connections in the connection pool exceeds the preset idle time, the database connection pool will be destroyed and all held connections will be released, saving system resources.

[0079] The connection release method provided in this embodiment, when the target value is zero, the time difference is not less than the preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time, it indicates that the connection pool has not been used for a long time, and the connection pool can be destroyed to avoid useless connection pools occupying system resources for a long time.

[0080] Please refer to Figure 2 , Figure 2 is a flowchart of a method for releasing a connection provided according to an embodiment of the present invention.

[0081] Figure 2In the GUC (Grand Unified Configuration), you can set the timeout parameter timeout (that is, the preset time interval mentioned above). GUC implements variable configuration of multiple data types (such as boolean, int, float, string, etc.). The items of GucContext define options that parameters may be configured by different processes at different times. The system will determine under what circumstances the configuration can take effect based on the established priority. This solution configures a user-configurable timeout parameter PoolDisconnectAfterAgentDestroyTimeout through GUC. When the time interval between the last agent destruction time and the current time exceeds this parameter, it will actively release all connections.

[0082] The client initiates a connection request with the backend database. Whenever a connection request is initiated, it first checks whether the corresponding agent exists. If not, it initializes the agent and creates it. If it exists, it continues to determine whether there is a connection pool that can create the required connection. DatabasePool represents a connection pool collection, which is associated with a PoolAgent (agent of the connection).<database,user_name,pgoptions> The parameter is used as the unique identifier of a connection pool. If the connection pool does not exist, it will be created and the reference counter RefCount and the Agent release time m_released will be initialized. After finding the corresponding connection pool, the reference counter RefCount will be incremented by one. When the connection is finished, it will be returned to the connection pool, and the Agent will be destroyed, and the reference counter RefCount will be decremented by one. Whenever an Agent is destroyed, the connection pool used by the Agent will also use m_released to record the destruction time. Each time an Agent using the connection pool is destroyed, m_released will be updated once.

[0083] During this process, the database connection pool maintenance is responsible for monitoring the connection status in the connection pool. It is called at regular intervals in the Pooler main process loop to maintain the health of the connection and ensure that the connection in the connection is always available and in normal working condition. The main functions are as follows:

[0084] (1) Check the idle connections in the connection pool and close the connections that have been idle for too long to avoid resource waste and connection expiration.

[0085] (2) Dynamically adjust the connection pool size to automatically increase or decrease the number of connections in the connection pool based on the current database load and application requirements.

[0086] (3) Monitor the health of connections in the connection pool, identify and clear abnormal or unstable connections, and ensure the stability and reliability of database operations.

[0087] In addition, this solution also adds a function to determine whether the connection pool should be destroyed during the connection pool maintenance process. If the reference counter of the connection pool is 0, and the time interval between the current time and the last Agent being destroyed and released is greater than the timeout parameter set by the user in the GUC, and all connections in the connection pool are idle connections, the database connection pool will be destroyed and all held connections will be released, saving system resources.

[0088] In this embodiment, a connected release device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0089] This embodiment provides a release device for connection, such as Figure 3 As shown, it includes: an acquisition module 301, which is used to acquire multiple first target connections and the execution status of the statements corresponding to each first target connection; wherein the first target connection is used to characterize the connection in use, and the first target connection corresponds to an agent; a processing module 302, which is used to destroy the agent corresponding to the second target connection corresponding to the target statement if the execution status of the target statement meets the target status, and reduce the current value of the counter to obtain the target value; wherein the current value of the counter is used to indicate the number of first target connections, and the target statement is any one of the statements corresponding to each connection; a first determination module 303, which is used to determine the target time corresponding to the target agent if the target value meets the preset value; wherein the target agent is used to indicate the last agent to be destroyed; a second determination module 304, which is used to determine the time difference based on the target time and the current time; a release module 305, which is used to release the first target connection if the time difference is not less than the preset time difference.

[0090] In one possible implementation, the device further includes: a first detection module, which is used to detect whether a proxy corresponding to a connection request exists when a connection request is received; a second detection module, which is used to detect whether a third target connection corresponding to the proxy exists in the connection pool if the proxy corresponding to the connection request exists; and an increase module, which is used to increase the current value of the counter if a third target connection corresponding to the proxy exists in the connection pool.

[0091] In one possible implementation, the device further includes: an initialization module, which is used to initialize the value of the counter corresponding to the third target connection if there is no third target connection corresponding to the proxy in the connection pool; and a creation and increase module, which is used to create the third target connection corresponding to the proxy and increase the value of the counter corresponding to the third target connection.

[0092] In one possible implementation, the device further includes: a load acquisition module, used to acquire the current database load and application requirements; an adjustment module, used to adjust the number of connections in the connection pool according to the current database load and application requirements within a preset time period; wherein the connections in the connection pool are used to characterize unused connections; and / or, a third detection module, used to detect whether the connections in the connection pool meet preset conditions within a preset time period; a first clearing module, used to clear the connections that do not meet the preset conditions if the connections in the connection pool do not meet the preset conditions; and / or, an idle time acquisition module, used to acquire the idle time of the connections in the connection pool within a preset time period; and a second clearing module, used to clear the connections whose idle time exceeds the preset idle time if the idle time of the connections in the connection pool exceeds the preset idle time.

[0093] In a possible implementation, the device further includes: a connection pool destroying module, configured to destroy the connection pool when the target value is zero, the time difference is not less than a preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time.

[0094] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0095] The connection release device in this embodiment is presented in the form of a functional unit, where the functional unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0096] The embodiment of the present invention also provides a computer device having the above Figure 3 Release device for connection shown.

[0097] See also Figure 4 , Figure 4 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 4As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 4 A processor 10 is taken as an example.

[0098] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0099] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0100] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0101] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0102] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0103] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0104] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0105] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for releasing a connection, characterized in that: The method comprises: Acquire multiple first target connections and the execution status of statements corresponding to each first target connection; wherein the first target connection is used to represent a connection in use, and the first target connection corresponds to a proxy; If the execution state of the target statement satisfies the target state, the proxy corresponding to the second target connection corresponding to the target statement is destroyed, and the current value of the counter is reduced to obtain the target value; wherein the current value of the counter is used to indicate the number of the first target connections, and the target statement is any one of the statements corresponding to each connection; If the target value meets the preset value, determine the target time corresponding to the target agent; wherein the target agent is used to indicate the last agent to be destroyed; Determine a time difference based on the target time and the current time; If the time difference is not less than the preset time difference, the first target connection is released.

2. The method for releasing a connection according to claim 1, characterized in that: The method further comprises: In the case of receiving a connection request, detecting whether a proxy corresponding to the connection request exists; If the proxy corresponding to the connection request exists, detecting whether there is a third target connection corresponding to the proxy in the connection pool; If there is a third target connection corresponding to the proxy in the connection pool, the current value of the counter is increased.

3. The method for releasing a connection according to claim 2, characterized in that: The method further comprises: If the third target connection corresponding to the proxy does not exist in the connection pool, initializing the value of the counter corresponding to the third target connection; A third target connection corresponding to the proxy is created, and a value of a counter corresponding to the third target connection is increased.

4. The method for releasing a connection according to claim 1, characterized in that: The method further comprises: Get the current database load and application requirements; Adjusting the number of connections in the connection pool according to the current database load and application requirements within a preset time period; wherein the connections in the connection pool are used to represent unused connections; and / or, Check whether the connections in the connection pool meet the preset conditions within a preset time period; If the connections in the connection pool do not meet the preset conditions, clear the connections that do not meet the preset conditions; and / or, Get the idle time of the connection in the connection pool within a preset time period; If the idle time of the connection in the connection pool exceeds the preset idle time, the connection whose idle time exceeds the preset idle time is cleared.

5. The method for releasing a connection according to claim 4, characterized in that: The method further comprises: When the target value is zero, the time difference is not less than the preset time difference, and the idle time of the connections in the connection pool exceeds the preset idle time, the connection pool is destroyed.

6. A connected release device, characterized in that: The device comprises: An acquisition module, used to acquire multiple first target connections and the execution status of statements corresponding to each first target connection; wherein the first target connection is used to represent a connection in use, and the first target connection corresponds to a proxy; A processing module, configured to, if the execution state of the target statement satisfies the target state, destroy the proxy corresponding to the second target connection corresponding to the target statement, and reduce the current value of the counter to obtain the target value; wherein the current value of the counter is used to indicate the number of the first target connections, and the target statement is any one of the statements corresponding to each connection; A first determination module is used to determine a target time corresponding to a target agent if the target value satisfies a preset value; wherein the target agent is used to indicate the last agent to be destroyed; A second determining module, configured to determine a time difference based on the target time and the current time; The release module is used to release the first target connection if the time difference is not less than a preset time difference.

7. The release device for connection according to claim 6, characterized in that: The device also includes: A first detection module, configured to detect whether a proxy corresponding to a connection request exists when a connection request is received; A second detection module is used to detect whether there is a third target connection corresponding to the proxy in the connection pool if the proxy corresponding to the connection request exists; The increasing module is used to increase the current value of the counter if there is a third target connection corresponding to the proxy in the connection pool.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the connection releasing method according to any one of claims 1 to 5 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the connection releasing method according to any one of claims 1 to 5.

10. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the connection releasing method according to any one of claims 1 to 5.