Service request initiating method and device
By obtaining and updating the connection information of cluster nodes and optimizing the selection and connection management of target cluster nodes, the problem of load increase in cluster nodes caused by load balancing algorithms is solved, and the efficiency of initiating service requests and system stability is improved.
Patent Information
- Application Number
- CN202410226723.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-28
- Publication Date
- 2025-08-29
AI Technical Summary
In the prior art, the load balancing algorithm easily sends remote call instructions to the same cluster node, resulting in an increase in the load of the cluster node, accumulating service requests, and low initiation efficiency.
By obtaining the connection information of the cluster nodes, determining the target cluster nodes based on the connection information, selecting idle or light-loaded nodes to send service requests, and creating connections when necessary, dynamically updating the connection information to ensure accuracy and timeliness.
It improves the efficiency of initiating service requests, effectively controls the load of cluster nodes, enhances the stability and reliability of the system, and saves system resources.
Smart Images

Figure CN120567862A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for initiating a service request. Background Art
[0002] Applications send service requests to external servers through pre-configured cluster nodes. For example, an enterprise microservices gateway application sends a remote call instruction to a cluster node, which then sends the service request to the target server. Typically, when setting up multiple cluster nodes, you first need to select cluster nodes using a load balancing algorithm such as a hashing algorithm or round-robin algorithm. Then, the remote call instruction is sent to the selected cluster node, which then sends the service request to the target server.
[0003] In the process of implementing the present invention, the inventors discovered that the prior art has at least the following problems:
[0004] Using a load balancing algorithm easily sends remote call instructions to the same cluster node, increasing the load on the cluster node, resulting in a backlog of service requests that need to be processed and low efficiency in initiating service requests. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and apparatus for initiating a service request, which can improve the efficiency of initiating a service request, effectively control the load of cluster nodes, and improve the stability and reliability of the system.
[0006] To achieve the above-mentioned object, according to a first aspect of an embodiment of the present invention, a method for initiating a service request is provided, comprising:
[0007] In response to receiving the service request, obtaining pre-set connection information of each cluster node;
[0008] determining a target cluster node among the cluster nodes according to the connection information, and applying for connection occupation from the target cluster node;
[0009] In the case that the application for connection occupation to the target cluster node is successful, the target cluster node is used to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0010] Optionally, the connection information includes: connection information between the cluster node and the server; and determining the target cluster node among the cluster nodes according to the connection information includes:
[0011] Determining, among the cluster nodes, a first cluster node that has target connection information for a target server corresponding to the service request;
[0012] Determining, based on the target connection information, the number of available connections, the number of used connections, the number of reserved connections, and the maximum number of connections between each first cluster node and the target server;
[0013] Determine, from the first cluster nodes, a second cluster node whose number of available connections is greater than the number of reserved connections, and use the second cluster node as the target cluster node;
[0014] If a second cluster node whose number of available connections is greater than the number of reserved connections is not determined, a third cluster node whose maximum number of connections is greater than the sum of the number of in-use connections and the number of reserved connections is determined among the first cluster nodes, and the third cluster node is used as the target cluster node.
[0015] Optionally, when it is not determined that a first cluster node having connection information for a target server corresponding to the service request exists, the method further includes:
[0016] Determine, based on the connection information, the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that each cluster node can carry, and the maximum number of connections of a single node of the target server;
[0017] A fourth cluster node whose maximum number of connections that can be carried is greater than or equal to the sum of the accumulated maximum number of connections and the maximum number of connections of a single node is determined among the cluster nodes, and the fourth cluster node is used as the target cluster node.
[0018] Optionally, before using the target cluster node to send the service request to the target server corresponding to the service request, the method further includes: obtaining a connection with the target server from a connection pool of the target cluster node; if a connection with the target server is not obtained from the connection pool of the target cluster node, obtaining configuration information of the target server, and establishing a connection between the target cluster node and the target server based on the configuration information;
[0019] Using the target cluster node to send the service request to the target server corresponding to the service request includes: using a connection between the target cluster node and the target server to send the service request to the target server.
[0020] Optionally, after sending the service request to the target server using the connection between the target cluster node and the target server, the method further includes:
[0021] Updating the connection information between the target cluster node and the target server;
[0022] It is determined whether the service request has been processed. If the service request has been processed, the updated connection information is updated again.
[0023] Optionally, before determining a target cluster node among the cluster nodes according to the connection information, the method further includes:
[0024] Determine the maximum number of connections and the number of connections in use of the target server according to the connection information;
[0025] It is determined that the maximum number of connections to the target server is greater than the number of connections in use to the target server.
[0026] Optionally, when the maximum number of connections to the target server is equal to the number of connections in use to the target server, the method further includes:
[0027] Repeat the following steps until it is determined that the maximum number of connections to the target server is greater than the number of connections in use of the target server: block the thread to which the service request belongs; when the blocking time of the thread is greater than or equal to a preset time threshold, wake up the thread and determine whether the maximum number of connections to the target server is greater than the number of connections in use of the target server.
[0028] According to a second aspect of an embodiment of the present invention, there is provided a device for initiating a service request, including:
[0029] An acquisition module, configured to acquire preset connection information of each cluster node in response to receiving a service request;
[0030] an occupation module, configured to determine a target cluster node among the cluster nodes according to the connection information, and apply to the target cluster node for connection occupation;
[0031] The request module is configured to, when the application for connection occupation to the target cluster node is successful, use the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0032] Optionally, the connection information includes: connection information between the cluster node and the server; and determining the target cluster node among the cluster nodes according to the connection information includes:
[0033] Determining, among the cluster nodes, a first cluster node that has target connection information for a target server corresponding to the service request;
[0034] Determining, based on the target connection information, the number of available connections, the number of used connections, the number of reserved connections, and the maximum number of connections between each first cluster node and the target server;
[0035] Determine, from the first cluster nodes, a second cluster node whose number of available connections is greater than the number of reserved connections, and use the second cluster node as the target cluster node;
[0036] If a second cluster node whose number of available connections is greater than the number of reserved connections is not determined, a third cluster node whose maximum number of connections is greater than the sum of the number of in-use connections and the number of reserved connections is determined among the first cluster nodes, and the third cluster node is used as the target cluster node.
[0037] Optionally, the device further comprises:
[0038] A first determining module is configured to determine, based on the connection information, the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that each cluster node can carry, and the maximum number of connections of a single node of the target server;
[0039] The screening module is configured to determine, from the cluster nodes, a fourth cluster node whose maximum number of connections that can be carried is greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node, and use the fourth cluster node as the target cluster node.
[0040] Optionally, the apparatus further comprises: a second acquisition module, configured to acquire a connection with the target server from a connection pool of the target cluster node; a creation module, configured to, if a connection with the target server is not acquired from the connection pool of the target cluster node, acquire configuration information of the target server, and establish a connection between the target cluster node and the target server according to the configuration information;
[0041] Using the target cluster node to send the service request to the target server corresponding to the service request includes: using a connection between the target cluster node and the target server to send the service request to the target server.
[0042] Optionally, the device further comprises:
[0043] A first updating module, configured to update the connection information between the target cluster node and the target server;
[0044] The second updating module is configured to determine whether the service request has been processed, and if the service request has been processed, to update the updated connection information again.
[0045] Optionally, the device further comprises:
[0046] A second determining module is used to determine the maximum number of connections and the number of used connections of the target server according to the connection information;
[0047] The determination module is configured to determine whether the maximum number of connections to the target server is greater than the number of connections in use to the target server.
[0048] Optionally, the device further comprises:
[0049] A repeated determination module is used to repeatedly execute the following steps until it is determined that the maximum number of connections to the target server is greater than the number of connections in use of the target server: blocking the thread to which the service request belongs; when the blocking time of the thread is greater than or equal to a preset time threshold, waking up the thread and determining whether the maximum number of connections to the target server is greater than the number of connections in use of the target server.
[0050] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, including:
[0051] one or more processors;
[0052] a storage device for storing one or more programs,
[0053] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.
[0054] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0055] An embodiment of the above invention has the following advantages or beneficial effects: determining the target cluster node based on the connection information of the cluster node, and using the target cluster node to send a service request to the target server can improve the efficiency of initiating service requests, effectively control the load of the cluster node, and improve the stability and reliability of the system; determining the priority between cluster nodes according to the connection information, and determining the target cluster node according to the priority, can improve the screening efficiency of the cluster node, reduce the load pressure of the cluster node, and preferentially allocate service requests to idle cluster nodes, so as to improve the efficiency of initiating service requests; reusing connections in the connection pool, and creating a connection according to the configuration information when no connection exists, can save system resources, avoid frequent establishment of connections with the target server, and improve the efficiency of initiating service requests; updating the connection information after sending the service request and processing the service request, can ensure dynamic update of the connection information, so that the connection information is accurate and timely; blocking and waking up the thread where the service request is located according to the connection information, can avoid the accumulation of a large number of service requests in the cluster node, reduce the load of the cluster node, ensure the stability and reliability of the system, and save system resources.
[0056] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.
[0058] Figure 1 is a schematic diagram of the main process of the method for initiating a service request according to an embodiment of the present invention;
[0059] Figure 2 is a schematic diagram of connection information according to a reference embodiment of the present invention;
[0060] Figure 3 is a schematic diagram of the main process of sending a service request to a target server according to a reference embodiment of the present invention;
[0061] Figure 4 is a schematic diagram of a system architecture of a method for initiating a service request according to a reference embodiment of the present invention;
[0062] Figure 5 is a schematic diagram of the main process of screening target cluster nodes according to a reference embodiment of the present invention;
[0063] Figure 6 1 is a schematic diagram of the main process of a method for initiating a service request according to a reference embodiment of the present invention;
[0064] Figure 7 is a schematic diagram of main modules of a device for initiating a service request according to an embodiment of the present invention;
[0065] Figure 8 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0066] Figure 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0067] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0068] It should be noted that in the technical solution of the present invention, the collection, use, storage, sharing and transfer of user personal information involved are in compliance with the provisions of relevant laws and regulations, and it is necessary to inform the user and obtain the user's consent or authorization. When applicable, the user's personal information is de-identified and / or anonymized and / or encrypted.
[0069] Applications send service requests to external servers through pre-configured cluster nodes. For example, an enterprise microservices gateway application sends a remote call instruction to a cluster node, which then sends the service request to the target server. Typically, when setting up multiple cluster nodes, you first need to select cluster nodes using a load balancing algorithm such as a hashing algorithm or round-robin algorithm. Then, the remote call instruction is sent to the selected cluster node, which then sends the service request to the target server.
[0070] Using a load balancing algorithm can easily send remote call instructions to the same cluster node, increasing the cluster node load, resulting in a backlog of service requests that need to be processed, and low efficiency in initiating service requests; long connections are usually established between cluster nodes and external servers. In the case of insufficient requests, most long connections cannot receive service requests, resulting in resource consumption.
[0071] In view of this, according to a first aspect of an embodiment of the present invention, a method for initiating a service request is provided.
[0072] Figure 1 FIG is a schematic diagram of the main process of the method for initiating a service request according to an embodiment of the present invention. Figure 1 As shown, the method for initiating a service request according to an embodiment of the present invention mainly includes the following steps S101 to S103.
[0073] Step S101 : in response to receiving a service request, obtaining preset connection information of each cluster node.
[0074] An application sends a service request to the execution entity of an embodiment of the present invention. This service request is forwarded to the target server via a pre-configured cluster node, which then processes the service request. One or more cluster nodes are pre-configured, each of which is a server that communicates with the target server.
[0075] After receiving the service request, the execution entity of the embodiment of the present invention obtains the connection information of each cluster node. Each cluster node has corresponding connection information. The connection information is the connection information between the cluster node and the server. The connection information includes: the maximum number of connections supported by the cluster node (that is, the maximum number of connections that can be maintained in a connected state at the same time), the maximum number of connections supported by the server, the number of connections between the cluster node and each server, the cumulative connection time of each connection, the request sending frequency of each connection, etc.
[0076] It should be noted that the connection information is dynamically updated. The executive body of the embodiment of the present invention updates the connection information according to the connection status between the cluster node and the server. For example, when a new connection is established between the cluster node and the server, the number of connections of the cluster node in the connection information is increased, and the cumulative connection time of the new connection in the connection information is updated at regular intervals. For another example, after the cluster node and / or server undergoes a system upgrade (for example, a hardware upgrade or a software upgrade), more connections can be established between the cluster node and the server. The executive body of the embodiment of the present invention updates the maximum number of connections that the cluster node and / or server can support in the connection information. For another example, if a cluster node or a server is deactivated, the executive body of the embodiment of the present invention will delete or hide the connection information related to the deactivated cluster node or server.
[0077] Exemplarily, the pre-set cluster nodes include: cluster node A1, cluster node A2, cluster node A3, and the pre-set servers include: server B1, server B2, server B3; after receiving the service request, the connection information obtained by the execution subject of the embodiment of the present invention includes: the maximum number of connections supported by cluster node A1 is 10, the maximum number of connections supported by cluster node A2 is 8, the maximum number of connections supported by cluster node A3 is 12, there are 2 connections between cluster node A1 and server B1, and the cumulative connection time is 10 minutes and 30 minutes respectively, there is 1 connection between cluster node A2 and server B3, and the cumulative connection time is 20 minutes, and in the past 1 hour, cluster node A1 sent 10 service requests to the server, cluster node A2 sent 20 service requests to the server, and cluster node A3 sent 5 service requests to the server.
[0078] Obtaining the connection information of each cluster node can quickly and accurately determine the connection status of each cluster node and the server, providing a data basis for sending service requests later, thereby improving the efficiency of sending service requests; dynamically updating connection information can ensure the accuracy and timeliness of connection information, further ensuring the efficiency of sending and processing service requests.
[0079] Step S102: determining a target cluster node among the cluster nodes according to the connection information, and applying for connection occupation to the target cluster node.
[0080] After obtaining the connection information, the execution entity of an embodiment of the present invention determines a target cluster node from the cluster nodes based on the connection information. For example, the execution entity of an embodiment of the present invention determines the corresponding target server based on the service request. The connection information includes the number of active connections between each cluster node and the target server. The cluster node with the smallest number of connections is selected as the target cluster node. This reduces the load on the cluster nodes and prevents excessive connections between a cluster node and the target server. For another example, the connection information includes the time since the last connection was established for each cluster node. The cluster node with the largest time is selected as the target cluster node. This reduces the frequency of connection establishment between the cluster nodes and the server, prevents a cluster node from frequently establishing connections, reduces cluster node overhead, and improves connection establishment efficiency. For another example, the connection between a cluster node and a server is terminated after a period of inactivity. The connection information includes the number of active connections between the cluster node and the server and the number of idle connections. The cluster node with an idle connection to the target server is selected as the target cluster node. This allows for reuse of connections between the cluster nodes and the server, conserves cluster node resources, prevents frequent connection establishment between the cluster nodes and the server, and improves the efficiency of initiating service requests.
[0081] After determining the target cluster node, the execution subject of the embodiment of the present invention sends a connection occupation application to the target cluster node, that is, applies for connection occupation to the target cluster node. The application for connection occupation indicates that the execution subject of the embodiment of the present invention requests to pre-occupy the connection between the target cluster node and the target server. For example, in the case where there is an idle connection between the target cluster node and the target server, the idle connection is occupied. For another example, in the case where there is a used connection between the target cluster node and the target server, the used connection is occupied, and waits for the used connection to be converted to an idle connection. For another example, in the case where there is no connection between the target cluster node and the target server, one connection number of the target cluster node is occupied. For example, the maximum number of connections of the target cluster node is 10, and the number of established connections is 5. Then, after applying for connection occupation to the target cluster node, the number of established connections is set to 6, including one occupied connection number. It should be noted that the number of established connections is less than or equal to the maximum number of connections.
[0082] It should be noted that the results of applying for connection occupation to the target cluster node include: success and failure. When the service request initiation method described in the embodiment of the present invention is executed concurrently, there are multiple execution entities of the embodiment of the present invention applying for connection occupation to the same target cluster node according to different service requests. When the number of concurrent applications is greater than the maximum number of connections of the target cluster node, the results of some applications are successful, and the results of other applications are unsuccessful.
[0083] Determining the target cluster node based on the connection information can reduce the load pressure and resource overhead of the cluster node and improve the efficiency of establishing connections; applying for connection occupation from the target cluster node can ensure that the connection is established within the capacity of the target cluster node, avoid excessive accumulation of service requests in the cluster node, improve the efficiency of initiating service requests, and reduce the load on the cluster node.
[0084] According to a reference embodiment of the present invention, the connection information includes: connection information between cluster nodes and servers, specifically, connection information between each cluster node and one or more servers, and connection information between each server and one or more cluster nodes. Based on the connection information, when determining the target cluster node in the cluster node, first determine the first cluster node in the cluster node that has target connection information for the target server corresponding to the service request. Specifically, query the connection information for target connection information including the server code of the target server. Each target connection information corresponds to a cluster node, and the queried cluster node is used as the first cluster node. This indicates that a connection has been established between the first cluster node and the target connection information, and that a connection pool with the target server exists in the first cluster node.
[0085] Then, based on the target connection information, the number of available connections, pre-occupied connections, and maximum connections between each first cluster node and the target server is determined. The connection information between the cluster node and the server includes: the number of available connections, the number of connections in use, the number of pre-occupied connections, and the maximum number of connections, where the maximum number of connections indicates the maximum number of connections that can be established between the cluster node and the server, and the maximum number of connections is limited by the configuration and performance of the cluster node and the server. The number of available connections indicates the number of idle connections between the cluster node and the server, that is, the number of connections that can be used directly. The number of pre-occupied connections indicates the number of connections that have been applied for and successfully occupied. The number of pre-occupied connections indicates the number of idle connections that are waiting and will be used to send requests after waiting, which is equivalent to the number of idle connections pre-occupied. The number of in-use connections indicates the number of connections currently in use between the cluster node and the server. The sum of the number of available connections and the number of connections in use is less than or equal to the maximum number of connections, and the number of pre-occupied connections is less than or equal to the maximum number of connections.
[0086] A second cluster node is identified in the first cluster node as having a larger number of available connections than the number of reserved connections. The larger number of available connections indicates that, given that each reserved connection corresponds to an available connection, some available connections remain, and the number of reserved connections can be increased. Therefore, the second cluster node is selected as the target cluster node. Because the larger number of available connections is than the number of reserved connections, the execution subject of this embodiment of the present invention will successfully apply to the second cluster node for connection occupation.
[0087] If no second cluster node with a greater number of available connections than the number of reserved connections is identified, that is, the number of available connections in all connection information is less than or equal to the number of reserved connections, a third cluster node is identified in the first cluster node whose maximum connection number is greater than the sum of the number of active connections and the number of reserved connections. This indicates that after deducting the number of active connections and the number of reserved connections, some maximum connections remain, and the number of reserved connections can be increased. Therefore, the third cluster node is selected as the target cluster node. Since the maximum connection number is greater than the number of active connections and the number of reserved connections, the execution subject of this embodiment of the present invention will successfully apply for connection occupation to the third cluster node.
[0088] Figure 2 FIG. 1 is a schematic diagram of connection information according to a reference embodiment of the present invention. For example, Figure 2As shown, the connection information 201 represents the connection information between the cluster node and the server, and the connection information includes the maximum number of connections, the number of available connections, the number of connections in use and the number of pre-occupied connections; when the server address of the target server is "http: / / www.xxx.com", the connection information of the target server is connection information No. 1 and connection information No. 2, thereby determining that the cluster node address of the first cluster node includes "10.189.uuu.10" and "10.189.vvv.11"; since the number of available connections corresponding to the cluster node address "10.189.uuu.10" is equal to the number of pre-occupied connections, and the number of available connections corresponding to the cluster node address "10.189.vvv.11" is greater than the number of pre-occupied connections, the cluster node corresponding to the cluster node address "10.189.vvv.11" is used as the target cluster node (i.e., the second cluster node). When the server address of the target server is "http: / / www.yyy.com", the connection information including the target server is connection information No. 3 and connection information No. 4, thereby determining that the cluster node addresses of the first cluster node include "10.189.uuu.10" and "10.189.www.12"; since the number of available connections corresponding to the above two cluster node addresses are both less than or equal to the number of pre-occupied connections, the second cluster node cannot be screened out; and since the maximum number of connections corresponding to the cluster node address "10.189.www.12" is equal to the sum of the number of connections in use and the number of pre-occupied connections, and the maximum number of connections corresponding to the cluster node address "10.189.uuu.10" is greater than the sum of the number of connections in use and the number of pre-occupied connections, the cluster node corresponding to the cluster node address "10.189.uuu.10" is used as the target cluster node (i.e., the third cluster node).
[0089] Determining the target cluster node based on the connection information can improve the screening efficiency of the cluster nodes, reduce the load pressure of the cluster nodes, and preferentially allocate service requests to idle cluster nodes, thereby improving the efficiency of initiating service requests.
[0090] According to another reference embodiment of the present invention, in the case where the first cluster node that has connection information for the target server corresponding to the service request has not been determined, that is, there is no connection pool with the target server in all cluster nodes, and no connection is established between all cluster nodes and the target connection information, the method further includes: determining the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that can be carried by each cluster node, and the maximum number of connections of a single node of the target server based on the connection information. Among them, the cumulative maximum number of connections represents the sum of the maximum number of connections assigned by the cluster node to different servers that have established connections, each cluster node corresponds to a maximum number of connections that can be carried, and the maximum number of connections that can be carried is greater than or equal to the cumulative maximum number of connections. The target server has multiple nodes. The execution subject of the embodiment of the present invention will send a service request between the target cluster node and a node of the target server. Each node corresponds to a maximum number of connections of a single node, that is, the cluster node is connected to the nodes included in the server.
[0091] A fourth cluster node is identified among the cluster nodes, whose maximum number of connections can be greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node. The fact that the maximum number of connections can be greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node indicates that the cluster node can still carry more connections. After the cluster node establishes a connection with the target server, the number of reserved connections can be increased. Therefore, the fourth cluster node is selected as the target cluster node. Because the maximum number of connections that can be carried is greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node, the execution subject of this embodiment of the present invention will successfully apply to the fourth cluster node for connection occupation.
[0092] Figure 2 FIG. 1 is a schematic diagram of connection information according to a reference embodiment of the present invention. For example, Figure 2As shown, the connection information 202 includes: the cluster node address and the maximum number of connections that can be carried corresponding to each cluster node, each cluster node establishes a connection with one or more servers, and the total number of connections established does not exceed the maximum number of connections that can be carried. In the connection information 201, the number of available connections and the number of connections in use of the same cluster node are added to obtain the cumulative maximum number of connections of the cluster node. It should be noted that the maximum number of connections in the connection information 201 is the maximum number of connections allocated to each server by the cluster node within the limit of the maximum number of connections that can be carried, that is, the maximum number of connections that can be established between the cluster node and each server; the connection information 203 includes: the server address of the server, the maximum number of connections, the number of nodes and the maximum number of connections of a single node; when the server address of the target server is "http: / / www.zzz.com", by querying the connection information 201, it is determined that all cluster nodes have not established a connection with the target server, then according to the connection information, a cluster node whose maximum number of connections that can be carried is greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections of a single node is selected as the target cluster node.
[0093] Determining the target cluster node based on the connection information can improve the screening efficiency of the cluster nodes, reduce the load pressure of the cluster nodes, and preferentially allocate service requests to idle cluster nodes, thereby improving the efficiency of initiating service requests.
[0094] According to another reference embodiment of the present invention, before determining the target cluster node from the cluster nodes based on the connection information, the method further includes: determining the maximum number of connections and the number of connections in use of the target server based on the connection information. The connection information includes: the maximum number of connections and the number of connections in use of the target server, the maximum number of connections indicating the maximum number of connections that the target server can support, the target server establishing connections with one or more cluster nodes, the sum of the number of connections being less than or equal to the maximum number of connections of the target server, and the number of connections in use indicating the number of connections that have been established and are in use between the target server and the one or more cluster nodes.
[0095] The execution subject of the embodiment of the present invention compares the maximum number of connections of the target server and the number of connections in use of the target server. In the case that the maximum number of connections of the target server is greater than the number of connections in use of the target server, it is determined that more connections can be established between the target server and the cluster node, or there are idle connections between the target server and the cluster node that can be used by the execution subject of the embodiment of the present invention, and after obtaining the above determination result, the target cluster node is screened in the cluster nodes. In the case that the maximum number of connections of the target server is equal to the number of connections in use of the target server, it means that the number of connections established between the target server and the cluster node has reached the maximum number of connections it can bear, and each connection of the target server is in use, then it is determined that there is no connection between the target server and the cluster node that can be used by the execution subject of the embodiment of the present invention, and therefore, the subsequent process is not executed, that is, the target cluster node is not screened in the cluster nodes.
[0096] Figure 2 FIG. 1 is a schematic diagram of connection information according to a reference embodiment of the present invention. For example, Figure 2 As shown, if the target server's server address is "http: / / www.yyy.com," and the number of active connections to each node connected to the target server is equal to the maximum number of connections, then it is determined that subsequent processes are temporarily unavailable, and the target cluster node is not selected from the cluster nodes. It should be noted that the execution subject of this embodiment of the present invention receives an information edit request or an information delete request and edits or deletes connection information 201, connection information 202, and connection information 203.
[0097] By judging whether the target server has a connection for use by the execution subject of the embodiment of the present invention based on the connection information, it is possible to avoid unsuccessful connection application, avoid the accumulation of a large number of service requests in the cluster node, reduce the load of the cluster node, ensure the stability and reliability of the system, and save system resources.
[0098] According to another reference embodiment of the present invention, when the maximum number of connections of the target server is equal to the number of connections in use of the target server, it means that the target server can no longer connect to a new connection and all the connections that have been established are in use. The method further includes: repeatedly executing the following steps until it is determined that the maximum number of connections of the target server is greater than the number of connections in use of the target server: blocking the thread to which the service request belongs, suspending the thread to which the service request belongs; when the blocking time of the thread is greater than or equal to a preset time threshold, waking up the thread, and re-judging whether the maximum number of connections of the target server is greater than the number of connections in use of the target server. The status of each connection includes: idle state, use state, etc. The connection in use corresponds to a number of connections in use, and the connection in idle state corresponds to a number of available connections. After a connection is used up, when the state of the connection is converted from the use state to the idle state, the corresponding number of connections in use is reduced by one, and the corresponding number of available connections is increased by one. The maximum number of connections that can be established is the maximum number of connections, and the sum of the number of connections in use and the number of available connections is equal to the number of connections that have been established. Therefore, after the thread is blocked or suspended for a period of time, the number of available connections and the number of connections in use may change. When the maximum number of connections of the target server is greater than the number of connections in use of the target server, stop executing the above steps, jump out of the loop, and determine whether more connections can be established between the target server and the cluster node, or whether there are still idle connections between the target server and the cluster node that can be used by the execution subject of the embodiment of the present invention. After obtaining the above determination result, the target cluster node is screened in the cluster nodes.
[0099] It should be noted that, in the process of a thread being blocked or suspended, the executing subject of the embodiment of the present invention detects the maximum number of connections and the number of connections in use of the target server. When the maximum number of connections of the target server is greater than the number of connections in use, it indicates that connection resources have been released, that is, at least one connection that was previously in use has now been converted to a connection in an idle state. The executing subject of the embodiment of the present invention actively wakes up the blocked or suspended thread without waiting for the blocking time to time out.
[0100] For example, the maximum number of connections of the target server is 20, and the number of connections in use of the target server is also 20. Since the maximum number of connections of the target server is equal to the number of connections in use of the target server, the thread to which the service request belongs is blocked and waits for 1 minute. After 1 minute, the thread to which the service request belongs is awakened. At this time, the maximum number of connections of the target server is 20, and the number of connections in use of the target server becomes 15. Since the maximum number of connections of the target server is greater than the number of connections in use of the target server, it means that more connections can be established between the target server and the cluster node, or there are idle connections between the target server and the cluster node that can be used by the execution subject of the embodiment of the present invention. After obtaining the above judgment result, the target cluster node is screened in the cluster nodes; it should be noted that if within 1 minute when the thread is blocked, the execution subject of the embodiment of the present invention detects that the maximum number of connections of the target server is greater than the number of connections in use, it means that connection resources have been released and there are currently idle connections, then the blocked thread is directly awakened, and then the target cluster node is screened in the cluster nodes.
[0101] Blocking and waking up the thread where the service request is located based on the connection information can avoid the accumulation of a large number of service requests in the cluster node, reduce the load of the cluster node, ensure the stability and reliability of the system, and save system resources.
[0102] Step S103 : When the connection occupation application to the target cluster node is successful, the target cluster node is used to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0103] When the application for connection occupation to the target cluster node is successful, a remote call instruction is sent to the target cluster node, and the target cluster node is used to send a service request to the target server. The target cluster node and the target server are connected using HTTP (HyperText Transfer Protocol). The target cluster node packages the service request as an HTTP request and sends it to the target server. The target server that receives the service request processes the service request and returns the processing result of the service request to the cluster node. The execution subject of the embodiment of the present invention queries the return result of the service request in the cluster node, and returns the return result to the application that generated the service request.
[0104] Exemplarily, the execution subject of an embodiment of the present invention initiates an RPC (Remote Procedure Call) call to a target cluster node. The target cluster node uses the method in the client programming toolkit org.apache.http.client.HttpClient that supports the HTTP protocol to send the service request to the target server via an HTTP request. The target server processes the service request and receives the processing result of the service request returned by the target server. For example, the service request is "update inventory data" and the processing result is "inventory data updated successfully". For another example, the service request is "query a list of products that meet the conditions", and the processing result includes: the information "data query successful" and product data that meets the query conditions.
[0105] Using remote procedure calls and HTTP requests can improve the efficiency of initiating service requests, ensure the stability and reliability of initiating service requests, and facilitate improving the processing efficiency of service requests.
[0106] According to one reference embodiment of the present invention, before using the target cluster node to send a service request to the target server corresponding to the service request, the method further includes: obtaining a connection to the target server from the target cluster node's connection pool. Each cluster node has a corresponding connection pool, which is used to create, manage, and reclaim connections between the cluster node and the server. The connection pool includes idle connections, in-use connections, and so on. Specifically, the execution subject of this embodiment of the present invention obtains an idle connection established with the target server from the target cluster node's connection pool.
[0107] If a connection to the target server is not obtained from the connection pool of the target cluster node, the configuration information of the target server is obtained. The configuration information is used to establish a connection between the target cluster node and the target server. The configuration information includes: the network address of the target server, the port number for establishing the connection, the network connection protocol used, the user name and password required to establish the connection, etc. Based on the above configuration information, a connection is created between the target cluster node and the target server. The newly created connection is an idle connection. The execution subject of the embodiment of the present invention uses the idle connection between the target cluster node and the target server to send a service request to the target server.
[0108] Figure 3 FIG. 1 is a schematic diagram of the main process of sending a service request to a target server according to a reference embodiment of the present invention. Figure 3As shown, the execution entity of the embodiment of the present invention selects a target cluster node from the cluster nodes, obtains an idle connection with the target server from the connection pool of the target cluster node, determines whether there is a connection in the connection pool that meets the above conditions, and if so, uses the obtained connection to send a service request to the target server. Otherwise, a connection is created between the target cluster node and the target server, and a service request is sent to the target server using the newly created connection, receiving the request result of the service request, and returning the request result to the generator of the service request. The execution entity of the embodiment of the present invention uses methods in the client connection pool management toolkit org.apache.http.impl.conn.PoolingHttpClientConnectionManager that supports the HTTP protocol to manage the connection pool in the cluster nodes and create and recycle connections in the connection pool.
[0109] Reusing connections in the connection pool and creating connections based on configuration information when no connections exist can save system resources, avoid frequent connection establishment with the target server, and improve the efficiency of initiating service requests.
[0110] According to another reference embodiment of the present invention, after using the connection between the target cluster node and the target server to send the service request to the target server, the method also includes: updating the connection information between the target cluster node and the target server, specifically, reducing the number of available connections and the number of pre-occupied connections between the target cluster node and the target server, and increasing the number of in-use connections between the target cluster node and the target server.
[0111] The execution subject of the embodiment of the present invention monitors the request result of the service request. When receiving or querying the request result of the service request, it determines that the service request has been processed, and then updates the updated connection information again. Specifically, the number of connections in use between the target cluster node and the target server is reduced, and the number of available connections between the target cluster node and the target server is increased.
[0112] For example, Table 1 is the target connection information between the target cluster node and the target server. Specifically, when the execution subject of the embodiment of the present invention determines the target cluster node, the number of available connections between cluster node C and the target server is 10, the number of in-use connections is 5, and the number of pre-occupied connections is 5. Since the number of available connections is greater than the number of pre-occupied connections, cluster node C is determined to be the target cluster node. After the execution subject of the embodiment of the present invention applies for connection occupation to the target cluster node and the application is successful, each of the previous pre-occupied connections occupies one available connection, and the available connections are converted into in-use connections, so that the available connections are equal to the number of available connections of the previous node minus the number of pre-occupied connections of the previous node, that is, (10- 5)=5, the number of connections in use is equal to the number of connections in use of the previous node plus the number of pre-occupied connections of the previous node, that is, (5+5)=10, the number of pre-occupied connections becomes 1, indicating that the execution subject of the embodiment of the present invention successfully applies for connection occupation; after sending a service request to the target server, the pre-occupied connection number occupies one available connection number, and the available connection number is converted into the number of connections in use, so that the number of available connections minus 1 becomes 4, the number of connections in use plus 1 becomes 11, and the number of pre-occupied connections minus 1 becomes 0; after receiving the request result of the service request, the processing process of this service request ends, and the connection between the target cluster node and the target server is no longer used, so that the number of available connections plus 1 becomes 5, and the number of connections in use minus 1 becomes 10.
[0113] Table 1
[0114]
[0115] After the service request is sent and the service request is processed, the connection information is updated to ensure dynamic updating of the connection information, making the connection information accurate and timely.
[0116] Figure 4 FIG is a schematic diagram of a system architecture of a method for initiating a service request according to a reference embodiment of the present invention. Figure 4As shown, each application includes one or more application nodes, and each application node corresponds to a load balancing component. The load balancing component is used to manage the connection information between the cluster node and the server, screen the target cluster node, and initiate a remote call to the target cluster node. The load balancing component stores the connection information in the Redis database and sends an RPC call request to the target cluster node. The cluster node includes a connection pool management component and a connection pool. The connection pool is used to manage the connection between the cluster node and the server. The cluster node stores the connection pool size, capacity, creation time, connection time, status, usage frequency and other data in the connection pool in the Redis database, and uses the connection in the connection pool to send an HTTP request to the server. The server includes one or more nodes, and the server node is used to receive service requests, process service requests, and return the request results of the service requests; the user sends a configuration request to the execution body of the embodiment of the present invention to configure the connection information and connection pool related information stored in Redis.
[0117] Figure 5 FIG. 1 is a schematic diagram of the main process of screening target cluster nodes according to a reference embodiment of the present invention. Figure 5 As shown, the execution subject of the embodiment of the present invention obtains the connection information between the cluster node and the server, determines whether the connection of the target server is full and occupied, and if so, blocks the thread to which the service request belongs. In the case of blocking timeout, wakes up the thread, and then continues to judge until the connection of the target server is full and occupied; then, based on the connection information, screens out the target cluster node from the cluster nodes, applies for connection occupation to the target cluster node, determines whether the application for connection occupation is successful, and if the application for connection occupation is successful, initiates a remote call request to the target cluster node, and if the application for connection occupation is unsuccessful, re-acquires the connection information between the cluster node and the server, and repeats the above steps until the application for connection occupation is successful.
[0118] Figure 6 FIG. 1 is a schematic diagram of the main process of a method for initiating a service request according to a reference embodiment of the present invention. Figure 6 As shown, the method for initiating the service request may include:
[0119] Step S601, in response to receiving a service request, obtaining pre-set connection information between each cluster node and the server, and determining a target server corresponding to the service request;
[0120] Step S602: determine whether there is target connection information with the target server. If yes, jump to step S603; otherwise, jump to step S607.
[0121] Step S603: determining the number of available connections, the number of used connections, the number of reserved connections, and the maximum number of connections between each first cluster node and the target server according to the target connection information;
[0122] Step S604, determine whether the number of available connections is greater than the number of reserved connections, if so, jump to step S610, otherwise jump to step S605;
[0123] Step S605: determine whether the maximum number of connections is greater than the sum of the number of connections in use and the number of reserved connections. If so, jump to step S606; otherwise, jump to step S602;
[0124] Step S606: select the cluster node that meets the above conditions as the target cluster node;
[0125] Step S607, determining the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that each cluster node can carry, and the maximum number of connections per node of the target server based on the connection information;
[0126] Step S608: Determine whether the maximum number of connections that can be carried is greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node. If so, jump to step S609; otherwise, jump to step S601.
[0127] Step S609: select the cluster node that meets the above conditions as the target cluster node;
[0128] Step S610: select a cluster node that meets the above conditions as a target cluster node;
[0129] Step S611, applying for connection occupation from the target cluster node;
[0130] Step S612, determine whether the connection occupation application is successful, if so, jump to step S613, otherwise jump to step S601;
[0131] Step S613: Use the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0132] The specific implementation content of the method for initiating a service request of a reference embodiment of the present invention has been described in detail in the above-mentioned method for initiating a service request, so the repeated content will not be described again here.
[0133] According to a second aspect of an embodiment of the present invention, a device for initiating a service request is provided.
[0134] Figure 7 FIG. 1 is a schematic diagram of the main modules of the device for initiating a service request according to an embodiment of the present invention. Figure 7As shown, the service request initiating device 700 mainly includes:
[0135] An acquisition module 701 is configured to acquire pre-set connection information of each cluster node in response to receiving a service request;
[0136] An occupation module 702 is configured to determine a target cluster node among the cluster nodes according to the connection information, and apply to the target cluster node for connection occupation;
[0137] The request module 703 is configured to, when the connection occupation application to the target cluster node is successful, use the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0138] According to a reference embodiment of the present invention, the connection information includes: connection information between the cluster node and the server; determining the target cluster node among the cluster nodes based on the connection information includes:
[0139] Determining, among the cluster nodes, a first cluster node that has target connection information for a target server corresponding to the service request;
[0140] Determining, based on the target connection information, the number of available connections, the number of used connections, the number of reserved connections, and the maximum number of connections between each first cluster node and the target server;
[0141] Determine, from the first cluster nodes, a second cluster node whose number of available connections is greater than the number of reserved connections, and use the second cluster node as the target cluster node;
[0142] If a second cluster node whose number of available connections is greater than the number of reserved connections is not determined, a third cluster node whose maximum number of connections is greater than the sum of the number of in-use connections and the number of reserved connections is determined among the first cluster nodes, and the third cluster node is used as the target cluster node.
[0143] According to another reference embodiment of the present invention, the service request initiating device 700 further includes:
[0144] A first determining module is configured to determine, based on the connection information, the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that each cluster node can carry, and the maximum number of connections of a single node of the target server;
[0145] The screening module is configured to determine, from the cluster nodes, a fourth cluster node whose maximum number of connections that can be carried is greater than or equal to the sum of the cumulative maximum number of connections and the maximum number of connections per node, and use the fourth cluster node as the target cluster node.
[0146] According to another reference embodiment of the present invention, the service request initiating device 700 further includes: a second acquisition module, configured to acquire a connection with the target server from the connection pool of the target cluster node; a creation module, configured to, if a connection with the target server is not acquired from the connection pool of the target cluster node, acquire configuration information of the target server, and establish a connection between the target cluster node and the target server based on the configuration information;
[0147] Using the target cluster node to send the service request to the target server corresponding to the service request includes: using a connection between the target cluster node and the target server to send the service request to the target server.
[0148] According to another reference embodiment of the present invention, the service request initiating device 700 further includes:
[0149] A first updating module, configured to update the connection information between the target cluster node and the target server;
[0150] The second updating module is configured to determine whether the service request has been processed, and if the service request has been processed, to update the updated connection information again.
[0151] According to another reference embodiment of the present invention, the service request initiating device 700 further includes:
[0152] A second determining module is used to determine the maximum number of connections and the number of used connections of the target server according to the connection information;
[0153] The determination module is configured to determine whether the maximum number of connections to the target server is greater than the number of connections in use to the target server.
[0154] According to a reference embodiment of the present invention, the service request initiating device 700 further includes:
[0155] A repeated determination module is used to repeatedly execute the following steps until it is determined that the maximum number of connections to the target server is greater than the number of connections in use of the target server: blocking the thread to which the service request belongs; when the blocking time of the thread is greater than or equal to a preset time threshold, waking up the thread and determining whether the maximum number of connections to the target server is greater than the number of connections in use of the target server.
[0156] It should be noted that the specific implementation content of the service request initiating device in the embodiment of the present invention has been described in detail in the service request initiating method described above, so the details will not be repeated here.
[0157] According to the technical solution of the embodiment of the present invention, the target cluster node is determined based on the connection information of the cluster node, and the target cluster node is used to send a service request to the target server, which can improve the efficiency of initiating service requests, effectively control the load of the cluster node, and improve the stability and reliability of the system; the priority between cluster nodes is determined according to the connection information, and the target cluster node is determined according to the priority, which can improve the screening efficiency of the cluster node, reduce the load pressure of the cluster node, and preferentially allocate service requests to idle cluster nodes, so as to improve the efficiency of initiating service requests; reuse the connections in the connection pool, and create a connection according to the configuration information when no connection exists, which can save system resources, avoid frequent establishment of connections with the target server, and improve the efficiency of initiating service requests; after sending the service request and processing the service request, the connection information is updated, which can ensure the dynamic update of the connection information and make the connection information accurate and timely; according to the connection information, the thread where the service request is located is blocked and awakened, which can avoid the accumulation of a large number of service requests in the cluster node, reduce the load of the cluster node, ensure the stability and reliability of the system, and save system resources.
[0158] According to a third aspect of an embodiment of the present invention, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided by the first aspect of the embodiment of the present invention.
[0159] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0160] Figure 8 An exemplary system architecture 800 is shown to which the method for initiating a service request or the apparatus for initiating a service request according to an embodiment of the present invention can be applied.
[0161] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0162] Users can use terminal devices 801, 802, and 803 to interact with server 805 via network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as request processing applications, request management applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0163] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0164] Server 805 can be a server that provides various services, such as a background management server (for example only) that supports the initiation of service requests sent by upstream terminal devices 801, 802, and 803. In response to receiving the service request, the background management server can obtain the connection information of each pre-set cluster node; based on the connection information, determine the target cluster node among the cluster nodes and apply for connection occupation to the target cluster node; if the application for connection occupation to the target cluster node is successful, use the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request; and feedback the initiation status of the service request (for example only) to the terminal device.
[0165] It should be noted that the method for initiating a service request provided in the embodiment of the present invention is generally executed by the server 805, and accordingly, the device for initiating the service request is generally disposed in the server 805. The method for initiating a service request provided in the embodiment of the present invention may also be executed by the terminal devices 801, 802, and 803, and accordingly, the device for initiating the service request may be disposed in the terminal devices 801, 802, and 803.
[0166] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0167] Reference below Figure 9 , which shows a schematic structural diagram of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Figure 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0168] like Figure 9As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage unit 908 into a random access memory (RAM) 903. Various programs and data required for the operation of the system 900 are also stored in the RAM 903. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0169] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, and the like; an output section 907 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 908 including a hard disk and the like; and a communication section 909 including a network interface card such as a LAN card or a modem. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 910 as needed, so that computer programs read therefrom can be installed into the storage section 908 as needed.
[0170] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 909, and / or installed from a removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the embodiment of the present invention are executed.
[0171] It should be noted that the computer-readable medium shown in the embodiments of the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In embodiments of the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or component. In embodiments of the present invention, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.
[0172] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer programs according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0173] The modules described in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided in a processor. For example, they may be described as comprising an acquisition module, an occupation module, and a request module. The names of these modules do not, in some cases, limit the modules themselves. For example, the acquisition module may also be described as a "module for acquiring connection information for each cluster node."
[0174] As another aspect, an embodiment of the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently and not be incorporated into the device. The computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the device implements the following method: in response to receiving a service request, obtaining pre-set connection information for each cluster node; determining a target cluster node among the cluster nodes based on the connection information, and applying for connection occupation to the target cluster node; if the application for connection occupation to the target cluster node is successful, using the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
[0175] According to the technical solution of the embodiment of the present invention, the target cluster node is determined based on the connection information of the cluster node, and the target cluster node is used to send a service request to the target server, which can improve the efficiency of initiating service requests, effectively control the load of the cluster node, and improve the stability and reliability of the system; the priority between cluster nodes is determined according to the connection information, and the target cluster node is determined according to the priority, which can improve the screening efficiency of the cluster node, reduce the load pressure of the cluster node, and preferentially allocate service requests to idle cluster nodes, so as to improve the efficiency of initiating service requests; reuse the connections in the connection pool, and create a connection according to the configuration information when no connection exists, which can save system resources, avoid frequent establishment of connections with the target server, and improve the efficiency of initiating service requests; after sending the service request and processing the service request, the connection information is updated, which can ensure the dynamic update of the connection information and make the connection information accurate and timely; according to the connection information, the thread where the service request is located is blocked and awakened, which can avoid the accumulation of a large number of service requests in the cluster node, reduce the load of the cluster node, ensure the stability and reliability of the system, and save system resources.
[0176] The above specific embodiments do not limit the scope of protection of the embodiments of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the embodiments of the present invention should be included in the scope of protection of the embodiments of the present invention.
Claims
1. A method for initiating a service request, characterized in that: include: In response to receiving the service request, obtaining pre-set connection information of each cluster node; determining a target cluster node among the cluster nodes according to the connection information, and applying for connection occupation from the target cluster node; In the case that the application for connection occupation to the target cluster node is successful, the target cluster node is used to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
2. The method according to claim 1, characterized in that The connection information includes: connection information between the cluster node and the server; determining the target cluster node among the cluster nodes according to the connection information includes: Determining, among the cluster nodes, a first cluster node that has target connection information for a target server corresponding to the service request; Determining, based on the target connection information, the number of available connections, the number of used connections, the number of reserved connections, and the maximum number of connections between each first cluster node and the target server; Determine, from the first cluster nodes, a second cluster node whose number of available connections is greater than the number of reserved connections, and use the second cluster node as the target cluster node; If a second cluster node whose number of available connections is greater than the number of reserved connections is not determined, a third cluster node whose maximum number of connections is greater than the sum of the number of in-use connections and the number of reserved connections is determined among the first cluster nodes, and the third cluster node is used as the target cluster node.
3. The method according to claim 2, characterized in that In a case where it is not determined that a first cluster node has connection information for a target server corresponding to the service request, the method further includes: Determine, based on the connection information, the cumulative maximum number of connections between each cluster node and other servers, the maximum number of connections that each cluster node can carry, and the maximum number of connections of a single node of the target server; A fourth cluster node whose maximum number of connections that can be carried is greater than or equal to the sum of the accumulated maximum number of connections and the maximum number of connections of a single node is determined among the cluster nodes, and the fourth cluster node is used as the target cluster node.
4. The method according to claim 1, wherein Before using the target cluster node to send the service request to the target server corresponding to the service request, the method further includes: obtaining a connection with the target server from a connection pool of the target cluster node; if a connection with the target server is not obtained from the connection pool of the target cluster node, obtaining configuration information of the target server, and establishing a connection between the target cluster node and the target server based on the configuration information; Using the target cluster node to send the service request to the target server corresponding to the service request includes: using a connection between the target cluster node and the target server to send the service request to the target server.
5. The method according to claim 4, characterized in that After sending the service request to the target server using the connection between the target cluster node and the target server, the method further includes: Updating the connection information between the target cluster node and the target server; It is determined whether the service request has been processed. If the service request has been processed, the updated connection information is updated again.
6. The method according to claim 1, characterized in that Before determining a target cluster node among the cluster nodes according to the connection information, the method further includes: Determine the maximum number of connections and the number of connections in use of the target server according to the connection information; It is determined that the maximum number of connections to the target server is greater than the number of connections in use to the target server.
7. The method according to claim 6, characterized in that In a case where the maximum number of connections to the target server is equal to the number of connections in use to the target server, the method further includes: Repeat the following steps until it is determined that the maximum number of connections to the target server is greater than the number of connections in use of the target server: block the thread to which the service request belongs; when the blocking time of the thread is greater than or equal to a preset time threshold, wake up the thread and determine whether the maximum number of connections to the target server is greater than the number of connections in use of the target server.
8. A device for initiating a service request, characterized in that: include: An acquisition module, configured to acquire preset connection information of each cluster node in response to receiving a service request; an occupation module, configured to determine a target cluster node among the cluster nodes according to the connection information, and apply to the target cluster node for connection occupation; The request module is configured to, when the application for connection occupation to the target cluster node is successful, use the target cluster node to send the service request to the target server corresponding to the service request, so that the target server processes the service request.
9. An electronic device, characterized in that: include: One or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
High-reliability video conference system, control method thereof and storage medium
CN113485821A
Cross-multi-cluster work scheduling method and device
CN114153580A
Cross-cluster load balancing method and device, equipment and storage medium
CN117149445A