Method and apparatus for allocating connection resources of a server connection pool

By prioritizing the allocation of idle connections to target clients and disconnecting low-usage connections, the problem of server-side connection pool resource consumption is solved, achieving more efficient resource allocation and utilization.

CN116248747BActive Publication Date: 2026-05-08NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NETEASE (HANGZHOU) NETWORK CO LTD
Filing Date
2023-02-20
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

In existing technologies, if the client does not automatically disconnect after the business is idle, the server connection pool will be continuously occupied, and resources cannot be provided to other clients.

Method used

By determining the connection needs of the target client, idle connections are allocated first, and connections from clients with low connection usage are disconnected from the already connected clients to meet the needs of the target client, ensuring efficient utilization of server-side connection pool resources.

Benefits of technology

While ensuring the service speed requirements of connected clients, connection resources are provided to more clients, thus improving the resource utilization efficiency of the server-side connection pool.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116248747B_ABST
    Figure CN116248747B_ABST
Patent Text Reader

Abstract

The application discloses a connection resource allocation method and device for a server connection pool. The method comprises the following steps: determining a target client; determining a target number of connections allocated to the target client; in the case that the number of idle connections in the server connection pool is less than the target number, performing connection allocation for the target client; the connection allocation comprises the following steps: allocating all idle connections to the target client; determining at least one to-be-disconnected client with a connection usage rate less than a first preset threshold from the connected clients; disconnecting a first number of connections from the connections currently used by the at least one to-be-disconnected client, and allocating the disconnected first number of connections to the target client. The application squeezes out a first number of connections from the connected clients with a small connection usage rate and allocates the first number of connections to the target client, which can provide connection resources for more clients without affecting the business rate requirement of the squeezed-out connected clients.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and specifically to a method, apparatus, electronic device, and computer-readable storage medium for allocating connection resources in a server connection pool. Background Technology

[0002] With the rapid development of network and computer technologies, most internet applications now adopt a client-server connection structure to allow clients to obtain the information they expect from the server. To avoid clients repeatedly creating server connections when they need to use the server, the server typically provides a certain number of connections to different clients using a connection pool.

[0003] In related technologies, when a connection request is received from a client, the server determines whether there are idle connections in the connection pool. If there are idle connections, the server accepts the connection request and allocates connection resources to the client; if there are no idle connections, the server rejects the connection request.

[0004] However, if a client that has already established a connection with the server is in a busy state, all connections in the server's connection pool may be occupied simultaneously. But if the client does not automatically disconnect after it transitions to an idle state, the connections in the server's connection pool will remain occupied, thus preventing the server's connection pool from providing connection resources to other clients. Summary of the Invention

[0005] This application provides a method, apparatus, electronic device, and computer-readable storage medium for allocating connection resources in a server-side connection pool, in order to solve the problem in the prior art where connections in the server-side connection pool are continuously occupied when the client does not automatically disconnect after the client transitions to an idle state, thus preventing the server-side connection pool from providing connection resources to other clients.

[0006] In a first aspect, embodiments of this application provide a method for allocating connection resources in a server-side connection pool. The server-side connection pool is used to provide connections to enable communication between the server and the client. The server-side connection pool includes a preset number of connections. The method includes:

[0007] Identify the target client, which is the client that needs to establish a new connection to meet the current service rate requirements;

[0008] Determine the target number of connections to allocate to the target client;

[0009] If the number of idle connections in the server connection pool is less than the target number, connection allocation is performed for the target client.

[0010] The connection allocation includes the following steps:

[0011] Allocate all the idle connections to the target client;

[0012] From all connected clients, at least one client to be disconnected is determined whose connection utilization rate is less than a first preset threshold. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client.

[0013] Disconnect a first number of connections from the connections currently being used by the at least one client to be disconnected, and allocate the first number of disconnected connections to the target client, wherein the connected client is the client that has established a connection relationship with the connection pool of the server at the current time, and the first number is the difference between the target number and the number of idle connections.

[0014] Secondly, embodiments of this application provide a connection resource allocation device for a server-side connection pool. The server-side connection pool is used to provide connections to enable communication between the server and the client. The server-side connection pool includes a preset number of connections. The device includes:

[0015] The first determining module is used to determine the target client, which is a client that needs to establish a new connection to meet the current service rate requirements;

[0016] The second determining module is used to determine the target number of connections to be allocated to the target client;

[0017] The processing module is configured to perform connection allocation for the target client when the number of idle connections in the server connection pool is less than the target number.

[0018] The processing module is specifically used for:

[0019] Allocate all the idle connections to the target client;

[0020] From all connected clients, at least one client to be disconnected is determined whose connection utilization rate is less than a first preset threshold. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client.

[0021] Disconnect a first number of connections from the connections currently being used by the at least one client to be disconnected, and allocate the first number of disconnected connections to the target client, wherein the connected client is the client that has established a connection relationship with the connection pool of the server at the current time, and the first number is the difference between the target number and the number of idle connections.

[0022] Thirdly, embodiments of this application provide an electronic device, the electronic device comprising:

[0023] The memory and the processor are coupled;

[0024] The memory is used to store one or more computer instructions;

[0025] The processor is used to execute one or more computer instructions to implement the connection resource allocation method for the server connection pool as described in any of the first aspects above.

[0026] Fourthly, embodiments of this application provide a computer-readable storage medium storing one or more computer instructions, characterized in that the instructions are executed by a processor to implement the connection resource allocation method for the server connection pool as described in any of the first aspects above.

[0027] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the connection resource allocation method for the server connection pool as described in any of the first aspects above.

[0028] Compared with the prior art, this application has the following advantages:

[0029] The connection resource allocation method for the server connection pool provided in this application determines the target client, which is a client that needs to establish a new connection to meet the current business rate requirements; determines the target number of connections to be allocated to the target client; and performs connection allocation for the target client when the number of idle connections in the server connection pool is less than the target number. The connection allocation includes the following steps: allocating all idle connections to the target client; determining at least one client to be disconnected from the connected clients whose connection utilization rate is less than a first preset threshold, where the connection utilization rate is the ratio of the total number of accesses by the connected client within a preset time period from the current moment to the current number of connections of the connected client; disconnecting a first number of connections from the connections currently used by the at least one client to be disconnected, and allocating the disconnected first number of connections to the target client, where the connected client is a client that has established a connection relationship with the connection in the server connection pool at the current moment, and the first number is the difference between the target number and the number of idle connections.

[0030] To meet the current business speed requirements of target clients by establishing new connections, a target number of connections are allocated to the target clients. During connection allocation, priority is given to allocating idle connections from the server's connection pool to the target clients. Furthermore, if the number of idle connections is less than the target number, a first number of connections are squeezed out from all connected clients whose connection utilization is below a first preset threshold, and these first number of connections are then allocated to the target clients. This ensures that the business speed requirements of each squeezed-out connected client are met, while allowing the server's connection pool to allocate these squeezed-out connections to target clients with connection needs. This enables the server's connection pool to provide connection resources to more clients while maintaining the business speed requirements of currently connected clients, resulting in efficient utilization of connection resources in the pool. Attached Figure Description

[0031] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0032] Figure 1 This is a schematic diagram illustrating an application scenario of a connection resource allocation method for a server-side connection pool provided in the first embodiment of this application.

[0033] Figure 2 One of the flowcharts for the connection resource allocation method of the server connection pool provided in the second embodiment of this application;

[0034] Figure 3 A flowchart illustrating the connection allocation method for the server-side connection pool provided in this application;

[0035] Figure 4 The second flowchart illustrates the connection resource allocation method for the server connection pool provided in the second embodiment of this application.

[0036] Figure 5 This is a schematic diagram illustrating the process of disconnecting a first number of connections provided in the second embodiment of this application;

[0037] Figure 6 A flowchart illustrating the process of determining the first order of clients to be disconnected, provided in the second embodiment of this application;

[0038] Figure 7 The third flowchart illustrates the connection resource allocation method for the server connection pool provided in the second embodiment of this application.

[0039] Figure 8 A schematic diagram of the connection resource allocation device for the server connection pool provided in the third embodiment of this application;

[0040] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the fourth embodiment of this application.

[0041] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0042] To make the objectives, advantages, and features of this application clearer, the application will be described clearly and completely below in conjunction with the accompanying drawings and specific embodiments. In the following description, many specific details are set forth to provide a full understanding of this application. However, the described embodiments are only some, not all, of the embodiments of this application, and all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application.

[0043] It should be noted that in the description of this application, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance, or a specific order or sequence. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, the term "multiple" refers to two or more. The term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. The terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.

[0044] To facilitate understanding of the technical solution of this application, the relevant concepts involved in this application will be introduced first.

[0045] A client, or user terminal, is an application that provides a user interface, offers local services to clients (users), and runs on the user's terminal device, in contrast to a server.

[0046] A server is an application or device that provides services to clients. These services include, for example, providing data to clients and storing client data.

[0047] The relationship between the client and the server is as follows: the client sends a request to the server (i.e., the sender of the request instruction), and the server processes the request and sends a response back to the client (i.e., the responder of the request instruction).

[0048] With the rapid development of network and computer technologies, most internet applications now adopt a client-server connection structure to retrieve data desired by the client user from the server. This involves establishing a connection between the client and server to allow the client to query or manipulate the server. For example, when a user needs to retrieve data, the user sends a connection request to the server through the application in the client to request the establishment of a network connection. Once the network connection is established, the client can use this connection to send a data download request to the server. The server accepts the data download request and transmits the data to the client through the aforementioned network connection.

[0049] Furthermore, to avoid the performance overhead caused by frequent connection creation and release when clients need to use the server, the concept of server-side connection pooling emerged. The crucial role of connection pooling is particularly evident when the server provides services to multiple clients. The basic idea of ​​server-side connection pooling is to pre-create a certain number of server-side connections (i.e., connection objects) and store them in the pool during server initialization. The server-side connection pool is responsible for allocating, managing, and releasing these connections. When a client needs to access the server, the server-side connection pool allocates connection resources to the client. This allows client applications to reuse existing server-side connections instead of establishing new ones. After use, the client does not delete the connection but returns it to the server-side connection pool for the next connection request. This avoids the significant overhead of server-side connection initialization and release, thereby reducing the overall system response time and improving the connection efficiency between the client and the server.

[0050] When a new client (referring to a client that has not yet established any connection with the server) requests a service, it first needs to obtain a connection object from the server's connection pool. It then establishes a connection with this object to enable normal communication with the server. During the connection establishment process, all client access requests will directly reuse existing connections to send the request content to the server. For example, in a database connection pool, a client might send SQL statements to the database server through an existing connection, allowing the database server to perform relevant operations based on the SQL statements.

[0051] Generally, the number of connections in the server connection pool remains fixed under normal circumstances. In special cases, after a server hardware upgrade, the administrator can increase the number of connections in the connection pool based on the server's connection capacity or the client's connection needs after the hardware upgrade; or, if it is necessary to reserve some server resources for other uses, it is necessary to reduce the number of connections to free up hardware resources.

[0052] The prior art involved in this application and the problems existing in the prior art are described below:

[0053] In related technologies, when a connection request is received from a client, the server determines whether there are idle connections in the connection pool. If there are idle connections, the server accepts the connection request and allocates connection resources to the client; if there are no idle connections, the server rejects the connection request.

[0054] However, if a client that has already established a connection with the server is in a busy state, all connections in the server's connection pool may be occupied simultaneously. But if the client does not automatically disconnect after it transitions to an idle state, the connections in the server's connection pool will remain occupied, thus preventing the server's connection pool from providing connection resources to other clients.

[0055] To address the aforementioned problems and resolve the issue in existing technologies where connections in the server-side connection pool remain occupied even after the client transitions to an idle state, preventing the server-side connection pool from providing connection resources to other clients, this application provides a connection resource allocation method for a server-side connection pool, a corresponding connection resource allocation device for a server-side connection pool, an electronic device for implementing the connection resource allocation method for a server-side connection pool, and a computer-readable storage medium. The following embodiments provide a detailed description of the above method, device, electronic device, and computer-readable storage medium.

[0056] To make the objectives and technical solutions of this application clearer and more intuitive, the methods provided by the embodiments of this application will be described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for explaining this application and are not intended to limit this application. It is understood that the following embodiments may exist independently, and the embodiments and features described below may be combined with each other where there is no conflict between the various embodiments provided in this application. For the same or similar content, it will not be repeated in different embodiments. Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation.

[0057] This application provides a method, apparatus, electronic device, and computer storage medium for allocating connection resources in a server-side connection pool. Specifically, the connection resource allocation method for a server-side connection pool according to one embodiment of this application can be executed by a computer device, which can be a terminal device or a server, etc. The terminal device can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), etc. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms.

[0058] It should be noted that the following description of the technical solution provided in this application uses the server as the execution subject as an example. In other possible implementations, a control device located on the server can also be used as the execution subject to execute the technical solution provided in this application. The embodiments of this application do not limit the type of execution subject. Optionally, the control device can be implemented by software or by a combination of software and hardware.

[0059] Below, in conjunction with Figure 1 This paper introduces an application scenario for a connection resource allocation method for a server-side connection pool provided in the first embodiment of this application. Figure 1 This is a schematic diagram illustrating an application scenario of a connection resource allocation method for a server-side connection pool provided in the first embodiment of this application.

[0060] like Figure 1 As shown, it includes at least one client device 101, which can establish a connection with a server 102 via a network. The client device 101 can be any device with computing hardware, such as a mobile phone, tablet computer, desktop computer, or other terminal device, or it can be a server; this embodiment does not impose any restrictions. The server 102 can provide services to the client terminal 101 via a network. The server can be a mobile phone, tablet computer, desktop computer, or other terminal, or it can be a server; this embodiment does not impose any restrictions.

[0061] In this embodiment, the server 102 is further configured to manage a server connection pool, which contains multiple connections. The server connection pool can be part of a server process or process group, or it can be maintained by other processes or a group of processes. Furthermore, other processes (groups) can maintain multiple services simultaneously. For example, for different database services, MySQL may be given a capacity of 50 connections, and PostgreSQL a capacity of 100 connections. PostgreSQL is an object-relational database management system.

[0062] After receiving a connection request from the client device 101, the server 102 can determine whether to allocate connection resources to the client device 101, and when allocating connection resources to the client device 101, consider which connections to allocate to the client device 101, etc.

[0063] The aforementioned network can be a wireless network or a wired network. For example, wireless networks include wireless local area networks (WLAN), local area networks (LAN), cellular networks, 2G networks, 3G networks, 4G networks, 5G networks, etc. Different client devices can also connect to the server using their own Bluetooth networks or hotspot networks, or they can communicate with each other through the server and the communication network.

[0064] It should be understood that the above application scenarios are merely examples and are not intended to limit this application. Furthermore, for any content not disclosed in these application scenarios, please refer to the following embodiments.

[0065] Below, in conjunction with Figure 2 The connection resource allocation method for the server connection pool provided in the second embodiment of this application will be described. Figure 2 This is one of the flowcharts illustrating the connection resource allocation method for the server connection pool provided in the second embodiment of this application.

[0066] like Figure 2 As shown, the method includes:

[0067] S201. Identify the target client. The target client is the client that needs to establish a new connection to meet the current business rate requirements.

[0068] In this embodiment, a server-side connection pool is used to provide connections to enable communication between the server and the client. The server-side connection pool includes a preset number of connections.

[0069] Optionally, the number of connections in the server connection pool can be increased or decreased based on the amount of server resources and / or the client's demand for the server.

[0070] In this embodiment, the target client refers to a client that needs to establish a new connection to meet current service rate requirements. The target client can be an already connected client currently in a positive connection state with the server, or a client awaiting connection that is currently not connected to the server. The already connected client can acquire more connection resources to create more communication paths with the server, thereby meeting its higher service rate requirements; the client awaiting connection can acquire connection resources to establish communication with the server and obtain corresponding services from the server.

[0071] S202. Determine the target number of connections to be allocated to the target client.

[0072] In this embodiment, the target number of connections to be allocated to the target client can be determined based on factors such as the target client's service rate requirements, and / or connection utilization, and / or maximum service latency requirements. Wherein, when the target client is a currently connected client in a positive connection state with the server, the connection utilization is the ratio of the total number of times the connected client accesses the server within a preset time period from the current moment to the current number of connections of the connected client.

[0073] S203. If the number of idle connections in the server connection pool is less than the target number, perform connection allocation for the target client.

[0074] Optionally, if the number of idle connections in the server-side connection pool is greater than or equal to the target number, priority should be given to determining the target number of connections from the idle connections in the server-side connection pool and allocating them to the target client.

[0075] Optionally, if the number of idle connections in the server-side connection pool is less than the target number, connection allocation for the target client is performed, including as follows: Figure 3 Steps S2031-S2033 shown are as follows: Figure 3 This is one of the flowcharts illustrating the connection allocation method provided in the embodiments of this application, wherein:

[0076] S2031. Allocate all idle connections to the target client.

[0077] In this embodiment of the application, if the number of idle connections in the server connection pool is less than the target number, all currently idle connections in the server connection pool are preferentially allocated to the target client.

[0078] S2032. Determine at least one client to be disconnected from among the connected clients whose connection utilization rate is less than a first preset threshold. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client.

[0079] It is important to note that during the process of each connected client establishing a connection with the server, the total number of accesses by each connected client within a preset time period from the current moment will be recorded, and the number of connections currently used by each connected client will be recorded and updated in real time.

[0080] Based on step S2031 above, after allocating all idle connections in the server connection pool to the target client, a certain number of connections are squeezed out (released) from the connections currently used by connected clients with low connection usage and allocated to the target client. Here, a connected client is a client that has established a connection with a connection in the server connection pool at the current moment, i.e., a client currently in a connected state with the server.

[0081] Optionally, the connection utilization rate of each connected client is determined; among all connected clients, those with a connection utilization rate less than a first preset threshold are identified as clients to be disconnected, thus obtaining at least one client to be disconnected.

[0082] S2033. Disconnect a first number of connections from at least one connection being used by the client to be disconnected, and assign the first number of disconnected connections to the target client, where the first number is the difference between the target number and the number of idle connections in the server connection pool.

[0083] It should be noted that the idle connections in the server connection pool here refer to the idle connections in the server connection pool when step S203 is executed.

[0084] Based on step S2032 above, after identifying at least one client to be disconnected, it is necessary to further determine, without affecting the normal access to services from the server by each client to be disconnected, to disconnect a total of a first number of connections from the connections currently being used by at least one client to be disconnected, and to allocate the disconnected first number of connections to the target client.

[0085] In summary, based on the above step S2031, while allocating idle connections in the server connection pool to the target client, a first number of connections are squeezed out from at least one connected client with low connection usage and allocated to the target client. Therefore, the server connection pool completes the allocation of the target number of connections to the target client.

[0086] The connection resource allocation method for a server-side connection pool provided in this application aims to allocate a target number of connections to a target client to meet its current business rate requirements by establishing new connections. During the connection allocation process, priority is given to allocating idle connections from the server-side connection pool to the target client. Furthermore, when the number of idle connections is less than the target number, a first number of connections are squeezed out from all connected clients whose connection utilization is below a first preset threshold, and these first number of connections are then allocated to the target client. This ensures that the business rate requirements of each squeezed-out connected client are met, while allowing the server-side connection pool to allocate these squeezed-out connections to the target client with connection needs. This enables the server-side connection pool to provide connection resources to more clients while maintaining the business rate requirements of currently connected clients, resulting in efficient utilization of connection resources in the pool.

[0087] Below, in conjunction with Figure 4 The connection resource allocation method for the server connection pool provided in the second embodiment of this application will be further described. Figure 4 This is the second flowchart illustrating the connection resource allocation method for the server connection pool provided in the second embodiment of this application.

[0088] like Figure 4 As shown, the method includes:

[0089] S401. Identify the target client.

[0090] Below, we will provide illustrative examples of two possible implementation methods for determining the target client.

[0091] One possible implementation involves receiving a connection request from the requesting client before determining the target client. The connection request is used to request the allocation of a connection to establish communication with the server. The connection request includes the client identifier of the requesting client and the minimum number of connections required to meet the minimum service rate requirements of the requesting client. If the requesting client is not among the already connected clients, and the sum of the minimum number of connections of all already connected clients and the minimum number of connections of the requesting client is less than or equal to a preset number, the requesting client is determined as the target client.

[0092] The following example illustrates this optional implementation method.

[0093] Assume that when the target client sends a connection request to the server, the server may have already established connections with 5 clients. The minimum number of connections for each of these 5 connected clients is 6, 8, 5, 4, 3, and 7, respectively. Also assume that the server's connection pool stores 30 connections, i.e., the default number is 30.

[0094] For example, if the minimum number of connections for the requesting client is 5, the sum of the minimum number of connections for the requesting client and the minimum number of connections for the 5 already connected clients is 28 = 6 + 8 + 5 + 4 + 3 + 7 + 5. Therefore, knowing that the minimum number of connections for the requesting client and the sum of the minimum number of connections for all the already connected clients are less than or equal to a preset number, the server connection pool is allowed to allocate a connection to this requesting client to establish a connection with the server; that is, this requesting client is identified as the target client.

[0095] For example, if the minimum number of connections for the requesting client is 9, the sum of the minimum number of connections for the requesting client and the minimum number of connections for the 5 already connected clients is 32 = 6 + 8 + 5 + 4 + 3 + 7 + 9. This means that to guarantee the minimum service speed requirements of all connected clients, at least 32 connections are required. However, the server's connection pool only stores 30 connections. Therefore, considering that the minimum service speed requirements of each client cannot be guaranteed after connecting the requesting client to the server, to ensure that the minimum service speed requirements of the connected clients are always met, it is determined that the requesting client is not allowed to establish a connection with the server; that is, the requesting client is not identified as the target client.

[0096] In this implementation, the embodiment of this application considers that the server-side connection pool should be able to guarantee the minimum service rate requirement of each connected client, allocating at least the minimum number of connections corresponding to each connected client. In this case, when the requesting client is not among the connected clients, the system determines whether to identify the requesting client as the target client by judging whether the sum of the minimum number of connections for all connected clients and the minimum number of connections for the requesting client is less than or equal to the total number of connections in the server-side connection pool. Therefore, while meeting the minimum service rate requirement of connected clients, connection resources can be allocated to more new clients; and when considering whether to allocate connection resources to a new client, connection resources are only allocated to the new client if the total number of connections in the server-side connection pool is greater than or equal to the sum of the minimum number of connections for all currently connected clients and the minimum number of connections for the new client, so that the minimum service rate requirement of all clients using connection resources can be guaranteed.

[0097] Another possible implementation involves obtaining the connection utilization rate of each connected client, and identifying connected clients with a connection utilization rate greater than or equal to a second preset threshold as target clients. The second preset threshold is greater than a first preset threshold. Considering that a high current utilization rate for a connected client indicates a high service rate requirement, more connection resources can be allocated to such connected clients to meet their actual service rate needs.

[0098] Optionally, when more than two connected clients with connection utilization greater than or equal to a second preset threshold are detected, more connection resources are allocated to connected clients with higher business importance.

[0099] S402. Determine whether the target client is a connected client. If yes, proceed to step S403; otherwise, proceed to step S404.

[0100] In this embodiment of the application, during the process of each connected client establishing a connection with the server, information such as the client identifier of each connected client, the total number of accesses within a preset time period from the current time, and the number of connections currently used by each connected client are recorded and updated in real time are recorded.

[0101] S403. The maximum number of connections to be disconnected is determined as the target number of connections to be allocated to the target client. The maximum number of connections to be disconnected is the difference between the maximum number of connections corresponding to the target client and the current number of connections corresponding to the target client.

[0102] In this embodiment of the application, the connection request also includes the maximum number of connections for the requesting client, which is the number of connections required to meet the highest service rate requirements of the requesting client.

[0103] If the connection utilization rate of the target client is greater than or equal to the second preset threshold, the server connection pool will increase the number of connections allocated to the target client to the maximum number of connections corresponding to the target client, so as to meet the highest business rate requirements of the target client.

[0104] S404. Determine the minimum number of connections for the target client as the target number of connections to be allocated to the target client.

[0105] It should be noted that, for new clients, we consider meeting their minimum service rate requirements first, so the minimum number of connections for the target client is determined as the target number of connections allocated to the target client.

[0106] S405. Determine whether the number of idle connections in the server connection pool is greater than or equal to the target number. If yes, proceed to step S406; otherwise, proceed to step S407.

[0107] S406. Determine the target number of idle connections from all idle connections in the server connection pool and allocate them to the target client.

[0108] S407. Allocate all available connections to the target client.

[0109] In this embodiment of the application, if the number of idle connections in the server connection pool is less than the target number, all idle connections are preferentially allocated to the target client.

[0110] S408. Determine at least one client to be disconnected from among the connected clients whose connection utilization rate is less than a first preset threshold.

[0111] After allocating all idle connections to the target client in step S407, there is still a first number of connections remaining before the target number of connections can be allocated to the target client. Here, the first number is the difference between the target number and the total number of idle connections mentioned above.

[0112] In this embodiment, priority is given to disconnecting a first number of connections from those currently in use by connected clients with low connection utilization. The client's connection utilization rate is the ratio of the total number of accesses made by the client within a preset time period to the number of current connections, reflecting the workload of the client in obtaining information from the server. Therefore, at least one client with a connection utilization rate less than a first preset threshold is first identified from the connected clients to be disconnected.

[0113] Below, we will illustrate one possible implementation of the step "determine at least one client to be disconnected from among the connected clients whose connection usage is less than a first preset threshold" with a specific example.

[0114] Assume that there are 5 connected clients in a connected state with the server, and the minimum number of connections, current number of connections, and total number of accesses for each of the 5 connected clients are shown in Table 1.

[0115] Table 1:

[0116] Connected client identifier Minimum number of connections Current number of connections Total number of visits aa 2 5 995 bb 3 3 20 cc 4 6 32 dd 15 20 0 ee 1 7 66

[0117] As shown in Table 1, the connected client identified as 'aa' has a current number of connections and a total number of accesses of 5 and 995, respectively. Therefore, the connection object utilization rate of this connected client identified as 'aa' is busy_aa = total number of accesses / current number of connections = 995 / 5 = 199.0. Following this logic, we can deduce that the connection object utilization rate of the connected client identified as 'bb' is busy_bb = 20 / 3 = 6.67; the connection object utilization rate of the connected client identified as 'cc' is busy_cc = 32 / 6 = 5.33; the connection object utilization rate of the connected client identified as 'dd' is busy_dd = 0 / 20 = 0.0; and the connection object utilization rate of the connected client identified as 'ee' is busy_ee = 66 / 7 = 9.43.

[0118] Assuming that when the first preset threshold is 15, at least one client to be disconnected whose connection utilization is less than the first preset threshold includes: bb, cc, dd, and ee.

[0119] S409. Determine the number of disconnectable connections for each client based on the minimum number of connections and the current number of connections for each client to be disconnected.

[0120] Optionally, the difference between the current number of connections and the minimum number of connections for each client to be disconnected can be determined as the number of disconnectable connections for each client.

[0121] Below, based on Table 1 above, we determine the number of disconnectable connections for each of the four clients to be disconnected in Table 1.

[0122] As shown in Table 1, the client to be disconnected, identified as bb, has a minimum number of connections and a current number of connections of 3 and 3 respectively. Therefore, the number of disconnectable connections for the client to be disconnected, identified as aa, is disc_bb = current number of connections - minimum number of connections = 3 - 3 = 0. Following this logic, the client to be disconnected, identified as cc, has a number of disconnectable connections disc_cc = 6 - 4 = 2; the client to be disconnected, identified as dd, has a number of disconnectable connections disc_dd = 20 - 15 = 5; and the client to be disconnected, identified as ee, has a number of disconnectable connections disc_ee = 7 - 1 = 6.

[0123] S410: Obtain the connection utilization rate of each client to be disconnected.

[0124] Based on step S408, obtain the connection utilization rate of each client to be disconnected.

[0125] S411. Based on the order of connection usage from smallest to largest, disconnect a first number of connections from at least one connection being used by the client to be disconnected.

[0126] One possible implementation is to sort all clients to be disconnected in ascending order of connection usage to obtain a first sort of all clients to be disconnected; based on the first sort, disconnect a first number of connections from the connections currently being used by at least one client to be disconnected.

[0127] The following section, in conjunction with Tables 1 and 2 above and a specific example, provides an exemplary description of this possible implementation method.

[0128] Further explaining the examples described in steps S408 and S409, the connection utilization rates of the four clients to be disconnected (bb, cc, dd, ee) are 6.67%, 5.33%, 0.0%, and 9.43%, respectively. Sort all the clients to be disconnected in ascending order of connection utilization rate, resulting in the first sort: dd, cc, bb, ee. Simultaneously, the number of disconnectable connections for the four clients to be disconnected (dd, cc, bb, ee) in this first sort is 5, 2, 0, and 6%, respectively.

[0129] Assuming the initial number of target clients is 5, and a maximum of 3 connections can be disconnected from each client to be disconnected, one method to disconnect the initial number of connections is, for example, to disconnect 3 connections from client dd, then disconnect 2 connections from client cc, thus disconnecting 5 connections from the connections currently being used by the clients to be disconnected. Another example is to disconnect 2 connections from client dd, then 2 connections from client cc, then 1 connection from client ee, thus disconnecting 5 connections from the connections currently being used by the clients to be disconnected.

[0130] Another possible implementation, such as Figure 5 As shown, the implementation of step S411 may include steps S501-S506. Figure 5 This is a schematic diagram illustrating the process of disconnecting a first number of connections, provided in the second embodiment of this application.

[0131] S501. Sort all clients to be disconnected in ascending order of connection usage, and determine each client to be disconnected as the client to be disconnected for the current disconnection steps.

[0132] The following is an exemplary description of step S501, using a specific example.

[0133] Based on the example in step S411, all clients to be disconnected are sorted in ascending order of connection usage, resulting in the following first order: dd, cc, bb, ee. Therefore, each client to be disconnected is sequentially determined as the client to be disconnected in the current disconnection step according to this first order. For example, in the first round of executing steps S502-S505, the client to be disconnected is dd; in the second round of executing steps S502-S505, the client to be disconnected is cc. And so on, the clients to be disconnected in each round of executing steps S502-S505 can be determined according to this first order.

[0134] S502. Determine whether the number of disconnectable connections of the client to be disconnected is less than or equal to the number of disconnectable connections. If yes, proceed to step S503; otherwise, proceed to step S504.

[0135] In this embodiment of the application, the number of connections to be disconnected is the difference between the first number and the number of connections already disconnected, and the number of connections already disconnected is the number of connections that have been disconnected during the disconnection process.

[0136] For example, assuming the first quantity is 8, and no currently connected connections have been removed before step S411 is executed, then the number of connections to be disconnected = first quantity - number of connections already disconnected = 8 - 0 = 8. As another example, assuming the first quantity is 8, and 3 connections have been disconnected during the disconnection step, then the number of connections to be disconnected = first quantity - number of connections already disconnected = 8 - 3 = 5.

[0137] S503. Disconnect the number of disconnectable connections of the client to be disconnected from the connections currently in use by the client to be disconnected.

[0138] In this embodiment of the application, when the number of disconnectable connections of the client to be disconnected is less than or equal to the number of disconnectable connections, all disconnectable connections of the client with the lower connection usage are disconnected first.

[0139] For example, based on the number of disconnectable connections for the four clients to be disconnected (dd, cc, bb, ee) determined in step S411 above, in the first order, the numbers are 0, 2, 5, and 6 respectively. If the client to be disconnected in the current round of disconnection is dd, the number of disconnectable connections for dd is 0, meaning the current number of connections for dd is equal to the minimum number of connections corresponding to dd, and no further connections can be disconnected; otherwise, the minimum service speed requirement for dd cannot be effectively guaranteed. If the client to be disconnected in the current round of disconnection is bb, then 5 connections are disconnected from the connections currently used by bb. As another example, if the client to be disconnected in the current round of disconnection is cc, then 2 connections are disconnected from the connections currently used by cc.

[0140] S504. Disconnect a second number of connections from the connections currently in use by the client to be disconnected, where the second number is the difference between the number of disconnectable connections of the client to be disconnected and the number of connections to be disconnected.

[0141] In this embodiment of the application, if the number of disconnectable connections of the client to be disconnected is greater than the number of connections to be disconnected, then a second number of connections of the client to be disconnected will be disconnected, that is, the number of disconnected connections has reached the first number.

[0142] For example, based on the number of disconnectable connections for the client ee determined in step S411 above, if the client to be disconnected in the current disconnection step is ee, and the number of disconnectable connections is 1, then only one connection needs to be disconnected from the connections currently being used by the client ee.

[0143] S505. Determine whether the total number of disconnected connections has reached the first number. If yes, proceed to step S506. If no, proceed to step S501.

[0144] S506. Stop performing the disconnection procedure for the next client to be disconnected.

[0145] S412. Distribute the first number of disconnected connections to the target client.

[0146] The connection resource allocation method for a server-side connection pool provided in this application embodiment considers that the server-side connection pool should be able to guarantee the minimum service rate requirements of each connected client, allocating at least the minimum number of connections corresponding to each connected client. Therefore, while meeting the minimum service rate requirements of connected clients, connection resources can be allocated to more new clients. Simultaneously, if the current usage rate of a connected client is detected to be high, it indicates that the connected client has a high service rate requirement. By allocating more connection resources to this type of connected client, the actual service rate requirements of the connected client can be met.

[0147] Further, before step S411, as Figure 6 As shown, it also includes the following steps S601-S602, Figure 6 This is a flowchart illustrating the process of determining the first order of clients to be disconnected, as provided in the second embodiment of this application.

[0148] in,

[0149] S601. Determine the business importance of all clients to be disconnected.

[0150] In this application implementation, the connection request also includes information on the business importance of the requesting client.

[0151] S601. Sort all clients to be disconnected in ascending order of business importance to obtain a second sort of all clients to be disconnected.

[0152] Optionally, based on the above steps S601-S602, step S411 can be implemented as follows: In the second sorting, for each client to be disconnected with the same business importance, the clients to be disconnected are sorted in order of connection usage from smallest to largest to obtain the first sorting of all clients to be disconnected.

[0153] Below, with reference to Table 2 and a specific example, the implementation method for determining the first ranking is illustrated by way of example. (Note: The higher the business importance value corresponding to the client, the more important the business of that client is.)

[0154] Table 2

[0155] Client ID to be disconnected Business Importance Connection utilization bb 3 6.67 cc 5 5.33 dd 5 0.0 ee 8 9.43

[0156] Based on the information in Table 2, all clients to be disconnected are sorted in ascending order of business importance, resulting in a second sort: bb, cc, dd, ee. For clients cc and dd with the same business importance in this second sort, their order is adjusted according to ascending connection usage, resulting in the order: dd, cc. Therefore, replacing the order of clients cc and dd in the second sort with the adjusted order yields the first sort: bb, dd, cc, ee.

[0157] The connection resource allocation method for the server connection pool provided in this application prioritizes squeezing out connections from connected clients with lower business importance and lower connection usage. This ensures that the business rate requirements of connected clients are not affected, while freeing up more connections to allocate to clients that need them more, thereby improving the utilization rate of connection resources.

[0158] Below, in conjunction with Figure 7 The connection resource allocation method for the server connection pool provided in the second embodiment of this application will be further described. Figure 7 This is the third flowchart illustrating the connection resource allocation method for the server connection pool provided in the second embodiment of this application.

[0159] like Figure 7 As shown, the method includes:

[0160] S701, Obtain the connection utilization rate of each connected client.

[0161] Optionally, the connection usage rate of each connected client can be detected and obtained periodically.

[0162] S702. Among all connected clients, the connected client with a connection utilization rate less than a third preset threshold is identified as the first client, where the third preset threshold is less than the first preset threshold.

[0163] S703. For each first client, if the current number of connections of the first client is greater than the minimum number of connections of the first client, disconnect a third number of connections from the connections currently used by the first client. The third number is the difference between the current number of connections of the first client and the minimum number of connections of the first client.

[0164] The connection resource allocation method for the server connection pool provided in this application embodiment periodically detects the connection utilization rate of each connected client, squeezes out a portion of the connections from connected clients with low connection utilization rates, and then allocates the squeezed-out connections to clients with higher connection needs and / or clients with high business importance.

[0165] The connection resource allocation device for the server connection pool provided in this application is described below. The connection resource allocation device for the server connection pool described below can be referred to in correspondence with the connection resource allocation method for the server connection pool described above.

[0166] Figure 8 This is a schematic diagram of the connection resource allocation device for the server connection pool provided in the third embodiment of this application. Figure 8 As shown, the connection resource allocation device of the server connection pool includes: a first determining module 801, a second determining module 802, and a processing module 803.

[0167] The first determining module 801 is used to determine the target client, which is a client that needs to establish a new connection to meet the current service rate requirements;

[0168] The second determining module 802 is used to determine the target number of connections to be allocated to the target client;

[0169] Processing module 803 is used to perform connection allocation for the target client when the number of idle connections in the server connection pool is less than the target number;

[0170] The processing module 803 is specifically used for:

[0171] Allocate all the idle connections to the target client;

[0172] From all connected clients, at least one client to be disconnected is determined whose connection utilization rate is less than a first preset threshold. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client.

[0173] Disconnect a first number of connections from the connections currently being used by the at least one client to be disconnected, and allocate the first number of disconnected connections to the target client, wherein the connected client is the client that has established a connection relationship with the connection pool of the server at the current time, and the first number is the difference between the target number and the number of idle connections.

[0174] Optionally, before determining the target client, the first determining module 801 is further configured to:

[0175] The server receives a connection request sent by a client. The connection request is used to request the allocation of a connection in order to establish communication with the server. The connection request includes the client identifier of the requesting client and the minimum number of connections. The minimum number of connections is the number of connections required to meet the minimum service rate requirements of the requesting client.

[0176] The first determining module 801 is specifically used for:

[0177] If the requesting client is not among the connected clients, determine whether the sum of the minimum number of connections for all the connected clients and the minimum number of connections for the requesting client is less than or equal to the preset number.

[0178] If so, the requesting client is identified as the target client.

[0179] Optionally, the first determining module 801 is specifically used for:

[0180] Obtain the connection utilization rate of each of the connected clients;

[0181] Among the connected clients, those with a connection utilization rate greater than or equal to a second preset threshold are identified as target clients, where the second preset threshold is greater than the first preset threshold.

[0182] Optionally, the connection request may also include the maximum number of connections for the requesting client, wherein the maximum number of connections is the number of connections required to meet the highest service rate requirements of the requesting client;

[0183] The second determining module 802 is specifically used for:

[0184] If the target client is not among the connected clients, the minimum number of connections for the target client is determined as the target number of connections allocated to the target client; or,

[0185] If the target client is one of the connected clients, the maximum number of connections to be disconnected is determined as the target number of connections to be allocated to the target client. The maximum number of connections to be disconnected is the difference between the maximum number of connections corresponding to the target client and the current number of connections corresponding to the target client.

[0186] Optionally, the processing module 803 is specifically used for:

[0187] The number of disconnectable connections for each client to be disconnected is determined based on the minimum number of connections and the current number of connections for each client to be disconnected.

[0188] Obtain the connection utilization rate of each client to be disconnected;

[0189] Based on the connection usage in ascending order, a first number of connections are disconnected from the connections currently being used by the at least one client to be disconnected.

[0190] Optionally, the processing module 803 is specifically used for:

[0191] All clients to be disconnected are sorted in ascending order of connection usage to obtain the first sort of all clients to be disconnected;

[0192] According to the first sorting, a first number of connections are disconnected from the connections being used by the at least one client to be disconnected.

[0193] Optionally, the processing module 803 is specifically used for:

[0194] In order of increasing connection utilization, the following disconnection steps are performed on each client to be disconnected until the total number of disconnected connections reaches the first number, at which point the disconnection steps are stopped for the next client to be disconnected:

[0195] Determine whether the number of disconnectable connections of the client to be disconnected is less than or equal to the number of connections to be disconnected, wherein the number of connections to be disconnected is the difference between the first number and the number of already disconnected connections, and the number of already disconnected connections is the number of connections that have been disconnected during the execution of the disconnection step;

[0196] If so, disconnect the number of disconnectable connections of the client to be disconnected from the connections currently in use by the client to be disconnected;

[0197] If not, then disconnect a second number of connections from the connections currently being used by the client to be disconnected, the second number being the difference between the number of disconnectable connections of the client to be disconnected and the number of connections to be disconnected.

[0198] Optionally, before sorting all the clients to be disconnected based on the connection usage in ascending order, the processing module 803 is specifically used for:

[0199] Determine the business importance of all clients to be disconnected;

[0200] Sort all the clients to be disconnected in ascending order of business importance to obtain a second sort of all the clients to be disconnected;

[0201] The first sorting of all clients to be disconnected based on their connection usage in ascending order, to obtain a first sort of all clients to be disconnected, includes:

[0202] In the second sorting, for each client to be disconnected with the same business importance, the clients to be disconnected are sorted in order of connection usage from smallest to largest to obtain the first sorting of all the clients to be disconnected.

[0203] Optionally, the processing module 803 is further configured to:

[0204] Obtain the connection utilization rate of each of the connected clients;

[0205] The connected clients whose connection utilization rate is less than a third preset threshold are identified as the first clients, where the third preset threshold is less than the first preset threshold.

[0206] For each of the first clients, if the current number of connections of the first client is greater than the minimum number of connections of the first client, a third number of connections are disconnected from the connections currently used by the first client, where the third number is the difference between the current number of connections of the first client and the minimum number of connections of the first client.

[0207] The connection resource allocation device for the server connection pool provided in this application embodiment can be used to execute the technical solution of the above-described connection resource allocation method embodiment for the server connection pool. Its implementation principle and technical effect are similar, and will not be repeated here.

[0208] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the fourth embodiment of this application, as shown below. Figure 9 As shown, the electronic device 900 of this embodiment includes: a processor 901 and a memory 902; wherein

[0209] Memory 902 is used to store instructions executed by the computer;

[0210] The processor 901 is used to execute computer execution instructions stored in the memory to implement the various steps of the connection resource allocation method for the server connection pool in the above embodiments. For details, please refer to the relevant descriptions in the foregoing method embodiments.

[0211] Alternatively, the memory 902 can be either standalone or integrated with the processor 901.

[0212] When the memory 902 is set up independently, the electronic device also includes a bus 903 for connecting the memory 902 and the processor 901.

[0213] The fifth embodiment of this application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the technical solution provided in any embodiment of the connection resource allocation method for the server connection pool executed by the above-mentioned electronic device.

[0214] The sixth embodiment of this application also provides a computer program product, which includes a computer program stored in a readable storage medium. At least one processor of the electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program to cause the electronic device to execute the technical solution provided in any embodiment of the connection resource allocation method for the server connection pool described above.

[0215] It should be noted that for detailed descriptions of the apparatus, electronic devices, computer-readable storage media, and computer program products provided in the third, fourth, fifth, and sixth embodiments of this application, please refer to the relevant descriptions of the second embodiment of this application, which will not be repeated here.

[0216] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.

[0217] The integrated modules implemented as software functional modules described above can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) or a processor to execute some steps of the methods described in the various embodiments of this application.

[0218] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.

[0219] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.

[0220] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0221] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.

[0222] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0223] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A method for allocating connection resources in a server-side connection pool, wherein the server-side connection pool provides connections to enable communication between a server and a client, and the server-side connection pool includes a preset number of connections, characterized in that... The method includes: Identify the target client, which is the client that needs to establish a new connection to meet the current service rate requirements; Determine the target number of connections to allocate to the target client; If the number of idle connections in the server connection pool is less than the target number, connection allocation is performed for the target client. The connection allocation includes the following steps: Allocate all the idle connections to the target client; From all connected clients, at least one client to be disconnected is determined whose connection utilization rate is less than a first preset threshold. The connected client is the client that has established a connection relationship with the connection pool of the server at the current time. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client. Disconnect a first number of connections from the connections currently in use by the at least one client to be disconnected, and allocate the first number of disconnected connections to the target client, wherein the first number is the difference between the target number and the number of idle connections; The method further includes: Obtain the connection utilization rate of each of the connected clients; The connected clients whose connection utilization rate is less than a third preset threshold are identified as the first clients, where the third preset threshold is less than the first preset threshold. For each of the first clients, if the current number of connections of the first client is greater than the minimum number of connections of the first client, a third number of connections are disconnected from the connections currently used by the first client, where the third number is the difference between the current number of connections of the first client and the minimum number of connections of the first client.

2. The method according to claim 1, characterized in that, Before determining the target client, the method further includes: The server receives a connection request sent by a client. The connection request is used to request the allocation of a connection in order to establish communication with the server. The connection request includes the client identifier of the requesting client and the minimum number of connections. The minimum number of connections is the number of connections required to meet the minimum service rate requirements of the requesting client. The determination of the target client includes: If the requesting client is not among the connected clients, determine whether the sum of the minimum number of connections for all the connected clients and the minimum number of connections for the requesting client is less than or equal to the preset number. If so, the requesting client is identified as the target client.

3. The method according to claim 1, characterized in that, The determination of the target client includes: Obtain the connection utilization rate of each of the connected clients; Among the connected clients, those with a connection utilization rate greater than or equal to a second preset threshold are identified as target clients, where the second preset threshold is greater than the first preset threshold.

4. The method according to claim 2, characterized in that, The connection request also includes the maximum number of connections for the requesting client, which is the number of connections required to meet the highest service rate requirements of the requesting client. Determining the target number of connections to allocate to the target client includes: If the target client is not among the connected clients, the minimum number of connections for the target client is determined as the target number of connections to be allocated to the target client; or, If the target client is one of the connected clients, the maximum number of connections to be disconnected is determined as the target number of connections to be allocated to the target client. The maximum number of connections to be disconnected is the difference between the maximum number of connections corresponding to the target client and the current number of connections corresponding to the target client.

5. The method according to claim 1, characterized in that, Disconnecting a first number of connections from the connections currently being used by the at least one client to be disconnected includes: The number of disconnectable connections for each client to be disconnected is determined based on the minimum number of connections and the current number of connections for each client to be disconnected. Obtain the connection utilization rate of each client to be disconnected; Based on the connection usage in ascending order, a first number of connections are disconnected from the connections currently being used by the at least one client to be disconnected.

6. The method according to claim 5, characterized in that, The step of disconnecting a first number of connections from the connections currently used by the at least one client to be disconnected, based on the connection usage in ascending order, includes: All clients to be disconnected are sorted in ascending order of connection usage to obtain the first sort of all clients to be disconnected; According to the first sorting, a first number of connections are disconnected from the connections being used by the at least one client to be disconnected.

7. The method according to claim 5, characterized in that, The step of disconnecting a first number of connections from the connections currently used by the at least one client to be disconnected, based on the connection usage in ascending order, includes: In order of increasing connection utilization, the following disconnection steps are performed on each client to be disconnected until the total number of disconnected connections reaches the first number, at which point the disconnection steps are stopped for the next client to be disconnected: Determine whether the number of disconnectable connections of the client to be disconnected is less than or equal to the number of connections to be disconnected, wherein the number of connections to be disconnected is the difference between the first number and the number of already disconnected connections, and the number of already disconnected connections is the number of connections that have been disconnected during the execution of the disconnection step; If so, disconnect the number of disconnectable connections of the client to be disconnected from the connections currently in use by the client to be disconnected; If not, then disconnect a second number of connections from the connections currently being used by the client to be disconnected, the second number being the difference between the number of disconnectable connections of the client to be disconnected and the number of connections to be disconnected.

8. The method according to claim 6, characterized in that, Before sorting all the clients to be disconnected based on the connection usage in ascending order, the following steps are included: Determine the business importance of all clients to be disconnected; Sort all the clients to be disconnected in ascending order of business importance to obtain a second sort of all the clients to be disconnected; The first sorting of all clients to be disconnected based on their connection usage in ascending order, to obtain a first sort of all clients to be disconnected, includes: In the second sorting, for each client to be disconnected with the same business importance, the clients to be disconnected are sorted in order of connection usage from smallest to largest to obtain the first sorting of all the clients to be disconnected.

9. A connection resource allocation device for a server-side connection pool, wherein the server-side connection pool is used to provide connections to enable communication between a server and a client, and the server-side connection pool includes a preset number of connections, characterized in that... The device includes: The first determining module is used to determine the target client, which is a client that needs to establish a new connection to meet the current service rate requirements; The second determining module is used to determine the target number of connections to be allocated to the target client; The processing module is configured to perform connection allocation for the target client when the number of idle connections in the server connection pool is less than the target number. The processing module is specifically used for: Allocate all the idle connections to the target client; From all connected clients, at least one client to be disconnected is determined whose connection utilization rate is less than a first preset threshold. The connection utilization rate is the ratio of the total number of accesses of the connected client within a preset time period from the current time to the current number of connections of the connected client. Disconnect a first number of connections from the connections currently being used by the at least one client to be disconnected, and allocate the first number of disconnected connections to the target client. The connected client is the client that has established a connection with the connection pool of the server at the current time. The first number is the difference between the target number and the number of idle connections. The processing module is further configured to: Obtain the connection utilization rate of each of the connected clients; The connected clients whose connection utilization rate is less than a third preset threshold are identified as the first clients, where the third preset threshold is less than the first preset threshold. For each of the first clients, if the current number of connections of the first client is greater than the minimum number of connections of the first client, a third number of connections are disconnected from the connections currently used by the first client, where the third number is the difference between the current number of connections of the first client and the minimum number of connections of the first client.

10. An electronic device, characterized in that, The electronic device includes: Processor; and The memory is used to store a data processing program. After the electronic device is powered on and the processor runs the program, it executes the connection resource allocation method of the server connection pool as described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, The system stores a data processing program that is executed by a processor to perform the connection resource allocation method for the server connection pool as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Database connection optimization method and device based on cloud monitoring and related equipment

    CN109800067A

  • Database middleware and method for achieving connection between client and server by usingdatabase middleware

    CN112612834A