CN117793167A - Connection processing method, device, equipment and medium in connection pool - Google Patents

Connection processing method, device, equipment and medium in connection pool Download PDF

Info

Publication number
CN117793167A
CN117793167A CN202311827994.XA CN202311827994A CN117793167A CN 117793167 A CN117793167 A CN 117793167A CN 202311827994 A CN202311827994 A CN 202311827994A CN 117793167 A CN117793167 A CN 117793167A
Authority
CN
China
Prior art keywords
connection
pool
target
connections
connection pool
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.)
Pending
Application number
CN202311827994.XA
Other languages
Chinese (zh)
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.)
Beijing Kingbase Information Technologies Co Ltd
Original Assignee
Beijing Kingbase Information Technologies 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 Beijing Kingbase Information Technologies Co Ltd filed Critical Beijing Kingbase Information Technologies Co Ltd
Priority to CN202311827994.XA priority Critical patent/CN117793167A/en
Publication of CN117793167A publication Critical patent/CN117793167A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The application provides a connection processing method, a device, equipment and a medium in a connection pool, wherein the method comprises the following steps: acquiring a connection acquisition request corresponding to a client application; determining a connection state corresponding to the connection pool according to the connection acquisition request; if the connection state of the connection pool is that no available connection exists, judging whether the connection pool has a condition for creating new connection; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool; if the connection pool is determined to have the condition for creating the new connection, and enabling the client application to acquire the new connection. According to the connection processing method in the connection pool, the new connection is created only when the connection pool has the condition of creating the new connection, and the new connection is not continuously created according to the requirement of the client application, so that the problem of resource exhaustion is avoided.

Description

Connection processing method, device, equipment and medium in connection pool
Technical Field
The present disclosure relates to the field of data processing technologies, and in particular, to a method, an apparatus, a device, and a medium for processing connection in a connection pool.
Background
In order to improve performance, in some high concurrency scenarios, since the client needs to frequently establish a connection with the server, a connection pool mode is generally adopted, and the number of connections that can be created in the connection pool is limited.
The connection pool commonly used at present can continuously create new connection according to the requirement of the client application even if the connection in an idle state exists, so that resources are exhausted.
Thus, the current connection pool can continuously create new connections according to the requirements of the client application, thereby generating a problem of resource exhaustion.
Disclosure of Invention
The application provides a connection processing method, device, equipment and medium in a connection pool, which are used for solving the problem that the current connection pool can continuously create new connection according to the requirement of a client application, so that resource exhaustion is generated.
The first aspect of the present application provides a connection processing method in a connection pool, including:
acquiring a connection acquisition request corresponding to a client application;
determining a connection state corresponding to the connection pool according to the connection acquisition request;
if the connection state of the connection pool is that no available connection exists, judging whether the connection pool has a condition for creating new connection; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool;
if the connection pool is determined to have the condition for creating the new connection, and enabling the client application to acquire the new connection.
Further, as described above, the method of creating the connection in the connection pool includes: used connections occupied by the thread application and available connections not occupied by the thread application; the used connection includes: an idle connection in an idle state and a busy connection in a busy state;
the determining the connection state corresponding to the connection pool according to the connection acquisition request includes:
judging whether the available connection exists in the connection pool according to the connection acquisition request;
if the available connection is determined to not exist, judging whether the idle connection exists in the used connection or not;
and if the idle connection is determined to be absent, determining that the connection state in the connection pool is the absence of the available connection.
Further, the method as described above, if it is determined that the available connection exists, the method further comprises:
determining a target connection corresponding to the client application from the available connections;
and enabling the client application to acquire the target connection.
Further, in the method as described above, if it is determined that the idle connection exists, the method further includes:
determining target connection corresponding to the client application from the idle connection;
and enabling the client application to acquire the target connection.
Further, in the method as described above, the determining whether the connection pool has a condition for creating a new connection includes:
obtaining the number of target connections of all the created connections in the connection pool;
judging whether the target connection number is larger than or equal to a preset theoretical connection number;
if the target connection number is determined to be greater than or equal to the preset theoretical connection number, determining that the connection pool does not have a condition for creating new connection;
and if the target connection quantity is smaller than the preset theoretical connection quantity, determining that the connection pool has the condition of creating new connection.
Further, before the determining whether the target connection number is greater than or equal to the preset theoretical connection number, the method further includes:
acquiring resource state related data; the resource status related data includes: the number of processor cores, the utilization of processor cores, the number of ports used, the total number of ports, the number of file descriptors used, and the maximum number of file descriptors;
and inputting the related data of the resource state into a preset theoretical connection number algorithm to generate the preset theoretical connection number.
Further, before the determining whether the target connection number is greater than or equal to the preset theoretical connection number, the method further includes:
judging whether the target connection quantity is larger than or equal to a preset quantity threshold value; the preset number threshold is the product of the preset maximum connection number corresponding to the connection pool and a preset proportion threshold;
if the target connection number is determined to be greater than or equal to a preset number threshold, executing the step of judging whether the target connection number is greater than or equal to a preset theoretical connection number;
and if the target connection quantity is determined to be smaller than the preset quantity threshold value, determining that the connection pool has the condition of creating new connection.
A second aspect of the present application provides a connection processing apparatus in a connection pool, including:
the acquisition module is used for acquiring a connection acquisition request corresponding to the client application;
the determining module is used for determining the connection state corresponding to the connection pool according to the connection acquisition request;
the judging module is used for judging whether the connection pool has the condition of creating new connection or not if the connection state of the connection pool is that no connection can be obtained; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool;
and the creation module is used for creating a new connection and enabling the client application to acquire the new connection if the connection pool is determined to have the condition of creating the new connection.
Further, as described above, the connection created in the connection pool includes: used connections occupied by the thread application and available connections not occupied by the thread application; the used connection includes: an idle connection in an idle state and a busy connection in a busy state;
the determining module is specifically configured to:
judging whether the available connection exists in the connection pool according to the connection acquisition request; if the available connection is determined to not exist, judging whether the idle connection exists in the used connection or not; and if the idle connection is determined to be absent, determining that the connection state in the connection pool is the absence of the available connection.
Further, in the apparatus as described above, if it is determined that the available connection exists, the determining module is further configured to:
determining a target connection corresponding to the client application from the available connections; and enabling the client application to acquire the target connection.
Further, in the apparatus as described above, if it is determined that the idle connection exists, the determining module is further configured to:
determining target connection corresponding to the client application from the idle connection; and enabling the client application to acquire the target connection.
Further, in the apparatus as described above, the determining module is specifically configured to, when determining whether the connection pool has a condition for creating a new connection:
obtaining the number of target connections of all the created connections in the connection pool; judging whether the target connection number is larger than or equal to a preset theoretical connection number; if the target connection number is determined to be greater than or equal to the preset theoretical connection number, determining that the connection pool does not have a condition for creating new connection; and if the target connection quantity is smaller than the preset theoretical connection quantity, determining that the connection pool has the condition of creating new connection.
Further, the apparatus as described above, further comprising:
the generation module is used for acquiring the related data of the resource state; the resource status related data includes: the number of processor cores, the utilization of processor cores, the number of ports used, the total number of ports, the number of file descriptors used, and the maximum number of file descriptors; and inputting the related data of the resource state into a preset theoretical connection number algorithm to generate the preset theoretical connection number.
Further, the apparatus as described above, further comprising:
the numerical judgment module is used for judging whether the target connection quantity is larger than or equal to a preset quantity threshold value; the preset number threshold is the product of the preset maximum connection number corresponding to the connection pool and a preset proportion threshold; if the target connection number is determined to be greater than or equal to a preset number threshold, executing the step of judging whether the target connection number is greater than or equal to a preset theoretical connection number; and if the target connection quantity is determined to be smaller than the preset quantity threshold value, determining that the connection pool has the condition of creating new connection.
A third aspect of the present application provides an electronic device, comprising: a memory and a processor;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored in the memory to implement the connection processing method in the connection pool according to any one of the first aspect.
A fourth aspect of the present application provides a computer-readable storage medium having stored therein computer-executable instructions for implementing the connection processing method in the connection pool according to any one of the first aspects when executed by a processor.
A fifth aspect of the present application provides a computer program product comprising a computer program which, when executed by a processor, implements a method for connection handling in a connection pool according to any of the first aspects.
The application provides a connection processing method, a device, equipment and a medium in a connection pool, wherein the method comprises the following steps: acquiring a connection acquisition request corresponding to a client application; determining a connection state corresponding to the connection pool according to the connection acquisition request; if the connection state of the connection pool is that no available connection exists, judging whether the connection pool has a condition for creating new connection; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool; if the connection pool is determined to have the condition for creating the new connection, and enabling the client application to acquire the new connection. According to the connection processing method in the connection pool, when the connection acquisition request corresponding to the client application is acquired, the connection state corresponding to the connection pool is determined, and if the connection state of the connection pool is that no connection can be acquired, whether the connection pool has a condition for creating a new connection is further judged. Meanwhile, a new connection is created only when the connection pool has the condition of creating the new connection, and the new connection is not continuously created according to the requirement of the client application, so that the problem of resource exhaustion is avoided.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
FIG. 1 is a scenario diagram of a connection processing method in a connection pool in which embodiments of the present application may be implemented;
fig. 2 is a schematic flow chart of a connection processing method in a connection pool provided in the present application;
FIG. 3 is a second flow chart of a connection processing method in the connection pool provided in the present application;
FIG. 4 is an overall flowchart of a connection processing method in a connection pool provided in the present application;
fig. 5 is a schematic structural diagram of a connection processing device in the connection pool provided in the present application;
fig. 6 is a schematic structural diagram of an electronic device provided in the present application.
Specific embodiments thereof have been shown by way of example in the drawings and will herein be described in more detail. These drawings and the written description are not intended to limit the scope of the inventive concepts in any way, but to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application as detailed in the accompanying claims.
In the technical scheme of the embodiment of the application, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing and the like of the personal information of the user accord with the regulations of related laws and regulations, and the public order is not violated.
It should be noted that, the user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are information and data authorized by the user or fully authorized by each party, and the collection, use and processing of the related data need to comply with the related laws and regulations and standards of the related country and region, and provide corresponding operation entries for the user to select authorization or rejection.
It should be noted that the connection processing method, device, equipment and medium in the connection pool of the present disclosure may be used in the technical field of data processing. And can be used in any field except the technical field of data processing. The connection processing method, device, equipment and medium application field in the connection pool are not limited.
The technical scheme of the present application is described in detail below with specific examples. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
For a clear understanding of the technical solutions of the present application, the prior art solutions will be described in detail first. Connection pools are a technique to create and manage a buffer pool of connections that are ready for use by any thread that needs them. In a high concurrency scenario, the client may acquire an available connection from the connection pool, and return the connection to the connection pool after use. Therefore, the connection process with the construction of the server does not need to be repeatedly executed, and the overall performance is improved. The connection pool commonly used at present can continuously create new connection according to the requirement of the client application even if the connection in an idle state exists, so that resources are exhausted.
Therefore, in order to solve the problem that in the prior art, a connection pool can continuously create new connection according to the requirement of a client application so as to generate resource exhaustion, the inventor finds out in the research that, when the connection pool does not have the connection corresponding to the client which can be acquired, whether the connection pool has the condition of creating the new connection or not can be judged, and the process of correspondingly creating the connection or waiting for the connection is performed based on the result of whether the connection pool has the condition of creating the new connection or waiting for the connection so as to avoid the problem of generating resource exhaustion.
Specifically, a connection acquisition request corresponding to a client application is acquired. And determining the connection state corresponding to the connection pool according to the connection acquisition request. If the connection state of the connection pool is that no available connection exists, judging whether the connection pool has the condition of creating a new connection. Connections may be acquired as connections in the connection pool that were not occupied by the thread application or occupied by the thread application but are in an idle state. If the connection pool is determined to have the condition for creating the new connection, creating the new connection and enabling the client application to acquire the new connection.
According to the connection processing method in the connection pool, when the connection acquisition request corresponding to the client application is acquired, the connection state corresponding to the connection pool is determined, and if the connection state of the connection pool is that no connection can be acquired, whether the connection pool has a condition for creating a new connection is further judged. Meanwhile, a new connection is created only when the connection pool has the condition of creating the new connection, and the new connection is not continuously created according to the requirement of the client application, so that the problem of resource exhaustion is avoided.
The inventor puts forward the technical scheme of the application based on the creative discovery.
The following describes an application scenario of a connection processing method in a connection pool provided in an embodiment of the present application. As shown in fig. 1, where 10 is a client device, 20 is a server device, 11 is a client application, and 13 is a connection pool. The network architecture of the application scenario corresponding to the connection processing method in the connection pool provided by the embodiment of the application includes: client device 10, and server device 20. The number of connections in the connection pool 13 may be one or more, and the client application 11 may be plural.
Illustratively, when the client application 11 requires a connection, the connection pool 13 acquires a connection acquisition request corresponding to the client application 11. The connection pool 13 determines a connection state corresponding to the connection pool 13 according to the connection acquisition request.
If the connection state of the connection pool 13 is such that no connection is available, it is determined whether or not the connection pool 13 has a condition to create a new connection. Wherein the connection may be acquired as a connection in the connection pool 13 that has not been occupied by a thread application or occupied by a thread application but is in an idle state.
If it is determined that the connection pool 13 has the condition to create a new connection, a new connection with the server device 20 is created, and the client application 11 is caused to acquire the new connection. After using the connection, the client application 11 returns the connection to the connection pool 13.
Embodiments of the present application are described below with reference to the accompanying drawings.
Fig. 2 is a schematic flow chart of a connection processing method in a connection pool provided in the present application, as shown in fig. 2, in this embodiment, an execution body of the embodiment of the present application is a connection processing device in a connection pool, where the connection processing device in the connection pool may be integrated in an electronic device, and the electronic device may be a client device, where the client device is in communication connection with a server device. The connection processing method in the connection pool provided in this embodiment includes the following steps:
s101, obtaining a connection obtaining request corresponding to a client application.
In this embodiment, the client application may be a plurality of types of applications, such as a communication application, a storage application, and the like.
S102, determining a connection state corresponding to the connection pool according to the connection acquisition request.
In this embodiment, the created connections in the connection pool include used connections that were occupied by the thread application and available connections that were not occupied by the thread application. The available connections indicate that the connection is not occupied by the thread application and that the client application can immediately acquire and use the connection resources when needed. The used connection indicates that the connection has been acquired by the client application, and there are two states for the connection: busy, free.
The connection state corresponding to the connection pool comprises whether connection exists, whether available connection exists, whether idle connection exists in the used connection or not, and the like, and the connection state corresponding to the connection pool can be determined simultaneously or sequentially, and can be set according to actual application.
S103, if the connection state of the connection pool is that no connection can be obtained, judging whether the connection pool has the condition of creating new connection. Connections may be acquired as connections in the connection pool that were not occupied by the thread application or occupied by the thread application but are in an idle state.
If the connection state is that no available connection exists, the connection pool is represented that no available connection exists, and no connection in an idle state exists in the used connection, so that only a new connection can be created or the used connection is waited for being returned, the available connection is obtained, the time for returning the connection is uncertain, and whether the connection pool has the condition of creating the new connection can be determined first.
The condition for creating new connection may be whether the number of connections has reached the maximum number of connections that can be carried by the connection pool, or whether the number of connections reaches the number of connections is determined according to the performance requirement of the actual application, where the number of connections does not decrease the performance requirement. Meanwhile, other conditions are also possible, and this embodiment is not limited thereto.
And S104, if the connection pool is determined to have the condition of creating the new connection, and enabling the client application to acquire the new connection.
The method for processing connection in the connection pool provided by the embodiment of the application comprises the following steps: and acquiring a connection acquisition request corresponding to the client application. And determining the connection state corresponding to the connection pool according to the connection acquisition request. If the connection state of the connection pool is that no available connection exists, judging whether the connection pool has the condition of creating a new connection. Connections may be acquired as connections in the connection pool that were not occupied by the thread application or occupied by the thread application but are in an idle state. If the connection pool is determined to have the condition for creating the new connection, creating the new connection and enabling the client application to acquire the new connection.
According to the connection processing method in the connection pool, when the connection acquisition request corresponding to the client application is acquired, the connection state corresponding to the connection pool is determined, and if the connection state of the connection pool is that no connection can be acquired, whether the connection pool has a condition for creating a new connection is further judged. Meanwhile, a new connection is created only when the connection pool has the condition of creating the new connection, and the new connection is not continuously created according to the requirement of the client application, so that the problem of resource exhaustion is avoided.
Fig. 3 is a second schematic flow chart of the connection processing method in the connection pool provided in the present application, as shown in fig. 3, where the connection processing method in the connection pool provided in the present embodiment is further refined on the basis of the connection processing method in the connection pool provided in the previous embodiment of the present application. The connection processing method in the connection pool provided in this embodiment includes the following steps.
S201, obtaining a connection obtaining request corresponding to a client application.
The implementation of S201 in this embodiment is similar to that of S101 in the previous embodiment, and will not be described here again.
It should be noted that, in this embodiment, the created connection in the connection pool includes: used connections that are occupied by the thread application and available connections that were not occupied by the thread application. The used connections include: an idle connection in an idle state and a busy connection in a busy state.
S202, judging whether available connection exists in the connection pool according to the connection acquisition request.
In this embodiment, when the client application acquires a connection, the connection will be occupied, and the connection at this time becomes a used connection. In the current connection pool, other client applications cannot use the used connection, and only after the client application returns the connection, the connection becomes an available connection, the use can be obtained.
Optionally, in this embodiment, if it is determined that there is an available connection, in this embodiment, the client application may further directly obtain the available connection:
and determining the target connection corresponding to the client application from the available connections.
And enabling the client application to acquire the target connection.
Before S202, it may also be determined whether there is a connection in the connection pool, and if not, the flow of creating a connection is directly performed.
S203, if it is determined that no available connection exists, judging whether an idle connection exists in the used connection.
An idle connection is one of the used connections that is in an idle state, at which time the client application occupying the used connection has not used the used connection, thereby placing the used connection in an idle state.
Optionally, in this embodiment, if it is determined that there is an idle connection, in this embodiment, the client application may directly obtain the corresponding idle connection:
and determining the target connection corresponding to the client application from the idle connection.
And enabling the client application to acquire the target connection.
In this embodiment, in order to utilize the idle connection in the idle state in the used connection when there is no available connection, the capability of physically multiplexing the connection channels can be achieved, thereby improving the concurrent processing capability of the connection pool.
S204, if it is determined that no free connection exists, determining that the connection state in the connection pool is that no available connection exists.
S205, it is determined whether the connection pool has a condition for creating a new connection.
In this embodiment, S205 may specifically be:
the target number of connections for all connections that have been created in the connection pool is obtained.
And judging whether the target connection number is larger than or equal to the preset theoretical connection number.
If the number of the target connections is determined to be greater than or equal to the preset theoretical number of connections, determining that the connection pool does not have a condition for creating new connections.
If the number of the target connections is smaller than the number of the preset theoretical connections, the connection pool is determined to have the condition of creating new connections.
The preset theoretical connection quantity can be preset, for example, the preset theoretical connection quantity can be determined according to the performance of the server equipment, and when the target connection quantity is smaller than the preset theoretical connection quantity, the equipment performance is not greatly affected.
Optionally, in this embodiment, the preset theoretical connection number may also be obtained by calculation, and specifically, before determining whether the target connection number is greater than or equal to the preset theoretical connection number, the following processing may be further performed:
and acquiring the resource state related data. The resource status related data includes: the number of processor cores, the utilization of processor cores, the number of ports used, the total number of ports, the number of file descriptors used, and the maximum number of file descriptors.
And inputting the related data of the resource state into a preset theoretical connection number algorithm to generate a preset theoretical connection number.
The preset theoretical connection number algorithm is as follows:
wherein N is conn Representing the number of preset theoretical connections, k s Representing a preset coefficient, P representing the number of ports used, and P representing the total number of ports, typically 65535, f d Representing the number of used file descriptors, F d Representing the maximum number of file descriptors, x i Indicating the utilization of the processor cores and N indicating the number of processor cores.
Wherein k is s Corresponding setting can be performed according to the system architecture platform, and different coefficients are set according to different performances. Such as tieThe number may be set to 0.7, 0.8, 1, or the like.
Optionally, in this embodiment, whether the relationship between the target connection number and the preset theoretical connection number needs to be determined may be further determined according to the relationship between the connection number in the connection pool and the maximum connection number set in the connection pool, which is specifically as follows:
and judging whether the number of the target connections is larger than or equal to a preset number threshold. The preset number threshold is the product of the preset maximum connection number corresponding to the connection pool and the preset proportion threshold.
And if the number of the target connections is determined to be greater than or equal to the preset number threshold, executing the step of judging whether the number of the target connections is greater than or equal to the preset theoretical number of connections.
If the number of the target connections is determined to be smaller than the preset number threshold, determining that the connection pool has the condition of creating new connections.
In this embodiment, the preset maximum number of connections is related to the connection pools, and the performance of each connection pool is different, and the corresponding maximum number of connections is also different. The preset ratio threshold may be set according to the actual application, for example, may be set to 75 percent. Only when the target connection number is greater than or equal to 0.75 maximum connection number, the relationship between the target connection number and the preset theoretical connection number is judged subsequently.
According to the embodiment, through double-layer judgment, the situation that connection is still established when the number of connections in the connection pool is too large can be further avoided, and the overall performance of the connection pool is improved.
And S206, if the connection pool is determined to have the condition of creating the new connection, and enabling the client application to acquire the new connection.
In this embodiment, if it is determined that the connection pool does not have a condition for creating a new connection, the client application is caused to wait.
In order to further explain the connection processing method in the connection pool of the present embodiment, another embodiment will be exemplarily described below with reference to the accompanying drawings.
In the architecture of the connection pool in this embodiment, the connection pool includes available connections and used connections, and when a client application (hereinafter referred to as a client for short) can obtain a connection of the connection pool, the connection pool can also be restored after use. The connection created by the connection pool is associated with the server device. Meanwhile, in the embodiment, the connection pool has the functions of performance evaluation, idle connection recovery and the like.
As shown in fig. 4, the overall flow is as follows:
s301, the client acquires connection.
S302, do there are connections in the connection pool? If there is a connection, S303 is executed, and if there is no connection, S309 is executed.
S303, is there a connection available in the connection pool? If there is an available connection, S307 is performed, and if there is no available connection, S304 is performed.
S304, is there an idle connection in the used connections in the connection pool? If there is an idle connection, S308 is executed, and if there is no idle connection, S305 is executed.
S305, calculating the theoretical connection number N conn
S306, whether the connection quantity of the connection pool is larger than the theoretical connection quantity N conn ? If yes, the step S306 is executed again after waiting for the preset interval time. If not, S309 is performed.
S307, directly acquiring connection from available connection.
S308, physically multiplexing the idle connection from the used connection.
S309, creating a new connection and enabling the client to acquire the connection.
Fig. 5 is a schematic structural diagram of a connection processing apparatus in a connection pool provided in the present application, as shown in fig. 5, in this embodiment, the connection processing apparatus 300 in a connection pool may be disposed in an electronic device, and the connection processing apparatus 300 in a connection pool includes:
the obtaining module 301 is configured to obtain a connection obtaining request corresponding to the client application.
A determining module 302, configured to determine a connection state corresponding to the connection pool according to the connection acquisition request.
And a judging module 303, configured to judge whether the connection pool has a condition for creating a new connection if the connection state of the connection pool is that no connection is available. Connections may be acquired as connections in the connection pool that were not occupied by the thread application or occupied by the thread application but are in an idle state.
A creation module 304, configured to create a new connection and enable the client application to acquire the new connection if it is determined that the connection pool has a condition for creating the new connection.
The connection processing device in the connection pool provided in this embodiment may execute the technical scheme of the method embodiment shown in fig. 2, and its implementation principle and technical effects are similar to those of the method embodiment shown in fig. 2, and are not described in detail herein.
On the basis of the connection processing device in the connection pool provided in the previous embodiment, the connection processing device in the connection pool is further refined, and then the connection processing device 300 in the connection pool includes:
optionally, in this embodiment, the created connection in the connection pool includes: used connections that are occupied by the thread application and available connections that were not occupied by the thread application. The used connections include: an idle connection in an idle state and a busy connection in a busy state.
The determining module 302 is specifically configured to:
and judging whether available connection exists in the connection pool according to the connection acquisition request. If it is determined that there is no available connection, it is determined whether there is an idle connection among the used connections. If it is determined that no free connection exists, determining that the connection state in the connection pool is that no available connection exists.
Optionally, in this embodiment, if it is determined that there is an available connection, the determining module 302 is further configured to:
and determining the target connection corresponding to the client application from the available connections. And enabling the client application to acquire the target connection.
Optionally, in this embodiment, if it is determined that there is an idle connection, the determining module 302 is further configured to:
and determining the target connection corresponding to the client application from the idle connection. And enabling the client application to acquire the target connection.
Optionally, in this embodiment, when determining whether the connection pool has a condition of creating a new connection, the determining module 303 is specifically configured to:
the target number of connections for all connections that have been created in the connection pool is obtained. And judging whether the target connection number is larger than or equal to the preset theoretical connection number. If the number of the target connections is determined to be greater than or equal to the preset theoretical number of connections, determining that the connection pool does not have a condition for creating new connections. If the number of the target connections is smaller than the number of the preset theoretical connections, the connection pool is determined to have the condition of creating new connections.
Optionally, in this embodiment, the connection processing apparatus 300 in the connection pool further includes:
and the generating module is used for acquiring the resource state related data. The resource status related data includes: the number of processor cores, the utilization of processor cores, the number of ports used, the total number of ports, the number of file descriptors used, and the maximum number of file descriptors. And inputting the related data of the resource state into a preset theoretical connection number algorithm to generate a preset theoretical connection number.
Optionally, in this embodiment, the connection processing apparatus 300 in the connection pool further includes:
the numerical judgment module is used for judging whether the number of the target connections is larger than or equal to a preset number threshold value. The preset number threshold is the product of the preset maximum connection number corresponding to the connection pool and the preset proportion threshold. And if the number of the target connections is determined to be greater than or equal to the preset number threshold, executing the step of judging whether the number of the target connections is greater than or equal to the preset theoretical number of connections. If the number of the target connections is determined to be smaller than the preset number threshold, determining that the connection pool has the condition of creating new connections.
The connection processing device in the connection pool provided in this embodiment may execute the technical scheme of the method embodiment shown in fig. 2 to 4, and its implementation principle and technical effect are similar to those of the method embodiment shown in fig. 2 to 4, and are not described in detail herein.
According to embodiments of the present application, there is also provided an electronic device, a computer-readable storage medium, and a computer program product.
As shown in fig. 6, fig. 6 is a schematic structural diagram of the electronic device provided in the present application. Electronic devices are intended for various forms of digital computers, such as laptops, desktops, workstations, blade servers, mainframes, and other appropriate computers. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the application described and/or claimed herein.
As shown in fig. 6, the electronic device includes: a processor 401 and a memory 402. The various components are interconnected using different buses and may be mounted on a common motherboard or in other manners as desired. The processor may process instructions executing within the electronic device.
Memory 402 is a non-transitory computer-readable storage medium provided herein. The memory stores instructions executable by the at least one processor to cause the at least one processor to perform a connection processing method in the connection pool provided herein. The non-transitory computer readable storage medium of the present application stores computer instructions for causing a computer to execute the connection processing method in the connection pool provided by the present application.
The memory 402 is used as a non-transitory computer readable storage medium, and may be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules (e.g., the acquisition module 301, the determination module 302, the determination module 303, and the creation module 304 shown in fig. 5) corresponding to a connection processing method in a connection pool in an embodiment of the present application. The processor 401 executes various functional applications of the electronic device and data processing, i.e. implements the connection processing method in the connection pool in the above-described method embodiment, by running non-transitory software programs, instructions and modules stored in the memory 402.
Meanwhile, the present embodiment also provides a computer product, which when executed by a processor of an electronic device, enables the electronic device to perform the connection processing method in the connection pool of the above embodiment.
Other embodiments of the examples herein will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any adaptations, uses, or adaptations of the embodiments of the application following, in general, the principles of the embodiments and including such departures from the present disclosure as come within known or customary practice within the art to which the embodiments of the application pertains.
It is to be understood that the embodiments of the present application are not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be made without departing from the scope thereof. The scope of embodiments of the present application is limited only by the appended claims.

Claims (10)

1. A connection processing method in a connection pool, comprising:
acquiring a connection acquisition request corresponding to a client application;
determining a connection state corresponding to the connection pool according to the connection acquisition request;
if the connection state of the connection pool is that no available connection exists, judging whether the connection pool has a condition for creating new connection; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool;
if the connection pool is determined to have the condition for creating the new connection, and enabling the client application to acquire the new connection.
2. The method of claim 1, wherein the created connection in the connection pool comprises: used connections occupied by the thread application and available connections not occupied by the thread application; the used connection includes: an idle connection in an idle state and a busy connection in a busy state;
the determining the connection state corresponding to the connection pool according to the connection acquisition request includes:
judging whether the available connection exists in the connection pool according to the connection acquisition request;
if the available connection is determined to not exist, judging whether the idle connection exists in the used connection or not;
and if the idle connection is determined to be absent, determining that the connection state in the connection pool is the absence of the available connection.
3. The method of claim 2, wherein if it is determined that there is the available connection, the method further comprises:
determining a target connection corresponding to the client application from the available connections;
and enabling the client application to acquire the target connection.
4. The method of claim 2, wherein if it is determined that the idle connection exists, the method further comprises:
determining target connection corresponding to the client application from the idle connection;
and enabling the client application to acquire the target connection.
5. The method according to any one of claims 1 to 4, wherein determining whether the connection pool has a condition to create a new connection comprises:
obtaining the number of target connections of all the created connections in the connection pool;
judging whether the target connection number is larger than or equal to a preset theoretical connection number;
if the target connection number is determined to be greater than or equal to the preset theoretical connection number, determining that the connection pool does not have a condition for creating new connection;
and if the target connection quantity is smaller than the preset theoretical connection quantity, determining that the connection pool has the condition of creating new connection.
6. The method of claim 5, wherein before determining whether the target number of connections is greater than or equal to a preset theoretical number of connections, further comprising:
acquiring resource state related data; the resource status related data includes: the number of processor cores, the utilization of processor cores, the number of ports used, the total number of ports, the number of file descriptors used, and the maximum number of file descriptors;
and inputting the related data of the resource state into a preset theoretical connection number algorithm to generate the preset theoretical connection number.
7. The method of claim 5, wherein before determining whether the target number of connections is greater than or equal to a preset theoretical number of connections, further comprising:
judging whether the target connection quantity is larger than or equal to a preset quantity threshold value; the preset number threshold is the product of the preset maximum connection number corresponding to the connection pool and a preset proportion threshold;
if the target connection number is determined to be greater than or equal to a preset number threshold, executing the step of judging whether the target connection number is greater than or equal to a preset theoretical connection number;
and if the target connection quantity is determined to be smaller than the preset quantity threshold value, determining that the connection pool has the condition of creating new connection.
8. A connection processing apparatus in a connection pool, comprising:
the acquisition module is used for acquiring a connection acquisition request corresponding to the client application;
the determining module is used for determining the connection state corresponding to the connection pool according to the connection acquisition request;
the judging module is used for judging whether the connection pool has the condition of creating new connection or not if the connection state of the connection pool is that no connection can be obtained; the available connection is a connection which is not occupied by the thread application or occupied by the thread application but is in an idle state in the connection pool;
and the creation module is used for creating a new connection and enabling the client application to acquire the new connection if the connection pool is determined to have the condition of creating the new connection.
9. An electronic device, comprising: a memory and a processor;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored in the memory to implement the connection processing method in the connection pool according to any one of claims 1 to 7.
10. A computer-readable storage medium, wherein computer-executable instructions are stored in the computer-readable storage medium, which when executed by a processor, are configured to implement the connection processing method in the connection pool according to any one of claims 1 to 7.
CN202311827994.XA 2023-12-27 2023-12-27 Connection processing method, device, equipment and medium in connection pool Pending CN117793167A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311827994.XA CN117793167A (en) 2023-12-27 2023-12-27 Connection processing method, device, equipment and medium in connection pool

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311827994.XA CN117793167A (en) 2023-12-27 2023-12-27 Connection processing method, device, equipment and medium in connection pool

Publications (1)

Publication Number Publication Date
CN117793167A true CN117793167A (en) 2024-03-29

Family

ID=90394193

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311827994.XA Pending CN117793167A (en) 2023-12-27 2023-12-27 Connection processing method, device, equipment and medium in connection pool

Country Status (1)

Country Link
CN (1) CN117793167A (en)

Similar Documents

Publication Publication Date Title
CN108647104B (en) Request processing method, server and computer readable storage medium
CN110096336B (en) Data monitoring method, device, equipment and medium
CN109951547B (en) Transaction request parallel processing method, device, equipment and medium
CN109729106B (en) Method, system and computer program product for processing computing tasks
CN111930498B (en) Efficient GPU resource allocation optimization method and system
CN107704310B (en) Method, device and equipment for realizing container cluster management
CN105740085A (en) Fault tolerance processing method and device
CN110781159B (en) Ceph directory file information reading method and device, server and storage medium
CN110750517B (en) Data processing method, device and equipment of local storage engine system
CN110399329B (en) RDMA data processing method and related device
CN111885184A (en) Method and device for processing hot spot access keywords in high concurrency scene
CN110162395B (en) Memory allocation method and device
CN111046004B (en) Data file storage method, device, equipment and storage medium
CN110489356B (en) Information processing method, information processing device, electronic equipment and storage medium
WO2015058594A1 (en) Process loading method, device and system
CN116932147A (en) Streaming job processing method and device, electronic equipment and medium
CN110609707B (en) Online data processing system generation method, device and equipment
CN111382141A (en) Master-slave architecture configuration method, device, equipment and computer readable storage medium
CN117793167A (en) Connection processing method, device, equipment and medium in connection pool
CN110955461A (en) Processing method, device and system of computing task, server and storage medium
CN112637201B (en) Method, device, equipment and system for processing request of web server
CN114116655A (en) Parallel file storage method, device, equipment and storage medium based on virtual machine
CN112231290A (en) Method, device and equipment for processing local log and storage medium
CN112328598A (en) ID generation method, device, electronic equipment and storage medium
CN110704026A (en) Calling method and device of software development kit, terminal and readable medium

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