CN109800261B - Dynamic control method and device for double-database connection pool and related equipment - Google Patents

Dynamic control method and device for double-database connection pool and related equipment Download PDF

Info

Publication number
CN109800261B
CN109800261B CN201811537696.6A CN201811537696A CN109800261B CN 109800261 B CN109800261 B CN 109800261B CN 201811537696 A CN201811537696 A CN 201811537696A CN 109800261 B CN109800261 B CN 109800261B
Authority
CN
China
Prior art keywords
database connection
connection pool
database
pool
utilization rate
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811537696.6A
Other languages
Chinese (zh)
Other versions
CN109800261A (en
Inventor
陈东杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN201811537696.6A priority Critical patent/CN109800261B/en
Publication of CN109800261A publication Critical patent/CN109800261A/en
Application granted granted Critical
Publication of CN109800261B publication Critical patent/CN109800261B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

A dynamic control method for a dual database connection pool, comprising: creating a first database connection pool and a second database connection pool, and initializing the maximum database connection number of the first database connection pool; when receiving a database connection request of an application program, calculating the current utilization rate of a first database connection pool; judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value or not; when the database connection is determined to be less than or equal to the first database connection pool, the available database connection is distributed to the application program; when determined to be greater than, a temporary database connection is created through the second database connection pool and assigned to the application. The invention also provides a dynamic control device, computer equipment and a storage medium of the double-database connection pool. According to the method and the device, the database connection can be dynamically adjusted by using the double database connection pools through cloud monitoring, so that the user request can be responded in time, and the database resources can be furthest used.

Description

Dynamic control method and device for double-database connection pool and related equipment
Technical Field
The invention relates to the technical field of computers, in particular to a dynamic control method and device for a double-database connection pool, computer equipment and a storage medium.
Background
Database connectivity is a critical, limited, expensive resource that is particularly apparent in multi-user web applications. When concurrent users are large, many identical connections will be repeatedly opened and closed, wasting a lot of system resources of the database, reducing access efficiency. Management of database connections can significantly impact the scalability and robustness of the overall application, affecting the performance index of the program.
Database connection pools are being proposed to address this problem. The database connection pool is responsible for allocating, managing and releasing database connections, which allows applications to reuse an existing database connection rather than reestablish one; releasing the database connection with the idle time exceeding the maximum idle time to avoid the database connection omission caused by the absence of releasing the database connection. This technique can significantly improve the performance of database operations.
However, in the existing database connection pool technology, a fixed maximum number of database connections is usually set, and the number of requested database connections is controlled within the maximum number of database connections. If the set maximum database connection number is smaller, the request connection number is more, which can seriously affect the use experience of the user and cause the user to wait for a long time. If the set maximum database connection number is larger, the system database resources are seriously occupied, so that the system operation is unstable.
Disclosure of Invention
In view of the foregoing, it is necessary to provide a method, an apparatus and a related device for dynamically controlling a dual database connection pool, which can dynamically adjust database connection using the dual database connection pool, and dynamically adjust temporary database connection according to the number of requests of a user when the user requests change, so that the user requests can be responded in time, abnormal situations caused by excessively long waiting time of the user can be avoided, and database resources can be used to the maximum extent.
A first aspect of the present invention provides a method for dynamically controlling a dual database connection pool, the method comprising:
creating a first database connection pool and a second database connection pool, and initializing the maximum database connection number of the first database connection pool;
when receiving a database connection request of an application program, calculating the current utilization rate of the first database connection pool;
judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value or not;
when the current utilization rate of the first database connection pool is less than or equal to the utilization rate threshold value of the preset database connection pool, distributing available database connection to the application program through the first database connection pool;
And when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, creating temporary database connection through the second database connection pool and distributing the temporary database connection to the application program.
According to a preferred embodiment of the present invention, said creating a temporary database connection through said second database connection pool and assigning to said application program comprises:
acquiring the request connection number of the application program;
creating a temporary database connection corresponding to the requested connection number through a second database connection pool;
and distributing the temporary database connection to the application program.
According to a preferred embodiment of the invention, after said creating of temporary database connections through said second database connection pool and assigning to said application, said method further comprises:
releasing the temporary database connection in the second database connection pool when the application program finishes using the temporary database connection; or alternatively
And when the application program finishes using the temporary database connection, releasing the temporary database connection in the second database connection pool after a preset time period.
According to a preferred embodiment of the present invention, when the database connection request of the application program is received, calculating the current usage rate of the first database connection pool includes:
when receiving a database connection request of the application program, acquiring the number of database connections currently used in the first database connection pool;
and calculating the current utilization rate of the first database connection pool according to the current database connection number and the initialized maximum database connection number of the first database connection pool.
According to a preferred embodiment of the present invention, when the determining that the current usage of the first database connection pool is greater than the preset database connection pool usage threshold, the method further includes:
judging whether the current utilization rate of the first database connection pool meets a preset alarm condition or not;
and if the current utilization rate of the first database connection pool meets the preset alarm condition, alarming.
According to a preferred embodiment of the present invention, the preset alarm condition includes:
and the current utilization rate of the first database connection pool exceeds a preset ratio of the contemporaneous utilization rate.
According to a preferred embodiment of the present invention, initializing the maximum database connection number of the first database connection pool includes:
Acquiring initial configuration in a system configuration file;
and determining the initial database connection number in the initial configuration file as the maximum database connection number in the first database connection pool.
A second aspect of the present invention provides a dynamic control apparatus for a dual database connection pool, the apparatus comprising:
the creation module is used for creating a first database connection pool and a second database connection pool and initializing the maximum database connection number of the first database connection pool;
the computing module is used for computing the current utilization rate of the first database connection pool when receiving a database connection request of an application program;
the judging module is used for judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value;
the first allocation module is used for allocating available database connection to the application program through the first database connection pool when the judging module judges that the current utilization rate of the first database connection pool is smaller than or equal to the preset database connection pool utilization rate threshold;
and the second allocation module is used for creating temporary database connection through the second database connection pool and allocating the temporary database connection to the application program when the judging module judges that the current utilization rate of the first database connection pool is greater than the utilization rate threshold of the preset database connection pool.
A third aspect of the present invention provides a computer device comprising a processor and a memory, the processor being adapted to implement the method of dynamic control of the dual database connection pool when executing a computer program stored in the memory.
A fourth aspect of the present invention provides a computer readable storage medium having a computer program stored thereon, which when executed by a processor implements the method for dynamic control of a dual database connection pool.
The embodiment of the invention provides a dynamic control method, a dynamic control device, computer equipment and a storage medium for double-database connection pools, wherein a first database connection pool and a second database connection pool are pre-established, and the maximum database connection number of the first database connection pool is initialized; when a database connection request of an application program is received, calculating the current utilization rate of the first database connection pool; when the calculated current utilization rate of the first database connection pool is smaller than or equal to a preset database connection pool utilization rate threshold value, directly distributing available database connection to the application program through the first database connection pool; and when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, creating a temporary database connection through the second database connection pool and distributing the temporary database connection to the application program. The maximum database connection number can be initialized according to the configuration of the system, so that the normal operation of the system can be ensured, and the system resources can be furthest used. When the user request changes, the temporary database connection can be dynamically adjusted according to the number of the user request, so that the user request is responded in time, and the abnormal occurrence caused by overlong waiting time of the user is avoided.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for dynamically controlling a dual database connection pool according to an embodiment of the present invention.
Fig. 2 is a functional block diagram of a dynamic control device for a dual database connection pool according to a second embodiment of the present invention.
Fig. 3 is a schematic diagram of a computer device according to a third embodiment of the present invention.
The invention will be further described in the following detailed description in conjunction with the above-described figures.
Detailed Description
In order that the above-recited objects, features and advantages of the present invention will be more clearly understood, a more particular description of the invention will be rendered by reference to specific embodiments thereof which are illustrated in the appended drawings. It should be noted that, without conflict, the embodiments of the present invention and features in the embodiments may be combined with each other.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, and the described embodiments are merely some, rather than all, embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The dynamic control method of the double-database connection pool in the embodiment of the invention is applied to computer equipment, and can also be applied to a hardware environment formed by the computer equipment and a server connected with the computer equipment through a network, and the dynamic control method is executed by the server and the computer equipment together. Networks include, but are not limited to: a wide area network, a metropolitan area network, or a local area network.
The computer equipment can be desktop computers, notebooks, palm computers, cloud servers and other computer equipment.
The computer equipment which needs to perform the dynamic control method of the double-database connection pool can directly integrate the dynamic control function of the double-database connection pool provided by the method of the invention on the computer equipment or install a client for realizing the method of the invention. For another example, the method provided by the invention can also be operated on computer equipment such as a server in the form of a software development kit (Software Development Kit, SDK), an interface for the dynamic control function of the double-database connection pool is provided in the form of the SDK, and the server or other computer equipment can realize the dynamic control function of the double-database connection pool through the provided interface.
Before describing embodiments of the present invention, the following terms referred to in the embodiments of the present invention will be explained:
database: software systems and their data for permanent or temporary storage of business data, system data, including but not limited to Oracle, mySQL, SQLServer, tair, oceanBase, etc.
Database connection: when an application interacts with a database, a channel, called a database connection, needs to be established according to a certain communication protocol.
Database connection pool: when the system is initialized, the database connection is stored in the memory as an object, and when an application program requests to access the database, a new database connection is not established, but an established idle connection object is taken out of a database connection pool. When the application program is used, the database connection is not closed, but is put back into the connection pool for the next request access.
Example 1
Fig. 1 is a schematic diagram of a dynamic control method for a dual-database connection pool according to a first embodiment of the present invention, where the dynamic control method for a dual-database connection pool monitors a current database connection pool index of a computer device, and dynamically controls the dual-database connection pool according to a monitored usage rate of the database connection pool. The order of execution in the flow chart may be changed, and certain steps may be omitted, according to different needs.
S11: creating a first database connection pool and a second database connection pool, and initializing a maximum database connection number of the first database connection pool.
In this embodiment, after the application server is started, two database connection pools may be created, where the first database connection pool may be used as a common database connection pool, and the second database connection pool may be used as a temporary database connection pool. The number of database connections created in a common pool of database connections is fixed, i.e. once a database connection is created, whether or not the database connection is occupied by an application, it will be present in the first pool of database connections until the application server is closed. For the temporary database connection pool, the number of database connections in the initial pool is zero, i.e., no database connections are created. And when the database connection in the common database connection pool cannot meet the requirement, creating the database connection number in the second database connection pool. Thus, the number of database connections in the second database connection pool is dynamically changing.
Specifically, initializing the maximum database connection number of the first database connection pool may include: acquiring initial configuration in a system configuration file, and determining the initial database connection number in the initial configuration file as the maximum database connection number in the first database connection pool.
The system in this embodiment is a computer system, which is composed of two parts, namely computer hardware and software. The hardware part may include a central processing unit, a memory, an external device, etc., and the software part may be various application programs and corresponding documents running on the computer. The computer system can receive and store information, quickly calculate and judge according to programs, and output processing results. The configuration files are typically stored on a local hard drive of the system, and may typically include a set of settings and files when the user uses the system, and so on.
The configuration files in this embodiment may include an initial configuration file and an intermediate configuration file, where the initial configuration file may be a file preset by the system in a development stage, and the intermediate configuration file may be a history file generated after the system operates for a period of time. The initial configuration file stores a preset initial database connection number, wherein the initial database connection number can be a reasonable value which is determined by a developer according to the hardware configuration of the system and can be carried by the system, namely, the concurrent request number which can be processed simultaneously at the same time. Thus, the initial database connection number in the initial configuration file can be extracted as the current maximum database connection number of the system.
S12: and when receiving a database connection request of an application program, calculating the current utilization rate of the first database connection pool.
In this embodiment, when the database connection request of the application program is received, calculating the current usage rate of the first database connection pool may include:
when receiving a database connection request of the application program, acquiring the number of database connections currently used in a first database connection pool;
and calculating the current utilization rate of the first database connection pool according to the current database connection number and the initialized maximum database connection number of the first database connection pool.
When an application needs to perform a database operation, a database connection may be applied to the system. And when the system receives the database connection request of the application program, calculating the current utilization rate of the first database connection pool.
The specific calculation formula is as follows:
the current usage of the first database connection pool= (the number of database connections used in the current first database connection pool/the maximum number of database connections of the first database connection pool) ×100%.
S13: judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value.
In this embodiment, the preset database connection pool usage rate threshold is a preset threshold value of the maximum database connection number used by the database connection pool, which is an optimal value capable of ensuring normal and stable operation of the system, so that the database resources can be used to the maximum extent, and the system is not blocked. Illustratively, the preset database connection pool usage threshold is 80%.
And when judging that the current utilization rate of the first database connection pool is smaller than or equal to the preset database connection pool utilization rate threshold value, executing S14. And when judging that the current utilization rate of the first database connection pool is greater than the preset database connection pool utilization rate threshold, executing S15.
S14: the available database connections are allocated to the application program via a first database connection pool.
In this embodiment, when it is determined that the current usage rate of the first database connection pool is less than or equal to the preset database connection pool usage rate threshold, it is indicated that there is still an available database connection in the first database connection pool, and the available database connection may be allocated to an application program that requests the database connection.
Judging whether the application program in the first database connection pool is available or not by judging whether the database connection in the first database connection pool is occupied by the application program or not, and considering that the occupied database connection is in a busy state and can not be used by other application programs any more when the database connection is occupied by the application program; when the database connection is not occupied by the application program, the unoccupied database connection is considered to be in an idle state and can be distributed to other application programs for use.
S15: a temporary database connection is created through the second database connection pool and assigned to the application.
And when judging that the current utilization rate of the first database connection pool is larger than the utilization rate threshold value of the preset database connection pool, indicating that the first database connection pool is close to or reaches a full load state, and connecting the non-redistributable database to an application program requesting the database connection. At this time, a temporary database connection may be created through the second database connection pool, and the created temporary database connection may be allocated to an application program requesting the database connection.
Further, the creating a temporary database connection through the second database connection pool and allocating to the application program may further include:
acquiring the request connection number of the application program;
creating a temporary database connection corresponding to the requested connection number through a second database connection pool;
and distributing the temporary database connection to the application program.
In this embodiment, the database connection request of the application program carries a request connection number, and a corresponding temporary database connection is created according to the request connection number. By way of example, if the number of requested connections for an application is 3, then 3 temporary database connections are created via the second database and assigned to the application.
Further, after the creating of the temporary database connection through the second database connection pool and the allocation to the application program, the dynamic control method of the dual database connection pool may further include:
when the application program finishes using the temporary database connection, releasing the temporary database connection in a second database connection pool; or alternatively
And when the application program finishes using the temporary database connection, releasing the temporary database connection in the second database connection pool after a preset time period.
When there is a connection request, temporary database connections are created through the second database connection pool, and when these temporary database connections are used up, the temporary database connections are released. The method can ensure that the request is responded quickly, can also be released in time after the temporary database is connected, ensures that the system database resources are saved to the greatest extent, and prevents the system breakdown caused by unlimited resource allocation.
Releasing the database connection in the second database connection pool after a preset time period, namely releasing the newly-built temporary connection immediately after the use is not finished, and distributing the temporary database connection to an application program of a new database connection request if a new database connection request arrives in the preset time period, so that frequent creation and release of the temporary database connection by the second database are avoided, and system resources are wasted.
Further, the dynamic control method of the dual database connection pool may further include: and acquiring the current utilization rate of the first database connection pool every preset time period.
The current usage rate of the first database connection pool may be periodically obtained, for example, the current usage rate of the first database connection pool may be obtained every 5 minutes, before the current usage rate of the first database connection pool is obtained, whether the first database connection pool currently has occupied database connection may be detected, and if so, the current usage rate of the first database connection pool may be obtained; if not, the next cycle is awaited.
In the embodiment of the invention, the specific time of the period is not limited, and can be set according to actual requirements when the period is specifically realized. The reasonable period duration is set, so that the problem that the system work is influenced by frequently creating or destroying database connection can be avoided.
Further, when the current usage rate of the first database connection pool is determined to be greater than the preset database connection pool usage rate threshold, the dynamic control method of the dual database connection pool may further include: judging whether the current utilization rate of the first database connection pool meets a preset alarm condition or not; and if the current utilization rate of the first database connection pool meets the preset alarm condition, alarming.
In some embodiments, the predetermined alert condition may be that the database connection usage is greater than a predetermined database connection pool usage threshold. When the current utilization rate of the first database connection pool is determined to be greater than the utilization rate threshold value of the preset database connection pool, an alarm condition is considered to be met, and an alarm is carried out; and when the current utilization rate of the first database connection pool is less than or equal to the utilization rate threshold value of the preset database connection pool, the alarm condition is not met, and no alarm is carried out.
Current usage of database connection pool= (current database connection number/maximum database connection number) ×100%.
Since the number of application connectable databases is limited, it is controllable by the profile parameters. The highest database connection pool utilization rate critical value is preset, the database connection pool utilization rate is monitored in real time, and an alarm is needed when the database connection pool utilization rate is higher than the highest database connection pool utilization rate critical value, and particularly when the database connection pool utilization rate tends to 100%. The use ratio of the database connection pool is too high, which indicates that the number of database connections is too large, and the operation and maintenance are needed to be applied to intervening processing in time, so that the situation that the system is abnormal due to too high number of database connections and too fast service growth is avoided.
In some embodiments, the preset alarm condition may be that the current usage rate of the first database connection pool is compared with contemporaneous data, and whether to alarm is determined according to the comparison result. For example, the current usage of the first database connection pool obtained by monday 10:00 am is compared with monday 10 am: and (3) comparing the utilization rate of the first database connection pool obtained by 00, and if the current utilization rate of the first database connection pool obtained by 10:00 am exceeds 10 am in monday: and (3) alarming if the usage rate of the first database connection pool obtained by 00 is 20%.
The current running state of the system can be determined by comparing the utilization rates of the first database connection pools, and generally, if no major accident occurs, the utilization rates of the database connection pools of the system should be kept in a stable state, and if the current utilization rates of the first database connection pools exceed the utilization rates in the same period, the system is considered to have an abnormality at present, and a developer needs to be reminded of detection.
The alarm can be given by sending out alarm sound, displaying an alarm picture, sending an alarm message, sending an alarm mail and the like.
In summary, in the method for dynamically controlling the dual database connection pool according to the first embodiment of the present invention, the first database connection pool and the second database connection pool may be created in advance, and the maximum database connection number of the first database connection pool may be initialized; when a database connection request of an application program is received, calculating the current utilization rate of the first database connection pool; when the calculated current utilization rate of the first database connection pool is smaller than or equal to a preset database connection pool utilization rate threshold value, directly distributing available database connection to the application program through the first database connection pool; and when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, creating a temporary database connection through the second database connection pool and distributing the temporary database connection to the application program. The maximum database connection number can be initialized according to the configuration of the system, so that the normal operation of the system can be ensured, and the system resources can be furthest used. When the user request changes, the temporary database connection can be dynamically adjusted according to the number of the user request, so that the user request is responded in time, and the abnormal occurrence caused by overlong waiting time of the user is avoided.
Secondly, in the mode that the database connection is managed through the connection pool, when a user needs to perform database operation, a connection is applied from the connection pool, and after the database operation is finished, the connection is immediately released into the connection pool for other users to use. Thus, the use efficiency of the database connection is greatly improved, a large number of users can share fewer database connections, and the time for establishing the connection is saved. And after the database connection in the second database connection pool is used up, the database connection is released after a preset time period, so that the cost of releasing the database connection can be effectively reduced, and the situation that new connection is re-established after the connection is just released is avoided, and the system resource is not wasted due to frequent establishment of the released database connection.
While the invention has been described with reference to specific embodiments, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention.
The functional modules and hardware structures of the computer device for implementing the dynamic control method of the dual database connection pool are described below with reference to fig. 2 to 3.
Example two
FIG. 2 is a functional block diagram of a dynamic control device for a dual database connection pool according to a preferred embodiment of the present invention.
In some embodiments, the dynamic control device 20 of the dual database connection pool is running in a computer device. The dynamic control device 20 of the dual database connection pool monitors the current database connection pool index of the computer equipment, and dynamically controls the dual database connection pool according to the monitored database connection pool utilization rate. The dynamic control device 20 of the dual database connection pool may comprise a plurality of functional modules consisting of program code segments. Program code for each program segment in the dual database connection pool dynamic control apparatus 20 may be stored in a memory and executed by at least one processor.
In this embodiment, the dynamic control device 20 of the dual database connection pool may be divided into a plurality of functional modules according to the functions performed by the dynamic control device. The functional module may include: the system comprises a creation module 201, a calculation module 202, a judgment module 203, a first distribution module 204, a second distribution module 205, a release module 206, an acquisition module 207 and an alarm module 208. The module referred to in the present invention refers to a series of computer program segments capable of being executed by at least one processor and of performing a fixed function, stored in a memory. In some embodiments, the function of each module will be described in detail in the following embodiments.
A creating module 201, configured to create a first database connection pool and a second database connection pool, and initialize a maximum database connection number of the first database connection pool.
In this embodiment, after the application server is started, two database connection pools may be created, where the first database connection pool may be used as a common database connection pool, and the second database connection pool may be used as a temporary database connection pool. The number of database connections created in a common pool of database connections is fixed, i.e. once a database connection is created, whether or not the database connection is occupied by an application, it will be present in the first pool of database connections until the application server is closed. For the temporary database connection pool, the number of database connections in the initial pool is zero, i.e., no database connections are created. And when the database connection in the common database connection pool cannot meet the requirement, creating the database connection number in the second database connection pool. Thus, the number of database connections in the second database connection pool is dynamically changing.
Specifically, initializing the maximum database connection number of the first database connection pool may include: acquiring initial configuration in a system configuration file, and determining the initial database connection number in the initial configuration file as the maximum database connection number in the first database connection pool.
The system in this embodiment is a computer system, which is composed of two parts, namely computer hardware and software. The hardware part may include a central processing unit, a memory, an external device, etc., and the software part may be various application programs and corresponding documents running on the computer. The computer system can receive and store information, quickly calculate and judge according to programs, and output processing results. The configuration files are typically stored on a local hard drive of the system, and may typically include a set of settings and files when the user uses the system, and so on.
The configuration files in this embodiment may include an initial configuration file and an intermediate configuration file, where the initial configuration file may be a file preset by the system in a development stage, and the intermediate configuration file may be a history file generated after the system operates for a period of time. The initial configuration file stores a preset initial database connection number, wherein the initial database connection number can be a reasonable value which is determined by a developer according to the hardware configuration of the system and can be carried by the system, namely, the concurrent request number which can be processed simultaneously at the same time. Thus, the initial database connection number in the initial configuration file can be extracted as the current maximum database connection number of the system.
The calculating module 202 is configured to calculate a current usage rate of the first database connection pool when receiving a database connection request of an application program.
In this embodiment, when the computing module 202 receives a database connection request of an application program, computing the current usage rate of the first database connection pool may include:
when receiving a database connection request of the application program, acquiring the number of database connections currently used in a first database connection pool;
and calculating the current utilization rate of the first database connection pool according to the current database connection number and the initialized maximum database connection number of the first database connection pool.
When an application needs to perform a database operation, a database connection may be applied to the system. And when the system receives the database connection request of the application program, calculating the current utilization rate of the first database connection pool.
The specific calculation formula is as follows:
the current usage of the first database connection pool= (the number of database connections used in the current first database connection pool/the maximum number of database connections of the first database connection pool) ×100%.
And the judging module 203 is configured to judge whether the current usage rate of the first database connection pool is greater than a preset database connection pool usage rate threshold.
In this embodiment, the preset database connection pool usage rate threshold is a preset threshold value of the maximum database connection number used by the database connection pool, which is an optimal value capable of ensuring normal and stable operation of the system, so that the database resources can be used to the maximum extent, and the system is not blocked. Illustratively, the preset database connection pool usage threshold is 80%.
And the first allocation module 204 is configured to allocate the available database connection to the application program through the first database connection pool when the determining module 203 determines that the current usage rate of the first database connection pool is less than or equal to the preset database connection pool usage rate threshold.
In this embodiment, when it is determined that the current usage rate of the first database connection pool is less than or equal to the preset database connection pool usage rate threshold, it is indicated that there is still an available database connection in the first database connection pool, and the available database connection may be allocated to an application program that requests the database connection.
Judging whether the application program in the first database connection pool is available or not by judging whether the database connection in the first database connection pool is occupied by the application program or not, and considering that the occupied database connection is in a busy state and can not be used by other application programs any more when the database connection is occupied by the application program; when the database connection is not occupied by the application program, the unoccupied database connection is considered to be in an idle state and can be distributed to other application programs for use.
And the second allocation module 205 is configured to create a temporary database connection through the second database connection pool and allocate the temporary database connection to the application program when the determination module 203 determines that the current usage rate of the first database connection pool is greater than the preset database connection pool usage rate threshold.
And when judging that the current utilization rate of the first database connection pool is larger than the utilization rate threshold value of the preset database connection pool, indicating that the first database connection pool is close to or reaches a full load state, and connecting the non-redistributable database to an application program requesting the database connection. At this time, a temporary database connection may be created through the second database connection pool, and the created temporary database connection may be allocated to an application program requesting the database connection.
Further, the second allocation module 205 creating a temporary database connection through the second database connection pool and allocating to the application program may further include:
acquiring the request connection number of the application program;
creating a temporary database connection corresponding to the requested connection number through a second database connection pool;
and distributing the temporary database connection to the application program.
In this embodiment, the database connection request of the application program carries a request connection number, and a corresponding temporary database connection is created according to the request connection number. By way of example, if the number of requested connections for an application is 3, then 3 temporary database connections are created via the second database and assigned to the application.
Still further, after the second allocation module 205 creates a temporary database connection through the second database connection pool and allocates the temporary database connection to the application program, the dynamic control apparatus 20 for a dual database connection pool may further include: a release module 206 for
When the application program finishes using the temporary database connection, releasing the temporary database connection in a second database connection pool; or alternatively
And when the application program finishes using the temporary database connection, releasing the temporary database connection in the second database connection pool after a preset time period.
When there is a connection request, temporary database connections are created through the second database connection pool, and when these temporary database connections are used up, the temporary database connections are released. The method can ensure that the request is responded quickly, can also be released in time after the temporary database is connected, ensures that the system database resources are saved to the greatest extent, and prevents the system breakdown caused by unlimited resource allocation.
Releasing the database connection in the second database connection pool after a preset time period, namely releasing the newly-built temporary connection immediately after the use is not finished, and distributing the temporary database connection to an application program of a new database connection request if a new database connection request arrives in the preset time period, so that frequent creation and release of the temporary database connection by the second database are avoided, and system resources are wasted.
Further, the dynamic control device 20 of the dual database connection pool may further include: an obtaining module 207, configured to obtain the current usage rate of the first database connection pool at intervals of a preset time period.
The current usage rate of the first database connection pool may be periodically obtained, for example, the current usage rate of the first database connection pool may be obtained every 5 minutes, before the current usage rate of the first database connection pool is obtained, whether the first database connection pool currently has occupied database connection may be detected, and if so, the current usage rate of the first database connection pool may be obtained; if not, the next cycle is awaited.
In the embodiment of the invention, the specific time of the period is not limited, and can be set according to actual requirements when the period is specifically realized. The reasonable period duration is set, so that the problem that the system work is influenced by frequently creating or destroying database connection can be avoided.
Further, when it is determined that the current usage rate of the first database connection pool is greater than the preset database connection pool usage rate threshold, the dynamic control device 20 for dual database connection pools may further include: an alarm module 208, configured to determine whether a current usage rate of the first database connection pool meets a preset alarm condition; and if the current utilization rate of the first database connection pool meets the preset alarm condition, alarming.
In some embodiments, the predetermined alert condition may be that the database connection usage is greater than a predetermined database connection pool usage threshold. When the current utilization rate of the first database connection pool is determined to be greater than the utilization rate threshold value of the preset database connection pool, an alarm condition is considered to be met, and an alarm is carried out; and when the current utilization rate of the first database connection pool is less than or equal to the utilization rate threshold value of the preset database connection pool, the alarm condition is not met, and no alarm is carried out.
Current usage of database connection pool= (current database connection number/maximum database connection number) ×100%.
Since the number of application connectable databases is limited, it is controllable by the profile parameters. The highest database connection pool utilization rate critical value is preset, the database connection pool utilization rate is monitored in real time, and an alarm is needed when the database connection pool utilization rate is higher than the highest database connection pool utilization rate critical value, and particularly when the database connection pool utilization rate tends to 100%. The use ratio of the database connection pool is too high, which indicates that the number of database connections is too large, and the operation and maintenance are needed to be applied to intervening processing in time, so that the situation that the system is abnormal due to too high number of database connections and too fast service growth is avoided.
In some embodiments, the preset alarm condition may be that the current usage rate of the first database connection pool is compared with contemporaneous data, and whether to alarm is determined according to the comparison result. For example, the current usage of the first database connection pool obtained by monday 10:00 am is compared with monday 10 am: and (3) comparing the utilization rate of the first database connection pool obtained by 00, and if the current utilization rate of the first database connection pool obtained by 10:00 am exceeds 10 am in monday: and (3) alarming if the usage rate of the first database connection pool obtained by 00 is 20%.
The current running state of the system can be determined by comparing the utilization rates of the first database connection pools, and generally, if no major accident occurs, the utilization rates of the database connection pools of the system should be kept in a stable state, and if the current utilization rates of the first database connection pools exceed the utilization rates in the same period, the system is considered to have an abnormality at present, and a developer needs to be reminded of detection.
The alarm can be given by sending out alarm sound, displaying an alarm picture, sending an alarm message, sending an alarm mail and the like.
In summary, in the dynamic control device for dual database connection pools provided in the second embodiment of the present invention, the first database connection pool and the second database connection pool may be created in advance, and the maximum database connection number of the first database connection pool may be initialized; when a database connection request of an application program is received, calculating the current utilization rate of the first database connection pool; when the calculated current utilization rate of the first database connection pool is smaller than or equal to a preset database connection pool utilization rate threshold value, directly distributing available database connection to the application program through the first database connection pool; and when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, creating a temporary database connection through the second database connection pool and distributing the temporary database connection to the application program. The maximum database connection number can be initialized according to the configuration of the system, so that the normal operation of the system can be ensured, and the system resources can be furthest used. When the user request changes, the temporary database connection can be dynamically adjusted according to the number of the user request, so that the user request is responded in time, and the abnormal occurrence caused by overlong waiting time of the user is avoided.
Secondly, in the mode that the database connection is managed through the connection pool, when a user needs to perform database operation, a connection is applied from the connection pool, and after the database operation is finished, the connection is immediately released into the connection pool for other users to use. Thus, the use efficiency of the database connection is greatly improved, a large number of users can share fewer database connections, and the time for establishing the connection is saved. And after the database connection in the second database connection pool is used up, the database connection is released after a preset time period, so that the cost of releasing the database connection can be effectively reduced, and the situation that new connection is re-established after the connection is just released is avoided, and the system resource is not wasted due to frequent establishment of the released database connection.
The integrated units implemented in the form of software functional modules described above may be stored in a computer readable storage medium. The software functional modules described above are stored in a storage medium and include instructions for causing a computer device (which may be a personal computer, a two-screen computer device, or a network computer device, etc.) or processor (processor) to perform portions of the methods described in the various embodiments of the invention.
Example III
Fig. 3 is a schematic diagram of a computer device according to a third embodiment of the present invention.
The computer device 3 comprises: a memory 31, at least one processor 32, a computer program 33 stored in the memory 31 and executable on the at least one processor 32, and at least one communication bus 34.
The at least one processor 32, when executing the computer program 33, implements the steps of the dynamic control method embodiment of the dual database connection pool described above.
Specifically, the steps in the embodiment of the method for implementing the dynamic control of the dual database connection pool when the at least one processor 32 executes the computer program 33 include:
creating a first database connection pool and a second database connection pool, and initializing the maximum database connection number of the first database connection pool;
when receiving a database connection request of an application program, calculating the current utilization rate of the first database connection pool;
judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value or not;
when the current utilization rate of the first database connection pool is less than or equal to the utilization rate threshold value of the preset database connection pool, distributing available database connection to the application program through the first database connection pool;
And when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, creating temporary database connection through the second database connection pool and distributing the temporary database connection to the application program.
By way of example, the computer program 33 may be partitioned into one or more modules/units that are stored in the memory 31 (e.g., the creation module 201, the calculation module 202, the determination module 203, the first allocation module 204, the second allocation module 205, the release module 206, the acquisition module 207, and the alarm module 208) and executed by the at least one processor 32. The one or more modules/units may be a series of computer program instruction segments capable of performing the specified functions for describing the execution of the computer program 33 in the computer device 3.
The computer device 3 may be a desktop computer, a notebook computer, a palm computer, a cloud server, or the like. It will be appreciated by those skilled in the art that the schematic diagram 3 is merely an example of the computer device 3 and does not constitute a limitation of the computer device 3, and may include more or less components than illustrated, or may combine certain components, or different components, e.g. the computer device 3 may also include input-output computer devices, network access computer devices, buses, etc.
The at least one processor 32 may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. The processor 32 may be a microprocessor or the processor 32 may be any conventional processor or the like, the processor 32 being a control center of the computer device 3, the various interfaces and lines being used to connect the various parts of the entire computer device 3.
The memory 31 may be used to store the computer program 33 and/or modules/units, and the processor 32 may perform various functions of the computer device 3 by executing or executing the computer program and/or modules/units stored in the memory 31 and invoking data stored in the memory 31. The memory 31 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program (such as a sound playing function, an image playing function, etc.) required for at least one function, and the like; the storage data area may store data created according to the use of the computer device 3 (such as audio data, phonebooks, etc.), and the like. In addition, the memory 31 may include a high-speed random access memory, and may also include a nonvolatile memory such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card), at least one disk storage device, a Flash memory device, or other volatile solid-state storage device.
The modules/units integrated by the computer device 3 may be stored in a computer readable storage medium if implemented in the form of software functional units and sold or used as a stand alone product. Based on such understanding, the present invention may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the computer program may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the computer readable medium contains content that can be appropriately scaled according to the requirements of jurisdictions in which such content is subject to legislation and patent practice, such as in certain jurisdictions in which such content is subject to legislation and patent practice, the computer readable medium does not include electrical carrier signals and telecommunication signals.
In the several embodiments provided in the present invention, it should be understood that the disclosed server and method may be implemented in other manners. For example, the server embodiments described above are merely illustrative, e.g., the division of the elements is merely a logical functional division, and there may be additional divisions when actually implemented.
In addition, each functional unit in the embodiments of the present invention may be integrated in the same processing unit, or each unit may exist alone physically, or two or more units may be integrated in the same unit. The integrated units can be realized in a form of hardware or a form of hardware and a form of software functional modules.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof. The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it will be obvious that the term "comprising" does not exclude other elements or that the singular does not exclude a plurality. A plurality of units or means recited in the system claims can also be implemented by means of software or hardware by means of one unit or means. The terms first, second, etc. are used to denote a name, but not any particular order.
Finally, it should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention.

Claims (6)

1. A method for dynamically controlling a dual database connection pool, the method comprising:
creating a first database connection pool and a second database connection pool, and initializing the maximum database connection number of the first database connection pool;
when receiving a database connection request of an application program, calculating the current utilization rate of the first database connection pool, including: when receiving a database connection request of the application program, acquiring the number of database connections currently used in the first database connection pool; calculating the current utilization rate of the first database connection pool according to the current database connection number and the initialized maximum database connection number of the first database connection pool;
judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value or not;
When the current utilization rate of the first database connection pool is less than or equal to the utilization rate threshold value of the preset database connection pool, distributing available database connection to the application program through the first database connection pool;
when the current utilization rate of the first database connection pool is judged to be greater than the preset database connection pool utilization rate threshold, creating a temporary database connection through the second database connection pool and distributing the temporary database connection to the application program, wherein the method comprises the following steps: acquiring the request connection number of the application program; creating a temporary database connection corresponding to the requested connection number through a second database connection pool; assigning the temporary database connection to the application; and
when the current utilization rate of the first database connection pool is judged to be larger than the utilization rate threshold value of the preset database connection pool, judging whether the current utilization rate of the first database connection pool meets a preset alarm condition or not; if the current utilization rate of the first database connection pool meets the preset alarm condition, alarming, wherein the preset alarm condition comprises the following steps: and the current utilization rate of the first database connection pool exceeds a preset ratio of the contemporaneous utilization rate.
2. The method of claim 1, wherein after said creating a temporary database connection through said second database connection pool and assigning to said application, said method further comprises:
releasing the temporary database connection in the second database connection pool when the application program finishes using the temporary database connection; or alternatively
And when the application program finishes using the temporary database connection, releasing the temporary database connection in the second database connection pool after a preset time period.
3. The method of any of claims 1-2, wherein initializing the maximum database connection number for the first database connection pool comprises:
acquiring initial configuration in a system configuration file;
and determining the initial database connection number in the initial configuration file as the maximum database connection number in the first database connection pool.
4. A dual database connection pool dynamic control apparatus, characterized in that the apparatus comprises means for implementing the dual database connection pool dynamic control method according to any one of claims 1 to 3, the apparatus comprising:
The creation module is used for creating a first database connection pool and a second database connection pool and initializing the maximum database connection number of the first database connection pool;
the computing module is used for computing the current utilization rate of the first database connection pool when receiving the database connection request of the application program, and comprises the following steps: when receiving a database connection request of the application program, acquiring the number of database connections currently used in the first database connection pool; calculating the current utilization rate of the first database connection pool according to the current database connection number and the initialized maximum database connection number of the first database connection pool;
the judging module is used for judging whether the current utilization rate of the first database connection pool is larger than a preset database connection pool utilization rate threshold value;
the first allocation module is used for allocating available database connection to the application program through the first database connection pool when the judging module judges that the current utilization rate of the first database connection pool is smaller than or equal to the preset database connection pool utilization rate threshold;
and the second allocation module is used for creating temporary database connection through the second database connection pool and allocating the temporary database connection to the application program when the judging module judges that the current utilization rate of the first database connection pool is greater than the utilization rate threshold of the preset database connection pool.
5. A computer device, characterized in that it comprises a processor and a memory, said processor being adapted to implement the method of dynamic control of a dual database connection pool according to any of claims 1 to 3 when executing a computer program stored in said memory.
6. A computer readable storage medium having stored thereon a computer program, characterized in that the computer program, when executed by a processor, implements a method for dynamic control of a dual database connection pool according to any of claims 1 to 3.
CN201811537696.6A 2018-12-15 2018-12-15 Dynamic control method and device for double-database connection pool and related equipment Active CN109800261B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811537696.6A CN109800261B (en) 2018-12-15 2018-12-15 Dynamic control method and device for double-database connection pool and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811537696.6A CN109800261B (en) 2018-12-15 2018-12-15 Dynamic control method and device for double-database connection pool and related equipment

Publications (2)

Publication Number Publication Date
CN109800261A CN109800261A (en) 2019-05-24
CN109800261B true CN109800261B (en) 2024-04-05

Family

ID=66556886

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811537696.6A Active CN109800261B (en) 2018-12-15 2018-12-15 Dynamic control method and device for double-database connection pool and related equipment

Country Status (1)

Country Link
CN (1) CN109800261B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110389977B (en) * 2019-06-14 2022-03-08 威富通科技有限公司 Database connection creating method and device and terminal equipment
US11176155B2 (en) * 2019-12-13 2021-11-16 Paypal, Inc Self-adjusting connection pool in a distributed system
CN111177203B (en) * 2019-12-18 2023-08-15 中国平安财产保险股份有限公司 Method for dynamically adjusting size of database connection pool, server and storage medium
CN112181652B (en) * 2020-09-25 2023-11-28 北京天融信网络安全技术有限公司 Method and device for adjusting capacity of connection pool, storage medium and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101095109A (en) * 2004-12-31 2007-12-26 Bea系统公司 Multipool manager
CN101140594A (en) * 2007-10-12 2008-03-12 中兴通讯股份有限公司 Data-base space automatic extended method and management module
CN102902779A (en) * 2012-09-28 2013-01-30 五八有限公司 Connection method and connection device of multiple databases
CN104239365A (en) * 2013-06-24 2014-12-24 北京新媒传信科技有限公司 Database connection pool and method for acquiring links in database connection pool
CN104750546A (en) * 2013-12-30 2015-07-01 中国移动通信集团公司 Method and system for adjusting connection tank
CN106021544A (en) * 2016-05-27 2016-10-12 北京京东尚科信息技术有限公司 Distributive connection pool management method and system for databases

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8984010B2 (en) * 2012-11-06 2015-03-17 Business Objects Software Ltd. Build pooled data source based on hana SAML login

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101095109A (en) * 2004-12-31 2007-12-26 Bea系统公司 Multipool manager
CN101140594A (en) * 2007-10-12 2008-03-12 中兴通讯股份有限公司 Data-base space automatic extended method and management module
CN102902779A (en) * 2012-09-28 2013-01-30 五八有限公司 Connection method and connection device of multiple databases
CN104239365A (en) * 2013-06-24 2014-12-24 北京新媒传信科技有限公司 Database connection pool and method for acquiring links in database connection pool
CN104750546A (en) * 2013-12-30 2015-07-01 中国移动通信集团公司 Method and system for adjusting connection tank
CN106021544A (en) * 2016-05-27 2016-10-12 北京京东尚科信息技术有限公司 Distributive connection pool management method and system for databases

Also Published As

Publication number Publication date
CN109800261A (en) 2019-05-24

Similar Documents

Publication Publication Date Title
CN109800261B (en) Dynamic control method and device for double-database connection pool and related equipment
US7890712B2 (en) Method, apparatus and program product for managing memory in a virtual computing system
US20170031622A1 (en) Methods for allocating storage cluster hardware resources and devices thereof
CN109840142B (en) Thread control method and device based on cloud monitoring, electronic equipment and storage medium
CN107426274B (en) Method and system for service application and monitoring, analyzing and scheduling based on time sequence
CN109960575B (en) Computing capacity sharing method, system and related equipment
CN107395458B (en) System monitoring method and device
CN110677274A (en) Event-based cloud network service scheduling method and device
CN111880936A (en) Resource scheduling method and device, container cluster, computer equipment and storage medium
US20130305245A1 (en) Methods for managing work load bursts and devices thereof
CN113037794A (en) Computing resource allocation scheduling method, device and system
CN112600761B (en) Resource allocation method, device and storage medium
CN109428926B (en) Method and device for scheduling task nodes
CN109726007B (en) Container arrangement quota management method and device and container arrangement system
CN105162823A (en) Virtual machine management method and device
US11709707B2 (en) Low latency distributed counters for quotas
CN109413117B (en) Distributed data calculation method, device, server and computer storage medium
US20150079966A1 (en) Methods for facilitating telecommunication network administration and devices thereof
CN111586140A (en) Data interaction method and server
CN116436968A (en) Service grid communication method, system, device and storage medium
CN109962941B (en) Communication method, device and server
CN116401024A (en) Cluster capacity expansion and contraction method, device, equipment and medium based on cloud computing
CN112860387A (en) Distributed task scheduling method and device, computer equipment and storage medium
CN111435319A (en) Cluster management method and device
CN115794396A (en) Resource allocation method, system and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant