Search

CN-116248747-B - Connection resource allocation method and device for server connection pool

CN116248747BCN 116248747 BCN116248747 BCN 116248747BCN-116248747-B

Abstract

The application discloses a connection resource allocation method and device of a server connection pool, the method comprises the steps of determining a target client, determining the target number of connection allocation for the target client, executing connection allocation for the target client under the condition that the number of the idle connections in the server connection pool is smaller than the target number, allocating all idle connections to the target client, determining at least one client to be disconnected, of which the connection utilization rate is smaller than a first preset threshold value, from all connected clients, disconnecting a first number of connections from the connections being used by the at least one client to be disconnected, and allocating the disconnected first number of connections to the target client. The application extrudes the first number of connections from the connected clients with smaller connection utilization rate to be distributed to the target clients, which can provide connection resources for more clients on the premise of not influencing the service rate requirement of the extruded connected clients.

Inventors

  • XU SHUAI
  • LIU YONGCHENG
  • HU ZHIPENG
  • YUAN SISI
  • CHENG LONG

Assignees

  • 网易(杭州)网络有限公司

Dates

Publication Date
20260508
Application Date
20230220

Claims (11)

  1. 1. A connection resource allocation method of a server connection pool, where the server connection pool is used to provide connections to enable a server to communicate with a client, and the server connection pool includes a preset number of connections, and the method is characterized in that the method includes: Determining a target client, wherein the target client is a client which needs to establish new connection to meet the current service rate requirement; Determining a target number of connections allocated for the target client; executing connection allocation for the target client under the condition that the number of the idle connections in the server connection pool is smaller than the target number; The connection allocation comprises the following steps: Distributing all the idle connections to the target client; Determining at least one client to be disconnected, the connection utilization rate of which is smaller than a first preset threshold value, from all connected clients, wherein the connected clients are clients which are connected with a service end connection pool at the current moment and have established connection relations, and the connection utilization rate is the ratio of the total number of accesses of the connected clients within a preset time period from the current moment to the current connection quantity of the connected clients; disconnecting a first number of connections from the connections being used by the at least one client to be disconnected, and allocating the disconnected first number of connections to the target client, the first number being the difference between the target number and the number of free connections; The method further comprises the steps of: Acquiring the connection utilization rate of each connected client; Determining a connected client with the connection utilization rate smaller than a third preset threshold value in the connected clients as a first client, wherein the third preset threshold value is smaller than the first preset threshold value; For each first client, disconnecting a third number of connections from connections being used by the first client, where the current number of connections of the first client is greater than the minimum number of connections of the first client, the third number being the difference between the current number of connections of the first client and the minimum number of connections of the first client.
  2. 2. The method of claim 1, wherein prior to the determining the target client, the method further comprises: receiving a connection request sent by a request client, wherein the connection request is used for requesting to allocate connection so as to establish communication with the server, the connection request comprises a client identifier of the request client and a minimum connection number, and the minimum connection number is the connection number required by meeting the minimum service rate requirement of the request client; the determining the target client includes: Judging whether the sum of the minimum connection number of all connected clients and the minimum connection number of the request client is smaller than or equal to the preset number or not under the condition that the request client does not belong to the connected clients; If so, the request client is determined to be the target client.
  3. 3. The method of claim 1, wherein the determining the target client comprises: Acquiring the connection utilization rate of each connected client; And determining the connected client with the connection utilization rate larger than or equal to a second preset threshold value in the connected clients as a target client, wherein the second preset threshold value is larger than the first preset threshold value.
  4. 4. The method of claim 2, wherein the connection request further includes a maximum number of connections for the requesting client, the maximum number of connections being a number of connections required to meet a highest traffic rate requirement for the requesting client; The determining a target number of connections to be allocated for the target client includes: in case the target client does not belong to the connected client, determining the minimum number of connections of the target client as the target number of allocated connections of the target client, or And under the condition that the target client belongs to the connected client, determining the maximum to-be-disconnected connection quantity as the target quantity of connection allocation of the target client, wherein the maximum to-be-disconnected connection quantity is the difference value between the maximum connection quantity corresponding to the target client and the current connection quantity corresponding to the target client.
  5. 5. The method of claim 1, wherein disconnecting a first number of connections from connections being used by the at least one to-be-disconnected client comprises: determining the number of disconnectable connections of each client to be disconnected according to the minimum number of connections and the current number of connections of each client to be disconnected; acquiring the connection utilization rate of each client to be disconnected; and disconnecting a first number of connections from the connections being used by the at least one client to be disconnected based on the order of the connection usage from small to large.
  6. 6. The method of claim 5, wherein disconnecting a first number of connections from the connections being used by the at least one client to be disconnected based on the order of the connection usage from smaller to larger comprises: Sequencing all clients to be disconnected based on the sequence from small to large of the connection utilization rate to obtain a first sequence of all clients to be disconnected; And disconnecting a first number of connections from the connections being used by the at least one client to be disconnected according to the first ordering.
  7. 7. The method of claim 5, wherein disconnecting a first number of connections from the connections being used by the at least one client to be disconnected based on the order of the connection usage from smaller to larger comprises: And sequentially executing the following disconnection steps on the clients to be disconnected according to the order of the connection utilization rate from small to large until the total number of disconnected connections reaches the first number, and stopping executing the disconnection steps on the next client to be disconnected: Judging whether the number of disconnectable connections of the client to be disconnected is smaller than or equal to the number of disconnectable connections, wherein the number of disconnectable connections is a difference value between the first number and the number of disconnectable connections, and the number of disconnectable connections is the number of disconnectable connections in the process of executing the disconnection step; If yes, disconnecting a number of disconnectable connections of the client to be disconnected from the connections being used by the client to be disconnected; If not, disconnecting a second number of connections from the connections being used by the client to be disconnected, wherein the second number is a difference value between the number of disconnectable connections of the client to be disconnected and the number of connections to be disconnected.
  8. 8. The method of claim 6, wherein before the ordering of all clients to be disconnected based on the order of the connection usage from small to large, comprises: determining the service importance of all clients to be disconnected; Sequencing all clients to be disconnected according to the sequence from the small importance degree to the large importance degree of the service to obtain a second sequence of all clients to be disconnected; The step of sorting all clients to be disconnected based on the order of the connection utilization rate from small to large to obtain a first order of all clients to be disconnected, including: and in the second ordering, for all clients to be disconnected with the same service importance, sequentially adjusting the clients to be disconnected according to the order of the connection use ratio from small to large to obtain the first ordering of all the clients to be disconnected.
  9. 9. A connection resource allocation apparatus of a server connection pool, the server connection pool being configured to provide a connection to enable a server to communicate with a client, the server connection pool including a preset number of connections, the apparatus comprising: The first determining module is used for determining a target client, wherein the target client is a client which needs to establish new connection to meet the current service rate requirement; a second determining module, configured to determine a target number of connections allocated for the target client; the processing module is used for executing connection allocation aiming at the target client under the condition that the number of the hollow connections in the server connection pool is smaller than the target number; The processing module is specifically configured to: Distributing all the idle connections to the target client; determining at least one client to be disconnected, the connection utilization rate of which is smaller than a first preset threshold value, from all connected clients, wherein the connection utilization rate is the ratio of the total number of accesses of the connected clients within a preset time period from the current moment to the current connection quantity of the connected clients; disconnecting a first number of connections from the connections being used by the at least one client to be disconnected, and distributing the disconnected first number of connections to the target client, wherein the connected client is a client which has a connection relationship with the connections in the server connection pool at the current moment, and the first number is a difference value between the target number and the number of idle connections; the processing module is further configured to: Acquiring the connection utilization rate of each connected client; Determining a connected client with the connection utilization rate smaller than a third preset threshold value in the connected clients as a first client, wherein the third preset threshold value is smaller than the first preset threshold value; For each first client, disconnecting a third number of connections from connections being used by the first client, where the current number of connections of the first client is greater than the minimum number of connections of the first client, the third number being the difference between the current number of connections of the first client and the minimum number of connections of the first client.
  10. 10. An electronic device, the electronic device comprising: processor, and A memory for storing a data processing program, the electronic device being powered on and executing the program by the processor, performing the connection resource allocation method of the server connection pool according to any one of claims 1 to 8.
  11. 11. A computer-readable storage medium, in which a data processing program is stored, the program being executed by a processor to perform the connection resource allocation method of the server connection pool according to any one of claims 1 to 8.

Description

Connection resource allocation method and device for server connection pool Technical Field The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for allocating connection resources of a server connection pool, an electronic device, and a computer readable storage medium. Background With the rapid development of network technology and computer technology, most of internet applications currently adopt a structure that a client is connected with a server to realize that the client obtains information expected by a client user from the server. To avoid clients from repeating creation of server connections multiple times when they need to use the server, the server typically provides a number of connections to different clients in a connection pool. In the related art, when receiving a connection request from a client, a server judges whether a connection pool has an idle connection or not, if so, receives the connection request and allocates connection resources for the client, and if not, refuses the connection request. However, once the client that has established a connection with the server is in a busy state, all the connections in the server connection pool may be occupied at the same time, but if the client is not automatically disconnected after the client transitions to the idle state, the connections in the server connection pool are continuously occupied, which results in that the server connection pool cannot provide connection resources for other clients. Disclosure of Invention The application provides a method, a device, electronic equipment and a computer readable storage medium for allocating connection resources of a server connection pool, which are used for solving the problem that the connection in the server connection pool is continuously occupied under the condition that a client is not automatically disconnected after the client is converted into a service idle state in the prior art, so that the server connection pool cannot provide connection resources for other clients. In a first aspect, an embodiment of the present application provides a connection resource allocation method of a server connection pool, where the server connection pool is used to provide a connection to enable the server to communicate with a client, and the server connection pool includes a preset number of connections, and the method includes: Determining a target client, wherein the target client is a client which needs to establish new connection to meet the current service rate requirement; Determining a target number of connections allocated for the target client; executing connection allocation for the target client under the condition that the number of the idle connections in the server connection pool is smaller than the target number; The connection allocation comprises the following steps: Distributing all the idle connections to the target client; determining at least one client to be disconnected, the connection utilization rate of which is smaller than a first preset threshold value, from all connected clients, wherein the connection utilization rate is the ratio of the total number of accesses of the connected clients within a preset time period from the current moment to the current connection quantity of the connected clients; Disconnecting a first number of connections from the connections being used by the at least one client to be disconnected, and distributing the disconnected first number of connections to the target client, wherein the connected client is a client which has established a connection relationship with the connections in the server connection pool at the current moment, and the first number is a difference value between the target number and the number of idle connections. In a second aspect, an embodiment of the present application provides a connection resource allocation apparatus for a server connection pool, where the server connection pool is used to provide a connection to enable the server to communicate with a client, and the server connection pool includes a preset number of connections, and the apparatus includes: The first determining module is used for determining a target client, wherein the target client is a client which needs to establish new connection to meet the current service rate requirement; a second determining module, configured to determine a target number of connections allocated for the target client; the processing module is used for executing connection allocation aiming at the target client under the condition that the number of the hollow connections in the server connection pool is smaller than the target number; The processing module is specifically configured to: Distributing all the idle connections to the target client; determining at least one client to be disconnected, the connection utilization rate of which is smaller than a first preset threshold value, from all connecte