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 do not represent all implementations consistent with the application. Rather, they are merely examples of apparatus and methods consistent with aspects of the application as detailed in the accompanying claims.
The terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. In the following description of the embodiments, the meaning of "a plurality" is two or more, unless explicitly defined otherwise.
First, the terms involved in the present application will be explained:
core thread number refers to the number of threads that survive, i.e., reside, for a long period of time in the connection pool.
The maximum number of threads refers to the maximum number of threads in the connection pool that can be created.
The idle thread survival time refers to the survival time corresponding to the idle thread, and when no task exists in the task queue of the connection pool and the idle time corresponding to the idle thread reaches the survival time, the idle thread can be destroyed. The number of threads destroyed = maximum number of threads-core number of threads.
The time unit refers to a description unit of the survival time of the idle thread.
The task queue refers to a queue for storing tasks in the connection pool and is used for storing tasks to be executed in the connection pool.
Thread factory refers to the method called when a connection pool creates a new thread.
Rejecting policy refers to a policy how to reject a request to execute when the task queue is full and the worker thread is greater than or equal to the maximum number of threads of the connection pool.
Principle of operation of the connection pool:
Step S1, judging whether the current thread number in a connection pool reaches the core thread number or not for a task to be executed, if not, creating a new thread to execute the task, and after the task is ended, reserving the thread in the connection pool without destruction processing;
Step S2, judging whether the task queue is full, if not, submitting the task to the task queue, and if so, entering step S3;
And S3, judging whether the current thread number in the connection pool reaches the maximum thread number, if not, newly creating threads to execute the task, and if so, processing the task by using a rejection strategy.
When the current thread number in the connection pool reaches the maximum thread number, each time the idle time corresponding to a certain thread reaches the idle thread survival time, destroying the thread until the current thread number in the connection pool is equal to the core thread number.
For a clear understanding of the technical solutions of the present application, the prior art solutions will be described in detail first.
With the rapid development of computer technology, most of internet applications currently adopt a structure that a client is connected with a server to realize that the client obtains data expected by the client from the server. When the client establishes a bottom layer TCP connection with the server, the client needs to undergo three-way handshake with the server, and the three-way handshake comprises a series of system calls with high cost on machine resources, such as I/O (Input/Output) operation, network monitoring and the like.
In the related art, the connection pool is an important middleware. By placing connection resources in advance in a management container, referred to as a connection pool, a client, when accessing a server, first obtains available connections from the connection pool and then uses the connections to communicate with the server. Taking a database connection pool for accessing a database as an example, when a client accesses a database server, the client accesses the connection pool to obtain available connection, and then uses the connection to communicate with the server. By using the connection pool, the client side is not required to newly establish a database connection when being connected with the database server side, thereby improving the system performance.
The connection pool is configured by the connection pool parameters, however, in the related art, the connection pool parameters are generally set by a technician according to experience in advance, but there is dynamic variation in communication between the client and the server, and how to dynamically adjust the connection pool parameters to better manage the connection pool becomes a problem to be solved.
Aiming at the technical problem of poor dynamic scheduling effect caused by large resource use gap between working nodes in the related technology, the inventor finds out in the research that in order to solve the problem, the parameters of the connection pool can be dynamically adjusted in the operation process of the connection pool, and further, the parameters can be adjusted according to the operation condition of the connection pool. In particular, the client obtains the operation data of the target connection pool in the operation process of the target connection pool, and sends the operation data to the configuration equipment, so that the configuration equipment adjusts the target connection pool based on the operation data, and because the operation data comprises the times of the target connection pool accessing the server in a preset time interval, the operation data can embody the service condition of the target connection pool, so that the adjusted connection pool parameters are more attached to the actual service condition of the target connection pool, the dynamic adjustment of the connection pool parameters of the target connection pool is realized, the correctness of the connection pool parameters is improved, and the management effect of the connection pool is further improved.
The application scenario of the connection pool management method provided by the embodiment of the application is described below.
Fig. 1 is a schematic diagram of an application scenario shown according to an example embodiment. As shown in fig. 1, the application scenario includes a configuration device 1, a client 2 and a server 3. The devices are connected through a network.
The configuration device 1 is used for managing a connection pool, the client 2 refers to client devices, the server 3 refers to server devices, and the client 2 and the server 3 communicate through connection objects in the connection pool. In this embodiment, the configuration device 1 receives the operation data for the target connection pool sent by the client 2, adjusts the connection pool parameter corresponding to the target connection pool based on the operation data to obtain an adjusted connection pool parameter, and then sends the adjusted connection pool parameter to the client 2, so that the client 2 configures the target connection pool based on the adjusted connection pool parameter.
The following describes the technical scheme of the present application and how the technical scheme of the present application solves the above technical problems in detail with specific embodiments. 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.
Fig. 2 is a flow diagram illustrating a method of connection pool management, according to an example embodiment. The execution main body of the connection pool management method provided by the application is a connection pool management device which is integrated in configuration equipment, and the configuration equipment is used for managing the connection pool. As shown in fig. 2, the connection pool management method provided in this embodiment includes the following steps:
step S101, receiving operation data sent by a client and aiming at a target connection pool, wherein the target connection pool is a connection pool related to a target application, the operation data comprises the times of the target connection pool accessing a server in a preset time interval, and the server is used for providing background service for the target application.
The target connection pool is a connection pool provided by the server and is used for the client to realize communication with the server through connection in the target connection pool. The client side is provided with a target application, the target application can be any type of application, and a background server of the target application is a server side. And the client acquires the operation data of the target connection pool in real time and sends the operation data to the configuration equipment. Optionally, the client transmits the acquired operation data to the configuration device at regular intervals. The fixed interval is the interval length corresponding to the preset time interval, namely the time interval between the starting time and the ending time in the preset time interval. The preset time interval may be set according to needs, and the embodiment is not limited thereto, for example, the preset time interval may be any time interval with an interval length of 5 minutes, such as 1 point to 1 point for 5 minutes, and further, the preset time interval may be any time interval with an interval length of 10 minutes, such as 2 points to 2 points for 10 minutes.
Step S102, based on the operation data, adjusting the connection pool parameters corresponding to the target connection pool to obtain adjusted connection pool parameters, wherein the connection pool parameters are used for describing the target connection pool.
The operation data can show the real operation condition of the target connection pool in a preset time interval, so that the connection pool parameters of the target connection pool can be adjusted according to the operation data, and the adjusted connection pool parameters are more close to the real operation condition of the target connection pool. The connection pool parameters comprise any one of core thread number, maximum thread number, idle thread survival time, a time unit corresponding to the idle thread survival time, a task queue, a thread factory and a rejection strategy.
Step S103, the adjusted connection pool parameters are sent to the client side, so that the client side configures the target connection pool based on the adjusted connection pool parameters.
In this embodiment, after the adjusted connection pool parameter is obtained, the adjusted connection pool parameter is sent to the client, so that the client configures the target connection pool.
In this embodiment, in the operation process of the target connection pool by the client, operation data of the target connection pool is obtained, and the operation data is sent to the configuration device, so that the configuration device adjusts the target connection pool based on the operation data, and because the operation data includes the number of times the target connection pool accesses the server in a preset time interval, the operation data can embody the service condition of the target connection pool, so that the adjusted connection pool parameters are more attached to the actual service condition of the target connection pool, the dynamic adjustment of the connection pool parameters of the target connection pool is realized, the correctness of the connection pool parameters is improved, and the management effect of the connection pool is further improved.
Fig. 3 is a flow diagram illustrating a method of connection pool management according to another exemplary embodiment. The execution main body of the connection pool management method provided by the application is a connection pool management device which is integrated in configuration equipment. As shown in fig. 3, the connection pool management method provided in this embodiment includes the following steps:
Step S201, receiving operation data sent by a client and directed against a target connection pool, where the target connection pool is a connection pool related to a target application, and the operation data includes the number of times that the target connection pool accesses a server in a preset time interval, where the server is used to provide background services for the target application.
In some embodiments, the implementation of step S201 is the same as that of step S101, and will not be described here again.
Illustratively, fig. 4 is a schematic diagram illustrating a relationship between a server and a connection pool, where the server is provided with a plurality of connection pools, as shown in fig. 4, including a connection pool a, a connection pool B, and the like, and the configuration center listens to operation data of the connection pools, where each connection pool has a user corresponding to it, such as user 1, user 2, user 3, user 4, and the like, where the user is a database connection user or a ssh connection user, and ssh refers to Secure Shell protocol (Secure Shell).
In this embodiment, after step S201, the configuration device adjusts, based on the operation data, the connection pool parameters corresponding to the target connection pool to obtain adjusted connection pool parameters, where the connection pool parameters are used to describe the target connection pool. Optionally, the connection pool parameters include core thread numbers. Correspondingly, based on the operation data, the implementation manner of adjusting the connection pool parameters corresponding to the target connection pool to obtain the adjusted connection pool parameters includes the following steps S202-S203.
Step S202, determining the ratio between the running data and the interval length corresponding to the preset time interval as the access frequency corresponding to the target connection pool, wherein the access frequency represents the frequency of the target connection pool accessing the server side.
The operation data comprises the times of accessing the server side by the target connection pool in a preset time interval, the times are more frequent, the times are less frequent, and accordingly, the frequency of accessing the server side by the target connection pool in the preset time interval can be represented between the operation data and the interval length corresponding to the preset time interval, so that the wallpaper can be determined to be the access frequency corresponding to the target connection pool.
Step S203, based on the access frequency, the number of core threads corresponding to the target connection pool is adjusted to obtain the adjusted number of core threads, and the access frequency is positively related to the number of core threads.
The larger the access frequency is, the more the target connection pool needs the resident threads, the larger the number of required core threads is, and the smaller the access frequency is, the smaller the target connection pool needs the resident threads, the smaller the number of required core threads is, and accordingly, the access frequency is positively related to the number of core threads. Therefore, the number of core threads corresponding to the target connection pool can be adjusted based on the access frequency. It should be noted that, the implementation manner of step S203 may be flexibly set by a technician as required, which is not limited in this embodiment. In an alternative implementation manner, the configuration device stores a corresponding relation between the access frequency and the core thread number in advance, the corresponding relation satisfies a condition that the access frequency and the core thread number are positively correlated, so that after the access frequency is determined, the core thread number corresponding to the determined access frequency is queried from the stored corresponding relation between the access frequency and the core thread number, and the core thread number is used as the adjusted core thread number.
In this embodiment, the greater the access frequency, the greater the demand of the target connection pool for resident threads, the greater the number of required core threads, and the smaller the access frequency, the smaller the demand of the target connection pool for resident threads, and the smaller the number of required core threads, so that the adjusted number of core threads can more satisfy the current running condition of the target connection pool by adjusting the number of core threads corresponding to the target connection pool based on the access frequency.
Step S204, the adjusted connection pool parameters are sent to the client side, so that the client side configures the target connection pool based on the adjusted connection pool parameters.
In some embodiments, the implementation of step S204 is the same as the implementation of step S103, and will not be described here again.
In the present application, the above-described embodiment describes a process in which the configuration device dynamically adjusts the connection pool parameters corresponding to the target connection pool during the operation of the target connection pool. Before running the target connection pool, the client needs to initialize the target connection pool, and accordingly, on the basis of the above embodiment, an initialization process of the target connection pool is described below.
In an alternative embodiment, before receiving the operation data for the target connection pool sent by the client, the connection pool management method further comprises the steps that the client sends an initialization request for the target connection pool to the configuration device when the connection requirement exists, correspondingly, the configuration device receives the initialization request for the target connection pool sent by the client, obtains initial connection pool parameters corresponding to the stored client, and sends the initial connection pool parameters to the client so that the client initializes the target connection pool according to the initial connection pool parameters.
When the client needs to execute tasks, the client can be considered to have connection requirements, and an initialization request for the target connection pool is sent to the configuration equipment. The task is a task realized by communicating with a server, for example, the task is to acquire data from a database, and the server is a server corresponding to the database. The related art loads and initializes the connection pool into the memory when the project is started, however, no task is usually submitted to the connection pool at this time, so that the connection in the connection pool is in an idle state, and unnecessary threads and memory overhead are caused. In this embodiment, the client connected to the server by using the connection pool method does not load and initialize the connection pool until the task needs to be executed when the project is started in a lazy loading manner, so as to reduce the phenomena of occupying threads and consuming memory and CPU (Central Processing Unit ) resources of the client when the service is idle.
In this embodiment, the configuration device stores the initial connection pool parameters corresponding to the client in advance, acquires the stored initial connection pool parameters after receiving the initialization request sent by the client, and sends the initial connection pool parameters to the client, so that the client can initialize the target connection pool according to the initial connection pool parameters, and resources of the client are saved in a lazy loading manner.
In the above optional embodiment, the configuration device stores the initial connection pool parameters corresponding to the target connection pool in advance, and in an optional embodiment, the process of determining the initial connection pool parameters includes the steps of receiving a registration request for the target connection pool sent by the client, the registration request carrying connection pool information corresponding to the target connection pool, storing the connection pool information in a registration information group corresponding to the server, determining the initial connection pool parameters corresponding to the target connection pool based on preset configuration information corresponding to the client, the maximum connection number corresponding to the server, and the calculation core number corresponding to the client, and storing the initial connection pool parameters.
The configuration device stores registration information groups corresponding to the service terminals respectively, and the registration information groups store connection pool information corresponding to at least one connection pool provided by the corresponding service terminal respectively. The configuration device stores preset configuration information in advance, and the preset configuration information includes preset idle thread survival time, a preset time unit corresponding to the preset idle thread survival time, a preset thread factory and a preset rejection policy. The preset configuration information may be set as needed, which is not limited in this embodiment. The maximum connection number corresponding to the server side refers to the maximum value of the connection number that the server side can establish.
In this embodiment, in the process of registering the target connection pool, the initial connection pool parameter corresponding to the target connection pool is determined, so as to provide data support for the initialization of the subsequent target connection pool.
In an alternative implementation of the above alternative embodiment, the connection pool information includes an identification of the server, which is illustratively an IP address. Correspondingly, the implementation mode of storing the connection pool information in the registration information group corresponding to the server side comprises the following two cases:
In the first case, if there is a registration information group corresponding to the IP address, the connection pool information is stored in the registration information group corresponding to the IP address. In this case, if there is a registration information group corresponding to an IP address, which indicates that a registration information group corresponding to a server to which the IP address belongs has been stored, connection pool information corresponding to a target connection pool may be stored in the registration information group. The group name of the registration information group may be an IP address of the server.
In the second case, if there is no registration information group corresponding to the IP address, a registration information group corresponding to the IP address is created, and the connection pool information is stored in the registration information group. In this case, if there is no registration information group corresponding to the IP address, which means that the registration information group corresponding to the server to which the IP address belongs is not stored, the registration information group corresponding to the IP address is created first, and then the connection pool information is stored in the created registration information group. Specifically, an IP address is used as a group name, a group is created, and ssh parameters are obtained from a server through a user name and a password corresponding to the server and stored in the group.
In the above optional implementation manner, the registration information set corresponding to the server uses the IP address corresponding to the server as the set name to store, when the connection pool information is stored, by first judging whether the registration information set corresponding to the IP address exists, the connection pool information is stored according to the corresponding situation, so that the occurrence of failure in storing the connection pool information is reduced.
In an optional implementation manner of the above optional embodiment, the preset configuration information includes preset idle thread survival time, a preset time unit corresponding to the preset idle thread survival time, a preset thread factory and a preset rejection policy, and the determining an implementation manner of the initial connection pool parameter corresponding to the target connection pool based on the preset configuration information corresponding to the client, the maximum connection number corresponding to the server and the calculation core number corresponding to the client correspondingly includes determining the initial core thread number and the initial maximum thread number by adopting a preset formula based on the maximum connection number corresponding to the server and the calculation core number corresponding to the client, and forming the initial connection pool parameter by the initial core thread number, the initial maximum thread number, the preset idle thread survival time, the preset time unit corresponding to the preset idle thread survival time, the preset thread factory and the preset rejection policy.
In the above optional implementation manner, the number of computing cores corresponding to the client can embody the performance of the client, the larger the number of computing cores is, the stronger the performance is, the smaller the number of computing cores is, the weaker the performance is, by adopting a preset formula, the initial core thread number and the initial maximum thread number can be accurately determined based on the maximum connection number corresponding to the server and the number of computing cores corresponding to the client, and on the basis, the initial connection pool parameter can be determined by combining the preset configuration information, so that the determination efficiency is higher.
Illustratively, the preset formulas include a formula for determining an initial core thread number and a formula for determining an initial maximum thread number. Wherein, the formula for determining the initial core thread number is shown in the following formula I:
Wherein Mn represents the initial core thread number corresponding to the nth client, cn represents the calculation core number corresponding to the nth client, n E (1, D), D represents the total number of clients, D is a positive integer greater than 1, and S represents the maximum connection number corresponding to the server.
In one possible case, if the number of calculation cores corresponding to a certain client is too large, the initial core number determined according to the formula one is too large, so that the client occupies more connection resources of the server, and other clients may not be separated from the connection resources.
Wherein Mn' represents the updated initial core thread number corresponding to the nth client, mn represents the initial core thread number corresponding to the nth client calculated by the formula I.
For example, the maximum connection number corresponding to the server is 1000, the calculation core number corresponding to the client a is 996, the calculation core number corresponding to the client B is 2, the initial core number corresponding to the client a is 995, the initial core number corresponding to the client B is 0 according to the first calculation of the formula, it can be seen that when the difference between the calculation core numbers corresponding to the client a and the client B is large, the client B may not be able to divide the connection resource, and on this basis, further calculation is performed according to the second calculation of the formula, the updated initial core number corresponding to the client a is 18, and the updated initial core number corresponding to the client B is 1.
On the basis of the formula I, the initial core thread number is further calculated through the formula II, so that each connection pool can be divided into at least one connection under the condition that the number of connections provided by a server is insufficient and distributed according to the performance of a client, and the reasonable core thread number can be obtained by each connection pool under the condition that the number of connections provided by the server is sufficient, and therefore the phenomenon that a large number of invalid threads are obtained by individual clients can be reduced.
Accordingly, the formula for determining the initial maximum thread number is referred to as formula three below:
Wherein Wn represents the initial maximum thread number corresponding to the nth client, and beta represents a random factor with a value of 0, -1 or 1.
And for the determination of the initial maximum thread number, adding the ratio of the thread number already obtained on the basis of the initial core thread number and taking the logarithm, acquiring the corresponding maximum thread number through the performance of the client under the condition of redundant connection number, adding a random factor, and carrying out pre-estimation judgment on the actual running condition after the connection pool, thereby reducing the capacity expansion requirement.
Wherein, the constraint conditions of the formula I and the formula II are thatThe constraint of equation three isThat is, the maximum connection number corresponding to the server is smaller than the total number of initial core thread numbers corresponding to the clients and smaller than the total number of maximum thread numbers, each client takes the form of a queue, preemptively acquires the connection number, and if the connection number is not acquired, the client needs to wait in a waiting queue and alarm. In this embodiment, the preset formula, the constraint formula, the related parameters of the preset formula and the related parameters of the constraint formula, the waiting queue and the alarm prompt interface are exposed for the user to modify according to the requirement, for example, to be exposed in a config (configuration file) form.
The above alternative implementation is illustrated by taking the example that the number of clients is greater than 1. When the number of clients is 1, after the initial core thread number and the initial maximum thread number are respectively determined by a formula for determining the initial core thread number and a formula for determining the initial maximum thread number, further calculation is needed, specifically, a half value of the determined initial core thread number is determined as a final initial core thread number, and a half value of the determined initial maximum thread number is determined as a final initial maximum thread number.
On the basis of the above optional implementation manner, optionally, if the user fixed connection number exists, before determining the initial core thread number and the initial maximum thread number based on the maximum connection number corresponding to the server and the calculation core number corresponding to the client by adopting a preset formula, determining a difference value between the maximum connection number corresponding to the server and the user fixed connection number as an updated maximum connection number, and then determining the initial core thread number and the initial maximum thread number based on the updated maximum connection number and the calculation core number corresponding to the client by adopting the preset formula. The user fixed connection number is the connection number which is set by the user according to the requirement in advance.
On the basis of the above optional implementation manner, optionally, after determining the initial connection pool parameter corresponding to the target connection pool based on the preset configuration information corresponding to the client, the maximum connection number corresponding to the server and the calculation core number corresponding to the client, the connection pool management method provided by the present application further includes the following two cases:
In the first case, if it is determined that the difference between the maximum connection number corresponding to the server and the fixed connection number of the user is smaller than the sum of the remaining connection pools, the target connection pool is placed into the waiting queue until it is determined that the difference between the maximum connection number corresponding to the server and the fixed connection number of the user is greater than or equal to the sum of the remaining connection pools, and the initial connection pool parameters corresponding to the target connection pool are determined again based on preset configuration information corresponding to the client, the maximum connection number corresponding to the server and the calculation core number corresponding to the client. The difference between the maximum connection number and the fixed connection number of the user is regarded as the available connection number provided by the server, if the difference is smaller than the sum of the number of the remaining connection pools, the available connection number is insufficient, connection cannot be allocated to the target connection pool at present, and the determined initial connection pool parameter is unavailable.
And in the second case, if the difference between the maximum connection number corresponding to the server and the fixed connection number of the user is determined to be greater than or equal to the sum of the number of the residual connection pools, executing the step of storing the initial connection pool parameters. Wherein, in case the number of available connections is sufficient, the determined initial connection pool parameters are available, the determined initial connection pool parameters are directly stored.
Fig. 5 is a schematic diagram of an initial connection pool parameter determining process according to an exemplary embodiment, where, as shown in fig. 5, a connection pool is initially registered, server information, that is, a maximum connection number is obtained, whether there is a user fixed connection number is first determined, if not, a preset formula is adopted, an initial connection pool parameter is determined based on the maximum connection number and a calculation core number corresponding to a client, then whether there is a sufficient connection number is determined, if there is a difference between the maximum connection number corresponding to the server and the user fixed connection number is determined as an updated maximum connection number, then a preset formula is adopted, an initial connection pool parameter is determined based on the updated maximum connection number and the calculation core number corresponding to the client, then whether there is a sufficient connection number is determined, if there is a sufficient connection number, the determined initial connection pool parameter is stored, and the connection pool configuration is refreshed, and if there is a insufficient connection number, the target connection pool is placed into a waiting queue, on the one hand, and on the other hand, the cluster is dynamically adjusted.
In the above alternative implementation manner, through the example and weight analysis, the connection resources are allocated to the target connection pool according to the performance of the client, when the connection resources are fewer, it can be ensured that the client can be allocated to a certain connection resource as much as possible, and the user can self-define the allocation through the user fixed connection number, so that the limited connection resources are more efficiently and fully utilized.
On the basis of the embodiment, the configuration equipment can also dynamically adjust the core thread number and the maximum thread number corresponding to the target connection pool at fixed time intervals. The time interval may be set as desired, for example, 5 seconds, 10 seconds, etc. In an alternative embodiment, the method for managing the connection pool provided by the application further comprises the steps of adopting a correction formula to respectively determine correction trend information and connection number correction values corresponding to the target connection pool, wherein the correction trend information indicates that the connection number is increased or decreased, adjusting the connection pool parameters corresponding to the target connection pool according to the correction trend information and the connection number correction values if a waiting queue is empty, wherein the waiting queue comprises a plurality of connection pools which are sequentially arranged and are to be determined, and placing the target connection pool into the waiting queue if the waiting queue is not empty, and sequentially determining the corresponding connection pool parameters for the connection pools in the waiting queue.
If the correction trend information indicates that the number of connections increases, the number of connections corresponding to the target connection pool needs to be expanded, and if the correction trend information indicates that the number of connections decreases, the number of connections corresponding to the target connection pool needs to be contracted. The connection number is contracted or expanded by adjusting parameters of the connection pool, specifically, the core thread number and the maximum thread number. The connection number correction value is a value which is specifically required to be adjusted, and the connection number correction value comprises a core thread number correction value and a maximum thread number correction value. Alternatively, the correction formula is referred to as formula four below:
Equation four:
Where P represents the difference between the current calculated weight and the sum of the last calculated weights, t represents the length of the last time period, ct represents the number of task submissions to the target connection pool in the last time period, S represents a set of recent time periods, S e {10,30,60,600....degree, P0 represents the sum of the weights calculated last time, c1 represents the core thread number correction value, and c2 represents the maximum thread number correction value. Constraint of equation four is In this embodiment, the correction formula and various parameters in the formula may be exposed for the user to modify as required.
The implementation mode of adjusting the connection pool parameters corresponding to the target connection pool according to the correction trend information and the connection number correction value comprises the steps of determining the sum value of the core thread number in the connection pool parameters and the core thread number correction value as updated core thread numbers and determining the sum value of the maximum thread number in the connection pool parameters and the maximum thread number correction value as updated maximum thread numbers if the correction trend information indicates that the connection number is increased, determining the difference value of the core thread number in the connection pool parameters and the core thread number correction value as updated core thread numbers if the correction trend information indicates that the connection number is decreased, and determining the difference value of the maximum thread number in the connection pool parameters and the maximum thread number correction value as updated maximum thread numbers.
For example, fig. 6 is a schematic diagram of a dynamic adjustment flow of parameters of a connection pool, as shown in fig. 6, where ssh related parameters of a server are refreshed and saved every 10 seconds, and then a correction formula is used to determine P, and determine whether P is greater than 0. When P is larger than 0, the target connection pool needs to be expanded, and when P is smaller than 0, the target connection pool needs to be contracted. And determining a connection number correction value corresponding to the target connection pool by using a correction formula, comparing the ssh related parameter with the ssh related parameter acquired last time, wherein the ssh related parameter comprises a maximum connection number, namely, the maximum connection number and the maximum connection number acquired last time are compared, determining a change value of the maximum connection number, namely, a difference value between the maximum connection number and the maximum connection number, and judging whether a waiting queue is empty, namely, whether the waiting queue has a connection pool waiting to be allocated. When the waiting queue is empty, the parameters of the connection pools are dynamically adjusted according to a strategy, the configuration of the connection pools is refreshed, specifically, if at least one connection pool needs to be expanded and the number of the left connection of the service end is larger than 0, the connection pool with higher c is preferentially allocated to the connection pool with higher c according to the proportion of c, wherein the maximum number of the connection corresponding to the service end minus the number of the used connection is the number of the left connection, if at least one connection pool needs to be expanded and the number of the left connection of the service end is 0, when the highest c value is higher than the lowest c value by 3 times of a threshold value, the connection number of the lowest c value is recovered and allocated to the connection pool with the highest c value, and if at least one connection pool needs to be contracted, the connection pool is contracted according to correction trend information and connection number correction value. When the connection pool exists in the waiting queue, judging whether the number of the left connection of the server is larger than the number of the connection pools waiting in the waiting queue. When the number of the remained connection is smaller than the number of the connection pools waiting in the waiting queue, the connection pools are sequentially allocated with one connection number according to the first-come first-served principle, and the remained connection pools which are not allocated with the connection number are continuously reserved in the waiting queue for waiting and alarm processing.
In the above alternative embodiment, a dynamic adjustment scheme is provided, where when P is greater than 0, it indicates that expansion is required, when P is less than 0, it indicates that contraction is required, and when the target connection pool continuously requires expansion or contraction twice, the connection pool parameters of the target connection pool are dynamically adjusted, where the dynamic adjustment of the core thread number and the maximum thread number considers the concurrency of the client, the concurrency of the target connection pool, the performance of itself, and the difference value from the last time, and constraint is performed by constraint conditions, and by combining the concurrency number of the last time period of the connection pool, the weight difference value, and the performance of the client, it calculates whether the connection pool needs to be expanded or contracted, and when the system resources are seriously insufficient, preferentially allocates connection resources for the connection pool with higher concurrency, so that the system resources of the client and the server can be fully utilized, and the connection pool can work normally as much as possible, thereby improving the overall resource utilization of the cluster.
In this embodiment, when a connection object needs to be obtained from a connection pool, whether an idle connection object exists is determined first, when an idle connection object exists, whether the current maximum number of threads and the number of core threads reach a threshold value is determined when no idle connection object exists, and the two parameters are exposed, so that the effect of dynamically adjusting the size of the connection pool can be achieved without shutting down the connection pool, if yes, waiting in a waiting queue is performed, if not, the thread factory is called to create the connection object, and after the connection object is used, the connection object is returned to the connection pool.
Most of currently used connection pool technologies load and initialize a connection pool into a memory when an item is started, and at this time, no task is usually submitted to the connection pool, so that connection is resident in an idle period, and unnecessary thread and memory overhead are caused. According to the scheme, under a distributed scene, a client end connected with a server end in a connection pool mode can not load and initialize the connection pool when a project is started in a lazy loading mode, and the connection pool is loaded and initialized until a task needs to be executed, so that the client end is prevented from occupying resources such as internal memory, CPU and the like when the service is idle. And when the client needs to initialize the connection pool, the client firstly takes ssh parameters corresponding to the server through configuration equipment, then determines the parameters of the connection pool through calculation, and transmits the parameters of the connection pool to the client, thereby completing the initial allocation of the connection pool. In the application, the client using the connection pool can send the operation condition of the connection pool to the configuration equipment, so that the configuration equipment dynamically adjusts the core thread number and the maximum thread number of the connection pool according to the operation condition of the connection pool of the client, thereby realizing the dynamic contraction, recovery and management of the connection pool. The application realizes configuration monitoring, instance and weight analysis, dynamic configuration strategy and dynamic recovery strategy through the container.
Fig. 8 is a schematic structural diagram of a connection pool management apparatus according to an exemplary embodiment, and as shown in fig. 8, in this embodiment, the connection pool management apparatus 300 may be disposed in a configuration device, and the connection pool management apparatus 300 includes:
The receiving module 301 is configured to receive operation data sent by a client and directed against a target connection pool, where the target connection pool is a connection pool related to a target application, and the operation data includes a number of times the target connection pool accesses a server in a preset time interval, where the server is configured to provide background service for the target application;
The adjustment module 302 is configured to adjust, based on the operation data, a connection pool parameter corresponding to the target connection pool, so as to obtain an adjusted connection pool parameter, where the connection pool parameter is used to describe the target connection pool;
And the sending module 303 is configured to send the adjusted connection pool parameter to the client, so that the client configures the target connection pool based on the adjusted connection pool parameter.
Optionally, the connection pool parameters include core thread numbers, an adjustment module 302 for:
Determining the ratio between the running data and the interval length corresponding to the preset time interval as the access frequency corresponding to the target connection pool, wherein the access frequency represents the frequency of the target connection pool accessing the server side;
and adjusting the number of core threads corresponding to the target connection pool based on the access frequency to obtain the adjusted number of core threads, wherein the access frequency is positively correlated with the number of core threads.
Optionally, the apparatus 300 further comprises an initialization module, configured to:
Receiving an initialization request for a target connection pool sent by a client;
acquiring stored initial connection pool parameters corresponding to a client;
And sending the initial connection pool parameters to the client so that the client initializes the target connection pool according to the initial connection pool parameters.
Optionally, the apparatus 300 further comprises a determining module, configured to:
Receiving a registration request for a target connection pool sent by a client, wherein the registration request carries connection pool information corresponding to the target connection pool;
storing the connection pool information into a registration information group corresponding to the server;
and determining initial connection pool parameters corresponding to the target connection pool based on preset configuration information corresponding to the client, the maximum connection number corresponding to the server and the calculation core number corresponding to the client, and storing the initial connection pool parameters.
Optionally, the connection pool information comprises an Internet Protocol (IP) address of the server, a determining module, a processing module and a processing module, wherein the determining module is used for:
if the registration information group corresponding to the IP address exists, the connection pool information is stored in the registration information group corresponding to the IP address;
if the registration information group corresponding to the IP address does not exist, the registration information group corresponding to the IP address is created, and the connection pool information is stored in the registration information group.
Optionally, the preset configuration information includes preset idle thread survival time, a preset time unit corresponding to the preset idle thread survival time, a preset thread factory and a preset rejection policy;
A determining module for:
Adopting a preset formula, and determining an initial core thread number and an initial maximum thread number based on the maximum connection number corresponding to the server and the calculation core number corresponding to the client;
And forming initial connection pool parameters by the initial core thread number, the initial maximum thread number, the preset idle thread survival time, a preset time unit corresponding to the preset idle thread survival time, a preset thread factory and a preset rejection strategy.
Optionally, the determining module is configured to:
If the difference between the maximum connection number corresponding to the server side and the user fixed connection number is determined to be smaller than the sum of the number of the remaining connection pools, placing the target connection pool into a waiting queue until the difference between the maximum connection number corresponding to the server side and the user fixed connection number is determined to be larger than or equal to the sum of the number of the remaining connection pools, and determining initial connection pool parameters corresponding to the target connection pool again based on preset configuration information corresponding to the client side, the maximum connection number corresponding to the server side and the calculation core number corresponding to the client side;
and if the difference value between the maximum connection number corresponding to the server and the fixed connection number of the user is larger than or equal to the sum of the number of the residual connection pools, storing the initial connection pool parameters.
Optionally, the adjusting module 302 is further configured to:
Adopting a correction formula to respectively determine correction trend information and a connection number correction value corresponding to the target connection pool, wherein the correction trend information indicates that the connection number is increased or decreased;
If the waiting queue is empty, adjusting the connection pool parameters corresponding to the target connection pool according to the correction trend information and the connection number correction value, wherein the waiting queue comprises a plurality of connection pools which are arranged in sequence and are used for determining the connection pool parameters;
If the waiting queue is not empty, the target connection pool is put into the waiting queue, and corresponding connection pool parameters are determined for the connection pools in the waiting queue in sequence.
The connection pool management device provided in this embodiment may execute the technical scheme of the corresponding method embodiment, and its implementation principle and technical effects are similar to those of the corresponding method embodiment, and will not be described in detail herein.
The configuration device in the embodiment of the application can be provided as an electronic device. Correspondingly, the embodiment of the application also provides electronic equipment. Electronic devices are intended for various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers.
Fig. 9 is a schematic diagram of an electronic device according to an exemplary embodiment. As shown in fig. 9, the electronic device 400 includes a processor 401 and a memory 402 and a transceiver 403 communicatively connected to the processor 401, respectively.
The memory 402 stores computer-executable instructions, and the transceiver 403 is used to transmit and receive data to and from a client or a server.
The processor 401 executes computer-executable instructions stored in the memory 402 to implement the connection pool management method provided by the present application.
In this embodiment of the present application, the memory 402 and the transceiver 403 are respectively connected to the processor 401 through a bus. The bus may be an industry standard architecture (Industry Standard Architecture, ISA) bus, an external device interconnect (PERIPHERAL COMPONENT INTERCONNECT, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
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 applications described and/or claimed herein. The various components are interconnected using different buses and may be mounted on a common motherboard or in other manners as desired.
In an exemplary embodiment, there is also provided a computer-readable storage medium having stored therein computer-executable instructions for implementing the connection pool management method provided by the present application when executed by a processor.
In an exemplary embodiment, a computer program product is also provided, comprising computer-executable instructions for implementing the connection pool management method provided by the application when the computer-executable instructions in the computer program product are executed by a processor.
It should be noted that, for simplicity of description, the foregoing method embodiments are all described as a series of acts, but it should be understood by those skilled in the art that the present application is not limited by the order of acts described, as some steps may be performed in other orders or concurrently in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are alternative embodiments, and that the acts and modules referred to are not necessarily required for the present application.
It should be further noted that, although the steps in the flowchart are sequentially shown as indicated by arrows, the steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least a portion of the steps in the flowcharts may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, the order in which the sub-steps or stages are performed is not necessarily sequential, and may be performed in turn or alternately with at least a portion of the sub-steps or stages of other steps or other steps.
It will be appreciated that the device embodiments described above are merely illustrative and that the device of the application may be implemented in other ways. For example, the division of the units/modules in the above embodiments is merely a logic function division, and there may be another division manner in actual implementation. For example, multiple units, modules, or components may be combined, or may be integrated into another system, or some features may be omitted or not performed.
In addition, each functional unit/module in each embodiment of the present application may be integrated into one unit/module, or each unit/module may exist alone physically, or two or more units/modules may be integrated together, unless otherwise specified. The integrated units/modules described above may be implemented either in hardware or in software program modules.
The integrated units/modules, if implemented in hardware, may be digital circuits, analog circuits, etc. Physical implementations of hardware structures include, but are not limited to, transistors, memristors, and the like. Unless otherwise indicated, the Processor may be any suitable hardware Processor such as a central processing unit (Central Processing Unit, CPU), a graphics Processor (Graphics Processing Unit, GPU), an Application-specific integrated Circuit (ASIC), a digital signal Processor (DIGITAL SIGNAL Processor, DSP), a programmable logic device (Programmable Logic Device, PLD), a field programmable gate array (Field Programmable GATE ARRAY, FPGA), a controller, microcontroller, microprocessor, or other electronic element. Unless specifically stated otherwise, the Memory may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as a U disk, random-Access Memory (RAM), static Random-Access Memory (SRAM), dynamic Random-Access Memory (DRAM), enhanced Dynamic Random-Access Memory (ENHANCED DYNAMIC Random-Access Memory, EDRAM), electrically erasable programmable Read-Only Memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ-Only Memory, EEPROM), erasable programmable Read-Only Memory (Erasable Programmable Read-Only Memory, EPROM), programmable Read-Only Memory (Programmable Read-Only Memory, PROM), read-Only Memory (ROM), variable Memory (RESISTIVE RANDOM ACCESS MEMORY, RRAM), high Bandwidth Memory HBM (High-Bandwidth Memory hard disk), hybrid Memory cube HMC (Hybrid Memory Cube), magnetic Memory, flash Memory, optical disk, mobile or various other programmable media.
The integrated units/modules may be stored in a computer readable memory if implemented in the form of software program modules and sold or used as a stand-alone product. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in whole or in part in the form of a software product stored in a memory, comprising several instructions for causing a computer device (which may be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method of the various embodiments of the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments. The technical features of the above embodiments may be combined in any way, and for brevity, all of the possible combinations of the technical features of the above embodiments are not described, but should be considered as the scope of the description
Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the application pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It is to be understood that the application is 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 effected without departing from the scope thereof. The scope of the application is limited only by the appended claims.