Database connection pool management method and device, equipment and storage medium
By creating a connection pool with tags and timers for each cluster, the problem of inefficient database connection pool management in distributed systems is solved, and efficient, reliable and flexible connection pool management is achieved, reducing the overhead of connection establishment and disconnection, and improving resource utilization.
Patent Information
- Application Number
- CN202510655084.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-09-02
AI Technical Summary
In the prior art, the management efficiency of database connection pools is low, especially in distributed systems. Due to resource isolation and permission isolation, the connections of each user cannot be placed equally in the same connection pool, the number of connections is large and the parameters are difficult to allocate, resulting in low management efficiency.
By creating a cluster connection pool for each cluster, the cluster connection pool includes multiple connection clusters, and the connection cluster has a first tag and a timer. A database cluster pool is created based on the correspondence between the cluster identity and the cluster connection pool, and the target connection is managed based on the database cluster pool, the first tag and the timer, so as to achieve efficient, reliable and flexible management of the connection.
By pre-allocating and maintaining database connections, the overhead of connection establishment and disconnection is reduced, and unified management of multiple cluster connection pools is realized, the management efficiency and resource utilization of connection pools are improved, and the reasonable allocation and life cycle management of connections is ensured.
Smart Images

Figure CN120578640A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database management technology, and in particular to a management method, apparatus, device, and storage medium for a database connection pool. Background Art
[0002] With the prevalence of distributed system architectures, data is often distributed across multiple locations and stored in multiple clusters. Due to resource and permission isolation requirements, each user's database connection cannot be placed equally in the same connection pool. Therefore, a connection pool is created for each business-specific connection, providing isolated management for each connection pool. However, the large number of connections and the difficulty in configuring connection parameters lead to low management efficiency.
[0003] Therefore, how to improve the management efficiency of the database connection pool is a problem that needs to be solved urgently. Summary of the Invention
[0004] The main purpose of this application is to provide a database connection pool management method, device, equipment and storage medium, aiming to solve the technical problem of low management efficiency of the database connection pool.
[0005] To achieve the above objectives, the present application proposes a method for managing a database connection pool, the method comprising:
[0006] Creating a corresponding cluster connection pool for each cluster according to the cluster parameter information and the cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection has a first tag and a timer;
[0007] Creating a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool;
[0008] The target connection is managed based on the database cluster pool, the first tag, and the timer.
[0009] In one embodiment, managing the target connection based on the database cluster pool, the first tag, and the timer includes:
[0010] In response to a connection request, obtaining a current cluster identifier and a second tag from the connection request, and selecting a target cluster connection pool from a plurality of cluster connection pools according to the current cluster identifier and the database cluster pool;
[0011] Determine whether there is an idle connection in the idle connection pool corresponding to the target cluster connection pool;
[0012] If there are idle connections in the idle connection pool, searching the idle connection pool for a target idle connection that matches the connection request based on the first tag and the second tag;
[0013] If the target idle connection matching the connection request is found, the target idle connection is multiplexed, the connection request is processed through the target idle connection, and the timer of the target idle connection is stopped.
[0014] In one embodiment, after the step of searching the idle connection pool for a target idle connection that matches the connection request based on the first tag and the second tag if the idle connection pool has an idle connection, the method further includes:
[0015] If the target idle connection matching the connection request is not found, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold;
[0016] If the total number of connections in the target cluster connection pool reaches the total connection number threshold, release the head connection in the idle connection pool and reduce the number of active connections in the target cluster connection pool by one;
[0017] Creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer;
[0018] The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
[0019] In one embodiment, after the step of determining whether the total number of connections in the target cluster connection pool reaches the total number of connections threshold, the method further includes:
[0020] If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer;
[0021] The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
[0022] In one embodiment, after determining whether there is an idle connection in the idle connection pool corresponding to the target cluster connection pool, the method further includes:
[0023] If there is no idle connection in the idle connection pool, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold;
[0024] If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer;
[0025] The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
[0026] In one embodiment, after the step of determining whether the target cluster connection pool has reached the maximum number of connections if there are no idle connections in the idle connection pool, the method further includes:
[0027] If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, the connection request is stored in a connection waiting queue;
[0028] Traversing the connection requests in the connection waiting queue from front to back, and determining whether a currently recycled connection matches the connection request based on the first tag and the second tag;
[0029] If the current recycled connection matches the connection request, the current recycled connection is reused and returned to the client.
[0030] In one embodiment, after the step of determining whether the current reclaimed connection matches the connection request based on the first tag and the second tag, the method further includes:
[0031] If the current recycled connection does not match the connection request, returning the current recycled connection to the head request in the connection waiting queue;
[0032] Release the current reclaimed connection and reduce the number of active connections in the target cluster connection pool by one;
[0033] Creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer;
[0034] The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a database connection pool management device, the database connection pool management device comprising:
[0036] A cluster connection pool creation module is used to create a corresponding cluster connection pool for each cluster according to cluster parameter information and cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection has a first tag and a timer;
[0037] A database cluster pool creation module, used to create a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool;
[0038] A target connection management module is configured to manage the target connection based on the database cluster pool, the first tag, and the timer.
[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a database connection pool management device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database connection pool management method as described above.
[0040] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, it implements the steps of the database connection pool management method as described above.
[0041] One or more technical solutions proposed in this application have at least the following technical effects:
[0042] Based on cluster parameter information and cluster configuration information, a corresponding cluster connection pool is created for each cluster. The cluster connection pool includes multiple connection clusters, each containing multiple target connections, each with a first tag and a timer. A database cluster pool is created based on the mapping between cluster identifiers and cluster connection pools. The target connections are managed based on the database cluster pool, first tag, and timer. The cluster connection pool pre-allocates and maintains a certain number of database connections, eliminating the need to create a new connection for each service request, thereby reducing the overhead of establishing and disconnecting connections. A two-level pool facilitates unified management of connection pools across multiple clusters, improving processing efficiency. Assigning tags to each connection upgrades the stateless, peer-to-peer connections of traditional database connection pools to asymmetric, stateful connections, facilitating the subsequent unified management of asymmetric connections based on state. Using first tags and timers to mark and track the usage of each connection helps better manage the connection lifecycle, enabling efficient, reliable, and flexible management of database connection resources and improving connection pool management efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0045] Figure 1 This is a flow chart of the first embodiment of the method for managing a database connection pool of the present application;
[0046] Figure 2 This is a flow chart of a second embodiment of the method for managing a database connection pool of the present application;
[0047] Figure 3 A schematic diagram of a waiting queue creation process in an embodiment of the present application;
[0048] Figure 4 This is a schematic diagram of the waiting connection recovery and reuse process in an embodiment of the present application;
[0049] Figure 5 This is a schematic diagram of the idle connection recovery and reuse process in an embodiment of the present application;
[0050] Figure 6 This is a schematic diagram of the idle connection pool management process in an embodiment of the present application;
[0051] Figure 7 This is a schematic diagram of the module structure of the management device of the database connection pool according to an embodiment of the present application;
[0052] Figure 8 This is a schematic diagram of the device structure of the hardware operating environment involved in the database connection pool management method in the embodiment of the present application.
[0053] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0054] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.
[0055] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0056] Database connection pooling technology generally refers to a technique used to improve system performance by reusing connections to avoid frequent database connection closing and creation when a software process frequently accesses a database and a fixed maximum number of connections is set on the database side. Traditional database connection pooling technology commonly used in the industry typically only maintains a single database connection for a single user within a cluster. However, many large-scale business scenarios today involve large amounts of data distributed across multiple locations and stored separately by multiple clusters. Furthermore, a single cluster often hosts different business operations. This necessitates simultaneous access to multiple databases during software development. Database users are isolated by resource and permission constraints. This isolation prevents all user connections from being placed in the same connection pool. To avoid frequent connection creation, a separate connection pool is required for each business's unique connections. This isolated management of connection pools makes it difficult to adjust connection parameters and manage large numbers of connections uniformly, resulting in reduced software performance.
[0057] Although connections to different databases can be maintained through a connection pool group, a connection pool is actually created for each database connection. The same connection is still stored in the connection pool. Different user connections still require the creation of multiple connection pools. Each connection pool needs to be configured with a different maximum number of connections and maximum number of idle connections. Improper configuration will lead to connection preemption or idle waste between connection pools, which leads to low management efficiency.
[0058] The present application provides a solution, which creates a corresponding cluster connection pool for each cluster based on cluster parameter information and cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, and the connection cluster includes multiple target connections, and the target connection has a first label and a timer; creates a database cluster pool based on the correspondence between the cluster identifier and the cluster connection pool; and manages the target connection based on the database cluster pool, the first label and the timer. Through the cluster connection pool, a certain number of database connections can be pre-allocated and maintained, avoiding the need to create a new connection every time a business request is made, thereby reducing the overhead of connection establishment and disconnection. Through the two-level pool, the connection pools of multiple clusters can be conveniently managed in a unified manner, thereby improving processing efficiency. Assigning a label to each connection is to upgrade the stateless and equal connection of the traditional database connection pool to an asymmetric stateful connection, providing a feasible basis for the subsequent unified management of asymmetric connections based on status. Using the first label and timer to mark and track the usage of each connection helps to better manage the life cycle of the connection, realizes efficient, reliable and flexible management of database connection resources, and improves the efficiency of connection pool management.
[0059] Based on this, the embodiment of the present application provides a method for managing a database connection pool. Figure 1 , Figure 1 This is a flow chart of the first embodiment of the method for managing a database connection pool of the present application.
[0060] In this embodiment, the database connection pool management method includes steps S10 to S40:
[0061] Step S10: creating a corresponding cluster connection pool for each cluster according to the cluster parameter information and cluster configuration information. The cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection carries a first tag and a timer.
[0062] It should be noted that cluster parameter information may include cluster connection information, database name, and user name, and cluster configuration information may include the maximum number of active connections in the connection pool, the maximum number of idle connections in the connection pool, and the maximum idle time of the connection pool. A cluster connection pool may be composed of multiple connection clusters, and a connection cluster may include multiple target connections. A target connection may respond to a connection request, wherein the target connection carries a first tag and a timer. The first tag may be a tag used to identify each connection, or to classify the target connection. Exemplarily, the connection status, connection priority, and application to which the connection belongs may be identified, and the timer may be used to count the idle time of the connection. Exemplarily, the first tag carried by the target connection may be <target database>_<target user>.
[0063] Step S20: Create a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool.
[0064] It should be noted that the cluster identifier may be a cluster number. For example, a hash table may be established according to the mapping relationship between the cluster number and the cluster connection pool to serve as a database cluster pool.
[0065] Step S30: managing the target connection based on the database cluster pool, the first tag, and the timer.
[0066] Exemplarily, based on the database cluster pool, the first tag and the timer, various management operations are performed on the target connection, including but not limited to allocation, recycling, timeout processing and load balancing of the target connection.
[0067] In this embodiment, a certain number of database connections can be pre-allocated and maintained through the cluster connection pool, avoiding the need to create a new connection every time a business request is made, thereby reducing the overhead of establishing and disconnecting connections. Through the two-level pool, the unified entrance of the connection pools of multiple clusters can be conveniently managed in a unified manner to improve processing efficiency. Assigning a label to each connection is to upgrade the stateless and equal connection of the traditional database connection pool to an unequal stateful connection, providing a feasible basis for the subsequent unified management of unequal connections according to the state. Using the first label and timer to mark and track the usage of each connection helps to better manage the life cycle of the connection, realizes efficient, reliable and flexible management of database connection resources, and improves the efficiency of connection pool management.
[0068] Reference Figure 2 , Figure 2 This is a flow chart of the second embodiment of the management method of the database connection pool of this application, based on the above Figure 1 The first embodiment shown provides the second embodiment of the method for managing a database connection pool of the present application.
[0069] In the second embodiment, step S30 includes:
[0070] Step S301 : In response to a connection request, a current cluster identifier and a second tag are obtained from the connection request, and a target cluster connection pool is selected from multiple cluster connection pools according to the current cluster identifier and the database cluster pool.
[0071] It should be noted that the connection request may originate from a client or other service component. The connection request may include the current cluster identifier and a second tag. The current cluster identifier can be used to locate the target database cluster. The target cluster connection pool may be the cluster connection pool that matches the connection request. It is understood that the second tag may also include the current cluster identifier. For example, the second tag may be <database name, user name>.
[0072] Step S302 : Determine whether there is an idle connection in the idle connection pool corresponding to the target cluster connection pool.
[0073] It should be noted that each target cluster connection pool can establish an idle connection pool, which is used to store idle connections. Idle connections can be understood as connections that are not currently used by any client or service component. Correspondingly, the idle connection pool can also be understood as a collection of idle connections.
[0074] Step S303: If there is an idle connection in the idle connection pool, search the idle connection pool for a target idle connection that matches the connection request based on the first tag and the second tag.
[0075] It should be noted that the first tag corresponds to the current connection, and the second tag corresponds to the connection request. By matching the first and second tags, it is possible to determine whether the current connection matches the connection request. The target idle connection can be understood as the idle connection that is most suitable for handling the current connection request based on the matching of the first and second tags.
[0076] Step S304: If a target idle connection matching the connection request is found, the target idle connection is reused, the connection request is processed through the target idle connection, and the timer of the target idle connection is stopped.
[0077] It should be noted that if a target idle connection matching the connection request is found, the target idle connection can be reused instead of creating a new connection to reduce resource consumption. It is understandable that when the target idle connection is reused, it will no longer be idle, so the timer used to count the connection idle time is stopped.
[0078] This embodiment uses tags (first and second tags) to match connection requests with target idle connections, upgrading the stateless, peer-to-peer connections of traditional database connection pools to asymmetric, stateful connections. This allows for more precise connection management, ensuring that each connection is assigned to the most appropriate request, thereby optimizing overall performance and resource allocation. By managing the lifecycle of idle connections through timers and reusing idle connections, the overhead of frequently establishing new connections and closing old ones is reduced, lowering the consumption of memory and network resources.
[0079] In one embodiment, after step S302, the method further includes: if there is no idle connection in the idle connection pool, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold; if the total number of connections in the target cluster connection pool does not reach the total connection number threshold, creating a new target connection in the target cluster connection pool, with a new first tag and a new timer in the new target connection; increasing the number of active connections in the target cluster connection pool by one, and returning the new target connection to the client.
[0080] It should be noted that, in this implementation, if the total number of connections in the target cluster connection pool does not reach the total connection number threshold, the connection request will be stored in the connection waiting queue; the connection requests in the connection waiting queue will be traversed from front to back, and whether the current recycled connection matches the connection request will be determined based on the first label and the second label; if the current recycled connection matches the connection request, the current recycled connection will be reused and the current recycled connection will be returned to the client.
[0081] It should be noted that the total connection number threshold can be the maximum number of connections allowed in the target cluster connection pool, the active connection number is the number of connections in the target cluster connection pool that are being used by clients, the connection waiting queue can be a queue that stores client connection requests that fail to obtain a connection immediately, and the recycled connection can be understood as the connection returned to the target cluster connection pool after being used by the client. The process of the above steps can be referred to Figure 3 For example, a connection waiting queue with status can be designed. When the number of active connections reaches the maximum active connection limit of the cluster connection pool and there are no available connections in the idle connection pool, all connection requests will be placed in the same connection waiting queue of the cluster for waiting, and all used connections will be managed and reused in a unified manner.
[0082] In this embodiment, by designing a connection waiting queue with a status (such as the first label), when the number of active connections reaches the maximum active connection limit of the cluster connection pool and there are no available connections in the idle connection pool, all connection requests will be placed in the same connection waiting queue of the cluster for waiting, and all connections that have ended in use will be uniformly managed and reused, ensuring timely response to waiting requests and avoiding resource waste and long waiting time due to connection pool isolation.
[0083] Based on the above embodiments and implementation methods, and taking into account the problem of determining whether the current recycled connection matches the connection request based on the first tag and the second tag, an implementation method is proposed. Specifically, after the step of determining whether the current recycled connection matches the connection request based on the first tag and the second tag, the method further includes: if the current recycled connection does not match the connection request, returning the current recycled connection to the head request in the connection waiting queue; releasing the current recycled connection and reducing the number of active connections in the target cluster connection pool by one; creating a new target connection in the target cluster connection pool, the new target connection having a new first tag and a new timer; increasing the number of active connections in the target cluster connection pool by one, and returning the new target connection to the client.
[0084] For example, the element of the connection waiting queue is a communication channel with a database name and a user name tag. Based on this connection waiting queue, when the business side has finished using the connection, the connection needs to be recycled, reused, or released. Figure 4The recycling processing strategy shown is that if the connection waiting queue is not empty, in order to give priority to requests with longer waiting times, the connection waiting queue is traversed from front to back, and the <database, user name> carried by the connection request is used to splice into a matching string, which is matched with the label of the connection currently to be recycled. If a waiting request in the queue is matched successfully, the current connection (i.e., the recycled connection) is sent to the waiting request in the waiting queue to wake up its waiting state, the connection is reused, and the connection recycling step ends. If the traversal ends and the match fails, a connection waiting request is taken out from the head of the connection waiting queue, and the current connection (head connection) is sent to the waiting request to wake up its waiting state, and the connection recycling step ends. It can be understood that the waiting request determines that the connection obtained from the channel does not match its own request, and then the connection can be released to create a new connection.
[0085] In this embodiment, when the recovered connection does not match the connection request, by quickly returning the request to the head of the queue and releasing the current connection, the connection demand can be responded to in a timely manner, reducing unnecessary waiting time. By dynamically creating a new target connection and updating the number of active connections, the resource allocation of the connection pool is flexibly adjusted to ensure that the connection pool can meet current business needs. In the connection waiting queue, requests with longer waiting times are given priority to ensure fair allocation of resources and avoid long-term resource occupation by certain low-priority requests. Processing requests from the head of the queue helps to improve response speed and fairness in request processing. In the case of a connection mismatch, a new target connection is dynamically created and a timer is added, which can flexibly expand connection resources according to actual needs. By releasing connections and creating new connections, the system can dynamically adapt to changes in demand for high concurrency or complex business scenarios.
[0086] In one embodiment, after step S303, the method further includes: if no target idle connection matching the connection request is found, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold; if the total number of connections in the target cluster connection pool reaches the total connection number threshold, releasing the head connection of the idle connection pool, and reducing the number of active connections in the target cluster connection pool by one; creating a new target connection in the target cluster connection pool, with a new first tag and a new timer in the new target connection; increasing the number of active connections in the target cluster connection pool by one, and returning the new target connection to the client.
[0087] It should be noted that if the total number of connections in the target cluster connection pool does not reach the total connection number threshold, a new target connection is created in the target cluster connection pool with a new first tag and a new timer; the number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
[0088] For example, referring to step S303, Figure 5As shown, after the client has finished using the connection, the connection needs to be recycled, reused or released. At this time, if the connection waiting queue is empty, it means that there is no connection request waiting, and an attempt is made to put the connection into the idle connection pool. First, check whether the number of connections in the idle connection pool has reached the maximum idle connection limit of the cluster connection pool: if it has reached it, the database connection of the connection pool connection is directly closed, the life cycle of the connection is ended, and the number of active connections in the cluster is reduced by one; if it has not reached it, the timer of the connection pool connection is started, and the connection pool connection is added to the end of the idle connection pool. When the business side needs to obtain a connection again, the parameters <cluster ID, database name, user name> are passed in. The database cluster pool receives the request and obtains the corresponding cluster connection pool according to the cluster ID. The cluster connection pool receives the request. If one or more available idle connections are maintained in its idle connection pool, the processing logic is as follows:
[0089] like Figure 6 As shown, using the <database name, user name> in the connection request parameters as the matching string, the process uses the least recently used (LRU) algorithm, prioritizing the most recently used connections, to loop through the connection list of the idle connection pool in a backward-to-forward order, matching the matching string with the connection tag of each connection. If a match is successful, the loop exits, the connection is removed from the list, the connection timer is stopped, the connection is returned, and the connection is reused. If the match is unsuccessful, two scenarios are handled separately based on the number of active connections in the cluster. The first scenario is when the number of active connections is less than the maximum number of active connections in the cluster. Based on the requested <database name, user name>, a new target connection is created and returned, and the number of active connections in the cluster is incremented by one. The second scenario is when the number of active connections is equal to the maximum number of active connections in the cluster. In this case, an idle connection needs to be eliminated and closed. Based on the LRU algorithm, a connection is removed from the head of the idle connection pool list and released. Then, a new target connection is created and returned based on the requested <database name, user name>.
[0090] In this implementation, by determining whether the idle connection pool has reached the maximum number of idle connections and whether a matching connection exists, idle connections can be reused preferentially, reducing unnecessary connection creation and destruction operations and improving connection pool resource utilization. By determining whether the number of active connections has reached the maximum value, the connection pool resources are prevented from being fully occupied. When the maximum number of active connections is reached, the least used idle connection is promptly released, ensuring that resources can be allocated for new connection requests and avoiding connection request blocking or failure. Through connection pool management and the LRU elimination mechanism, the rational release and allocation of resources is controlled. By dynamically adjusting the connection status, multi-level connection management is achieved, improving the flexibility of the connection pool.
[0091] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the management method of the database connection pool of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0092] This application also provides a database connection pool management device, please refer to Figure 7 , the management device of the database connection pool includes:
[0093] A cluster connection pool creation module 10 is configured to create a corresponding cluster connection pool for each cluster based on cluster parameter information and cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection has a first tag and a timer.
[0094] A database cluster pool creation module 20 is used to create a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool;
[0095] The target connection management module 30 is configured to manage the target connection based on the database cluster pool, the first tag, and the timer.
[0096] The database connection pool management device provided in this application, which utilizes the database connection pool management method of the aforementioned embodiment, can resolve the technical problem of low database connection pool management efficiency. Compared with the prior art, the beneficial effects of the database connection pool management device provided in this application are the same as those of the database connection pool management method provided in the aforementioned embodiment. Other technical features of the database connection pool management device are the same as those disclosed in the aforementioned embodiment and are not further described here.
[0097] The present application provides a database connection pool management device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the database connection pool management method in the above-mentioned embodiment 1.
[0098] Reference below Figure 8, which shows a schematic diagram of the structure of a database connection pool management device suitable for implementing an embodiment of the present application. The database connection pool management device in the embodiment of the present application can include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 8 The management device of the database connection pool shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0099] like Figure 8 As shown, the database connection pool management device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. Various programs and data required for the operation of the database connection pool management device are also stored in RAM 1004. The processing device 1001, ROM 1002, and RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication devices 1009 can allow the management device of the database connection pool to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 The management device of the database connection pool with various systems is shown, but it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.
[0100] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0101] The database connection pool management device provided in this application, which utilizes the database connection pool management method of the above-described embodiment, can solve the technical problem of low database connection pool management efficiency. Compared with the prior art, the beneficial effects of the database connection pool management device provided in this application are the same as those of the database connection pool management method provided in the above-described embodiment. Other technical features of the database connection pool management device are the same as those disclosed in the above-described embodiment and are not further described here.
[0102] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0103] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0104] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, wherein the computer-readable program instructions are used to execute the database connection pool management method in the above-mentioned embodiment.
[0105] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0106] The computer-readable storage medium may be included in the management device of the database connection pool; or may exist independently without being assembled into the management device of the database connection pool.
[0107] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the management device of the database connection pool, the management device of the database connection pool: creates a corresponding cluster connection pool for each cluster according to cluster parameter information and cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, and the connection cluster includes multiple target connections, and the target connections have a first label and a timer; creates a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool; and manages the target connection based on the database cluster pool, the first label and the timer.
[0108] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0109] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0110] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.
[0111] The computer-readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned database connection pool management method, thereby resolving the technical issue of inefficient database connection pool management. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the database connection pool management method provided in the aforementioned embodiments, and are not further elaborated upon herein.
[0112] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for managing a database connection pool, characterized in that: The method includes: Creating a corresponding cluster connection pool for each cluster according to the cluster parameter information and the cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection has a first tag and a timer; Creating a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool; The target connection is managed based on the database cluster pool, the first tag, and the timer.
2. The method for managing a database connection pool according to claim 1, wherein: The managing the target connection based on the database cluster pool, the first tag, and the timer includes: In response to a connection request, obtaining a current cluster identifier and a second tag from the connection request, and selecting a target cluster connection pool from a plurality of cluster connection pools according to the current cluster identifier and the database cluster pool; Determine whether there is an idle connection in the idle connection pool corresponding to the target cluster connection pool; If there are idle connections in the idle connection pool, searching the idle connection pool for a target idle connection that matches the connection request based on the first tag and the second tag; If the target idle connection matching the connection request is found, the target idle connection is multiplexed, the connection request is processed through the target idle connection, and the timer of the target idle connection is stopped.
3. The method for managing a database connection pool according to claim 2, wherein: After the step of searching the idle connection pool for a target idle connection that matches the connection request based on the first tag and the second tag if the idle connection pool has an idle connection, the method further includes: If the target idle connection matching the connection request is not found, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold; If the total number of connections in the target cluster connection pool reaches the total connection number threshold, release the head connection in the idle connection pool and reduce the number of active connections in the target cluster connection pool by one; Creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer; The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
4. The method for managing a database connection pool according to claim 3, wherein: After the step of determining whether the total number of connections in the target cluster connection pool reaches the total number of connections threshold, the method further includes: If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer; The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
5. The method for managing a database connection pool according to claim 2, wherein: After determining whether there is an idle connection in the idle connection pool corresponding to the target cluster connection pool, the method further includes: If there is no idle connection in the idle connection pool, determining whether the total number of connections in the target cluster connection pool reaches a total connection number threshold; If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer; The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
6. The method for managing a database connection pool according to claim 5, wherein: After the step of determining whether the target cluster connection pool has reached the maximum number of connections if there are no idle connections in the idle connection pool, the method further includes: If the total number of connections in the target cluster connection pool does not reach the total connection number threshold, the connection request is stored in a connection waiting queue; Traversing the connection requests in the connection waiting queue from front to back, and determining whether a currently recycled connection matches the connection request based on the first tag and the second tag; If the current recycled connection matches the connection request, the current recycled connection is reused and returned to the client.
7. The method for managing a database connection pool according to claim 6, wherein: After the step of determining whether the current reclaimed connection matches the connection request according to the first tag and the second tag, the method further includes: If the current recycled connection does not match the connection request, returning the current recycled connection to the head request in the connection waiting queue; Release the current reclaimed connection and reduce the number of active connections in the target cluster connection pool by one; Creating a new target connection in the target cluster connection pool, wherein the new target connection has a new first tag and a new timer; The number of active connections in the target cluster connection pool is increased by one, and the new target connection is returned to the client.
8. A database connection pool management device, characterized in that: The device comprises: A cluster connection pool creation module is used to create a corresponding cluster connection pool for each cluster according to cluster parameter information and cluster configuration information, wherein the cluster connection pool includes multiple connection clusters, each connection cluster includes multiple target connections, and each target connection has a first tag and a timer; A database cluster pool creation module, used to create a database cluster pool according to the correspondence between the cluster identifier and the cluster connection pool; A target connection management module is configured to manage the target connection based on the database cluster pool, the first tag, and the timer.
9. A database connection pool management device, characterized in that: The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the method for managing a database connection pool according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the method for managing a database connection pool according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Micro-service connection pool and method for establishing connection between micro-service connection pool and database cluster
CN118312569A
Data processing method and device, computer equipment and program product
CN118861142A
Cited By
Cloud mobile phone starting method and device, storage medium and electronic equipment
CN121284016A
Database connection pool management method and device based on DataX
CN121560862A
A database connection control method and device based on a dynamic threshold and a medium
CN122388024A