Request routing method, device, equipment and readable storage medium
By determining the routing weight value and routing rules based on the average consumption time of the server, and optimizing the request routing, the problems of low request processing efficiency and insufficient resource utilization in the existing technology are solved, and more efficient server resource utilization is achieved.
Patent Information
- Application Number
- CN202210204906.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-02
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-03-02
AI Technical Summary
When existing request routing methods handle a large number of network requests, the request processing efficiency may be low and the server resources cannot be fully utilized, mainly due to differences in the request processing capabilities of each server.
By obtaining the average consumption time of each server's current request processing, sorting and assigning routing weight values to servers, establishing a routing rule array, and randomly selecting target servers to route requests, thereby optimizing request distribution.
It improves the efficiency of request processing and the utilization of server resources, ensuring that requests are allocated to servers with stronger processing capabilities, thereby improving overall performance.
Smart Images

Figure CN114615339B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of resource scheduling, and in particular to a request routing method, apparatus, device and readable storage medium. Background Art
[0002] As the business develops, the number of network requests sent by clients increases. In order to process a large number of requests, the requests need to be routed to multiple servers.
[0003] Currently, common request routing methods include distributed routing and fixed rule routing. Distributed routing is based on business rules, routing requests of the same business type to a group of servers, and the number of requests routed to each server in a group of servers is the same. Fixed rule routing can be round-robin, that is, routing requests to each server in turn, and restarting the next round of routing after all are completed.
[0004] However, since the request processing capabilities of each server may be different, routing requests to each server using the above method may result in low request processing efficiency and fail to fully utilize server resources. Summary of the invention
[0005] The present application provides a request routing method, apparatus, device and readable storage medium to improve request processing efficiency and enhance utilization of server resources.
[0006] In a first aspect, an embodiment of the present application provides a request routing method, including:
[0007] Receive the request sent by the client;
[0008] For each server, obtain the pre-stored average time consumed by the server to currently process each request;
[0009] According to the average consumption time corresponding to each server, the servers are sorted in a first order to obtain a server list, and the obtained average consumption time is sorted in a second order, and the obtained average consumption time is used as the routing weight value corresponding to each server in the server list; wherein the second order is opposite to the first order;
[0010] The server numbers corresponding to the servers in the server list are stored repeatedly in an array to obtain a routing rule array; wherein the number of times each server number is stored in the routing rule array is consistent with the routing weight value corresponding to the server corresponding to the server number;
[0011] Select a random number, and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array;
[0012] The request is routed to the target server corresponding to the target server number.
[0013] Furthermore, in the above method, the servers are sorted in a first order according to the average consumption time corresponding to each server to obtain a server list, including:
[0014] Sort the servers in descending order according to the average time consumed to process each request, and obtain a server list.
[0015] Furthermore, in the above method, the obtained average consumption time is sorted according to the second order, and the obtained average consumption time is used as the routing weight value corresponding to each server in the server list, including:
[0016] Sort the average consumption times obtained from small to large.
[0017] The minimum average consumption time is used as the routing weight value corresponding to the server at the top of the server list;
[0018] The maximum average consumption time is used as the routing weight value corresponding to the server at the end of the server list.
[0019] Furthermore, in the above method, the server numbers corresponding to the servers in the server list are repeatedly stored in an array in sequence to obtain a routing rule array, including:
[0020] The server numbers corresponding to the servers in the server list are sequentially stored in the array, and the routing weight value corresponding to each server corresponding to the server number is reduced by one;
[0021] For each server number, determine whether the current routing weight value corresponding to the server corresponding to the server number is zero;
[0022] If yes, stop storing the server number in the array;
[0023] If not, the server number is stored in the array again, and the routing weight value corresponding to the server corresponding to the server number is reduced by one, and the step of returning to execute for each server number, determining whether the current routing weight value corresponding to the server corresponding to the server number is zero;
[0024] When the current routing weight values corresponding to the servers corresponding to each server number are all zero, the obtained array is a routing rule array.
[0025] Furthermore, the method as described above further comprises:
[0026] For each server, collect the time consumed by the server to process the request received this time at the target time point;
[0027] According to the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, a pre-set average consumption time calculation formula is used to calculate the first average consumption time for the server to process each request after processing the request received this time;
[0028] The first average consumption time is used to update the pre-stored average consumption time currently used by the server to process each request.
[0029] Furthermore, the method as described above, before collecting the time consumed by each server for processing the request received this time at the target time point, further includes:
[0030] Obtain the current time and the time taken by the server to process the request received this time for the first time;
[0031] Determine whether the difference between the current time and the time taken for the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval;
[0032] If yes, determining the current time as the target time point;
[0033] If not, it is determined that the current time is a non-target time point.
[0034] In a second aspect, an embodiment of the present application provides a request routing device, including:
[0035] A receiving module, used for receiving a request sent by a client;
[0036] An acquisition module is used to acquire, for each server, an average time consumed by the server currently processing each request, which is pre-stored;
[0037] A sorting module, configured to sort the servers in a first order according to the average consumption time corresponding to each server, obtain a server list, sort the obtained average consumption time in a second order, and use them as the routing weight value corresponding to each server in the server list; wherein the second order is opposite to the first order;
[0038] A storage module, used for repeatedly storing the server numbers corresponding to the servers in the server list in sequence in an array to obtain a routing rule array; wherein the number of times each server number in the routing rule array is stored is consistent with the routing weight value corresponding to the server corresponding to the server number;
[0039] A selection module, used to select a random number, and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array;
[0040] The routing module is used to route the request to the target server corresponding to the target server number.
[0041] Furthermore, the device as described above further comprises:
[0042] A collection module is used to collect, for each server, at a target time point, the time taken by the server to process the request received this time;
[0043] A calculation module, configured to calculate, based on the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, a first average consumption time for the server to process each request after processing the request received this time, using a pre-set average consumption time calculation formula;
[0044] An updating module is used to update the pre-stored average time consumed by the server currently processing each request using the first average time consumed.
[0045] Furthermore, in the above-mentioned device, the acquisition module is further used to acquire the current time and the time for initially collecting the time consumed by the server to process the request received this time;
[0046] The device also includes:
[0047] A judging module, used to judge whether the difference between the current time and the time taken for the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval;
[0048] A determination module, configured to determine the current time as a target time point if the difference between the current time and the time taken by the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval;
[0049] The determination module is further configured to determine that the current time is a non-target time point if the difference between the current time and the time taken for the server to initially collect and process the request received this time is not equal to an integer multiple of a preset collection interval.
[0050] In a third aspect, an embodiment of the present application provides a processor, and a memory and a transceiver communicatively connected to the processor;
[0051] The memory stores computer-executable instructions; the transceiver is used to receive and forward requests sent by the client;
[0052] The processor executes the computer-executable instructions stored in the memory to implement the request routing method as described in the first aspect.
[0053] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the request routing method as described in the first aspect.
[0054] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the request routing method described in the first aspect.
[0055] The present application provides a request routing method, apparatus, device and readable storage medium, which determines a server list and a routing weight value of each server in the list according to the average time consumed by each server to process each request, establishes a routing rule array according to the server number of each server in the server list and the routing weight value of each server in the list, and after receiving a request sent by a client, randomly selects a server number corresponding to a position from the routing rule array as the target server number, and routes the request to the target server corresponding to the target server number. In other words, the present application can accurately determine the request processing capacity of each server through the average time consumed by each server to process each request, and thereby determine the routing weight value of each server, and use the routing rule array established based on the routing weight value for request routing, which can have more opportunities to route requests to servers with stronger request processing capabilities, thereby effectively improving the efficiency of request processing and improving server resource utilization. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0057] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;
[0058] Figure 2 A flowchart of a request routing method provided in an embodiment of the present application;
[0059] Figure 3 A flowchart of another request routing method provided in an embodiment of the present application;
[0060] Figure 4 A flowchart of another request routing method provided in an embodiment of the present application;
[0061] Figure 5 A schematic diagram of the structure of a request routing device provided in an embodiment of the present application;
[0062] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0063] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0064] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application.
[0065] In daily business, clients usually send a large number of network requests. In order to process the requests in a timely manner, the requests need to be routed to multiple servers. At present, common request routing methods include distributed routing and fixed rule routing. Among them, distributed routing is based on business rules, routing requests of the same business type to a group of servers, and the number of requests routed to each server in a group of servers is the same. Fixed rule routing can be round-robin, that is, routing requests to each server in turn, and restarting the next round of routing after all are completed.
[0066] However, since the request processing capabilities of each server may be different, routing requests to each server using the above method may result in low request processing efficiency and fail to fully utilize server resources.
[0067] The request routing method, apparatus, device and readable storage medium provided in this application are intended to solve the above technical problems in the prior art.
[0068] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0069] Figure 1 A schematic diagram of a system architecture provided in an embodiment of the present application is shown as follows: Figure 1 As shown, the Figure 1 The system architecture shown may specifically include a client 1 , a routing device 2 , a plurality of servers 3 and a remote dictionary server 4 , wherein the routing device 2 is provided with a request routing device.
[0070] The client 1 can be installed on any electronic device with communication function, such as a desktop computer, a laptop computer, a mobile phone, or a smart home device, etc., and is used to send a network request to the routing device 2, so that the routing device 2 forwards the received network request to multiple servers 3 to realize request routing. The request routing device can be mounted on the routing device 2, and is used to receive the request sent by the client 1. After receiving the request, for each server, the average time consumed by the server currently processing each request stored in the remote dictionary server 4 is obtained, and the server list and the routing weight value of each server in the list are determined according to the average time consumed. A routing rule array is established according to the server number of each server in the server list and the routing weight value of each server in the list, and a server number corresponding to a position is randomly selected from the routing rule array as the target server number, and the request is routed to the target server 3 corresponding to the target server number.
[0071] Embodiment 1
[0072] Figure 2 A flowchart of a request routing method provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the request routing method provided in this embodiment includes the following steps:
[0073] Step 201: Receive a request sent by a client.
[0074] Step 202: For each server, obtain the pre-stored average time consumed by the server to currently process each request.
[0075] Step 203: sort the servers in a first order according to the average consumption time corresponding to each server to obtain a server list, sort the obtained average consumption time in a second order, and use them as the routing weight value corresponding to each server in the server list; wherein the second order is opposite to the first order.
[0076] Step 204: repeatedly store the server numbers corresponding to the servers in the server list in an array to obtain a routing rule array; wherein the number of times each server number is stored in the routing rule array is consistent with the routing weight value corresponding to the server corresponding to the server number.
[0077] Step 205: select a random number, and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array.
[0078] Step 206: Routing the request to the target server corresponding to the target server number.
[0079] It should be noted that the execution subject of the request routing method provided in this embodiment may be a request routing device. In practical applications, the request routing device may be implemented by a computer program, such as application software, etc., or by a medium storing relevant computer programs, such as a USB flash drive, a CD, etc., or by a physical device integrated or installed with relevant computer programs, such as a chip, etc.
[0080] In this embodiment, since the existing request routing method may result in low efficiency in request processing and inability to fully utilize server resources, in order to improve the efficiency of request processing and increase the utilization of server resources, the request processing capacity of each server can be determined by the average time consumed by each server to process each request, and the routing weight value of each server can be determined accordingly, and a routing rule array established based on the routing weight value can be used to perform request routing.
[0081] Specifically, the request routing device may first receive a request sent by a client, and in order to route the request to a suitable server so as to process the request as quickly as possible, the request routing device may obtain, for each server, a pre-stored average time consumed by the server currently processing each request.
[0082] In practical applications, the average time consumed by each server to process each request can be pre-stored in a remote dictionary server (Remote Dictionary Server, Redis for short), that is, the request routing device can obtain the average time consumed by each server to process each request from the remote dictionary server based on the server identifier.
[0083] For example, there are currently 5 servers for processing requests, namely srv_1, srv_2, srv_3, srv_4 and srv_5. When the request routing device receives the request sent by the client, it can obtain the pre-stored average consumption time of each server currently processing each request from the remote dictionary server based on the respective identifiers of the 5 servers, wherein the obtained average consumption time corresponding to each server can be: the average consumption time corresponding to srv_1 is 4ms, the average consumption time corresponding to srv_2 is 3ms, the average consumption time corresponding to srv_3 is 8ms, the average consumption time corresponding to srv_4 is 6ms, and the average consumption time corresponding to srv_5 is 2ms.
[0084] After obtaining the average time consumed by each server to currently process each request, the request routing device may sort the servers in a first order according to the average time consumed by each server to obtain a server list.
[0085] Based on the above-mentioned embodiment 1, in an optional implementation, in step 203, the servers are sorted in a first order according to the average consumption time corresponding to each server to obtain a server list, including: sorting each server in descending order according to the average consumption time currently processing each request to obtain a server list.
[0086] In this embodiment, following the above example, the request routing device can sort the five servers in descending order according to the average time consumed for processing each request, where srv_3 has the largest average time consumed, which is 8ms, and srv_5 has the smallest average time consumed, which is 2ms. In the middle, srv_4 has an average time consumed, which is 6ms, srv_1 has an average time consumed, which is 4ms, and srv_2 has an average time consumed, which is 3ms. Accordingly, the server list obtained is [srv_3, srv_4, srv_1, srv_2, srv_5].
[0087] After obtaining the server list, the request routing device may further sort the obtained average consumption times according to a second order and use them as the routing weight values corresponding to each server in the server list, wherein the second order is the opposite order of the first order.
[0088] Based on the above-mentioned embodiment 1, in another optional implementation, in step 203, the obtained average consumption times are sorted according to a second order, and are respectively used as the routing weight values corresponding to each server in the server list, including: sorting the obtained average consumption times in ascending order; using the smallest average consumption time as the routing weight value corresponding to the server at the first position in the server list; and using the largest average consumption time as the routing weight value corresponding to the server at the last position in the server list.
[0089] In this embodiment, following the above example, the request routing device can sort the 5 average consumption times obtained in ascending order, wherein the minimum average consumption time is 2ms, the maximum average consumption time is 8ms, and the middle ones are 3ms, 4ms, and 6ms. The request routing device can use them as the routing weight values corresponding to each server in the server list [srv_3, srv_4, srv_1, srv_2, srv_5], that is, the minimum average consumption time 2ms is used as the server at the top of the server list, that is, the routing weight value corresponding to srv_3, the maximum average consumption time 8ms is used as the server at the bottom of the server list, that is, the routing weight value corresponding to srv_5, and the middle average consumption time 3ms, 4ms, and 6ms are used as the routing weight values corresponding to the servers in the middle of the server list, that is, srv_4, srv_1, and srv_2.
[0090] Accordingly, the routing weight value 2 corresponding to srv_3, the routing weight value 3 corresponding to srv_4, the routing weight value 4 corresponding to srv_1, the routing weight value 6 corresponding to srv_2, and the routing weight value 8 corresponding to srv_5 can be obtained.
[0091] After obtaining the server list and the routing weight values corresponding to each server in the server list, the request routing device can repeatedly store the server numbers corresponding to the servers in the server list in an array to obtain a routing rule array. The number of times each server number is stored in the routing rule array is consistent with the routing weight value corresponding to the server corresponding to the server number.
[0092] Figure 3 A flowchart of another request routing method provided in an embodiment of the present application is as follows: Figure 3 As shown, the request routing method provided in this embodiment, based on the above embodiment 1, step 204 specifically includes the following steps:
[0093] Step 301: Store the server numbers corresponding to the servers in the server list in the array in sequence, and reduce the routing weight value corresponding to each server corresponding to the server number by one.
[0094] Step 302: for each server number, determine whether the current routing weight value corresponding to the server corresponding to the server number is zero.
[0095] Step 303: If yes, stop storing the server number in the array.
[0096] Step 304: If not, store the server number in the array again, reduce the routing weight value of the server corresponding to the server number by one, and return to execute the step of determining whether the current routing weight value of the server corresponding to the server number is zero for each server number.
[0097] Step 305: When the current routing weight values corresponding to the servers corresponding to each server number are all zero, the obtained array is a routing rule array.
[0098] In this embodiment, the request routing device may first store the server numbers corresponding to the servers in the server list in an array in sequence, and subtract one from the routing weight value corresponding to each server number.
[0099] Continuing with the above example, the request routing device can first store the server numbers corresponding to each server in the server list [srv_3, srv_4, srv_1, srv_2, srv_5], that is, 3, 4, 1, 2, 5 in an array in sequence, obtain the array [3, 4, 1, 2, 5], and respectively subtract one from the routing weight value 2 corresponding to srv_3 corresponding to server number 3, the routing weight value 3 corresponding to srv_4 corresponding to server number 4, the routing weight value 4 corresponding to srv_1 corresponding to server number 1, the routing weight value 6 corresponding to srv_2 corresponding to server number 2, and the routing weight value 8 corresponding to srv_5 corresponding to server number 5. That is, the routing weight value corresponding to srv_3 corresponding to server number 3 is reduced to 1, the routing weight value corresponding to srv_4 corresponding to server number 4 is reduced to 2, the routing weight value corresponding to srv_1 corresponding to server number 1 is reduced to 3, the routing weight value corresponding to srv_2 corresponding to server number 2 is reduced to 5, and the routing weight value corresponding to srv_5 corresponding to server number 5 is reduced to 7.
[0100] After subtracting the routing weight value corresponding to each server number by one, the request routing device can determine, for each server number, whether the current routing weight value corresponding to the server corresponding to the server number is zero. In one possible case, if the current routing weight value corresponding to the server corresponding to the server number is zero, the server number is stopped from being stored in the array.
[0101] In another possible situation, if the current routing weight value of the server corresponding to the server number is not zero, the server number is stored in the array again, and the routing weight value of the server corresponding to the server number is reduced by one, and the step of returning to execute for each server number to determine whether the current routing weight value of the server corresponding to the server number is zero.
[0102] When the request routing device determines that the current routing weight values corresponding to the servers corresponding to each server number are all zero, the currently obtained array is the routing rule array.
[0103] Continuing with the above example, after the request routing device reduces the routing weight value corresponding to srv_3 corresponding to server number 3 to 1, the routing weight value corresponding to srv_4 corresponding to server number 4 to 2, the routing weight value corresponding to srv_1 corresponding to server number 1 to 3, the routing weight value corresponding to srv_2 corresponding to server number 2 to 5, and the routing weight value corresponding to srv_5 corresponding to server number 5 to 7, the request routing device can respectively determine whether the current routing weight values corresponding to servers srv_3, srv_4, srv_1, srv_2, and srv_5 corresponding to server numbers 3, 4, 1, 2, and 5 are zero.
[0104] As a result, it can be seen that the current routing weight values corresponding to the servers srv_3, srv_4, srv_1, srv_2, and srv_5 corresponding to server numbers 3, 4, 1, 2, and 5 are not zero, so the request routing device can store the server numbers 3, 4, 1, 2, and 5 in the array in sequence again, obtain the array [3, 4, 1, 2, 5, 3, 4, 1, 2, 5], and reduce the routing weight values corresponding to the servers srv_3, srv_4, srv_1, srv_2, and srv_5 corresponding to server numbers 3, 4, 1, 2, and 5 by one, that is, the routing weight value corresponding to srv_3 corresponding to server number 3 is reduced to 0, the routing weight value corresponding to srv_4 corresponding to server number 4 is reduced to 1, the routing weight value corresponding to srv_1 corresponding to server number 1 is reduced to 2, the routing weight value corresponding to srv_2 corresponding to server number 2 is reduced to 4, and the routing weight value corresponding to srv_5 corresponding to server number 5 is reduced to 6.
[0105] At this time, the request routing device can return to the step of determining whether the current routing weight value corresponding to the server corresponding to the server number is zero for each server number. As a result, it can be seen that the current routing weight value corresponding to srv_3 corresponding to server number 3 is zero, so the server number, that is, server number 3, is stopped from being stored in the array. At the same time, the current routing weight values corresponding to the servers srv_4, srv_1, srv_2, and srv_5 corresponding to server numbers 4, 1, 2, and 5 are not zero, then the request routing device can store the server numbers 4, 1, 2, and 5 in the array in sequence again, obtain the array [3, 4, 1, 2, 5, 3, 4, 1, 2, 5, 4, 1, 2, 5], and reduce the routing weight values corresponding to the servers srv_4, srv_1, srv_2, and srv_5 corresponding to the server numbers 4, 1, 2, and 5 by one, that is, the routing weight value corresponding to srv_4 corresponding to server number 4 is reduced to 0, the routing weight value corresponding to srv_1 corresponding to server number 1 is reduced to 1, the routing weight value corresponding to srv_2 corresponding to server number 2 is reduced to 3, and the routing weight value corresponding to srv_5 corresponding to server number 5 is reduced to 5.
[0106] The request routing device returns to execute the step of determining whether the current routing weight value corresponding to the server corresponding to the server number is zero for each server number, and repeats the above process until the request routing device determines that the current routing weight value corresponding to the server corresponding to each server number is zero, that is, when the routing weight value corresponding to srv_5 corresponding to the last server number 5 is reduced to 0, the currently obtained array is [3, 4, 1, 2, 5, 3, 4, 1, 2, 5, 4, 1, 2, 5, 1, 2, 5, 2, 5, 2, 5, 5, 5], which is the routing rule array.
[0107] After obtaining the routing rule array, the request routing device can select a random number, obtain the target server number of the corresponding position from the routing rule array according to the random number, and route the request to the target server corresponding to the target server number. The random number is less than or equal to the number of all server numbers stored in the routing rule array.
[0108] Continuing with the above example, after obtaining the above routing rule array, since the total number of server numbers stored in the above routing rule array is 23, the request routing device can select a random number less than or equal to 23, such as 11, and obtain the target server number at the corresponding position from the routing rule array according to the random number 11, that is, the 11th server number in the routing rule array, that is, server number 4. The request routing device can route the request to the target server srv_4 corresponding to the server number 4, so that srv_4 processes the request.
[0109] The request routing method provided in this embodiment determines the server list and the routing weight value of each server in the list according to the average time consumed by each server currently processing each request, establishes a routing rule array according to the server number of each server in the server list and the routing weight value of each server in the list, and after receiving the request sent by the client, randomly selects a server number corresponding to a position from the routing rule array as the target server number, and routes the request to the target server corresponding to the target server number. That is to say, in the embodiment of the present application, the request processing capacity of each server can be accurately determined by the average time consumed by each server currently processing each request, and the routing weight value of each server can be determined accordingly. Using the routing rule array established based on the routing weight value for request routing, there can be more opportunities to route requests to servers with stronger request processing capabilities, thereby effectively improving the efficiency of request processing and improving server resource utilization.
[0110] Embodiment 2
[0111] Figure 4 A flowchart of another request routing method provided in an embodiment of the present application, such as Figure 4 As shown, based on any of the above embodiments, the request routing method provided in this embodiment further includes the following steps:
[0112] Step 401: For each server, collect the time consumed by the server to process the request received this time at the target time point.
[0113] Step 402: Based on the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, a pre-set average consumption time calculation formula is used to calculate the first average consumption time for the server to process each request after processing the request received this time.
[0114] Step 403: Use the first average consumption time to update the pre-stored average consumption time of the server currently processing each request.
[0115] In this embodiment, since factors such as the network may affect the request processing speed of the server, the speed at which different servers process requests in different time periods may vary. Therefore, in order to accurately determine the current request processing capacity of the server, the average time consumed by the server to process each request can be periodically calculated, and the pre-stored average time consumed can be updated.
[0116] Specifically, the request routing device may collect, for each server, at a target time point, the time taken by the server to process the request received this time. The specific collection method is not limited in this embodiment.
[0117] After collecting the consumption time, the request routing device can use a preset average consumption time calculation formula to calculate the first average consumption time for the server to process each request after processing the request received this time, based on the collected consumption time, the pre-stored average consumption time for the server to process each request, and the number of requests currently received by the server. The preset average consumption time calculation formula is:
[0118] S_Avgs1[sno]=(S_Avgs[sno]*(N-1)+C_Time) / N
[0119] Among them, sno is the server number, S_Avgs1 is the first average time consumed by the server to process each request after processing the request received this time, S_Avgs is the pre-stored average time consumed by the server to process each request, N is the number of requests currently received by the server, and C_Time is the time consumed by the server to process the request received this time.
[0120] In an example, if the time taken by the server numbered 1 to process the request received this time is 105ms, the pre-stored average time taken by the server numbered 1 to process each request is 5ms, and the number of requests currently received by the server is the 100th, then after the server numbered 1 processes the request received this time, the first average time taken to process each request is (5*99+105) / 100, which is 6ms.
[0121] After calculating the first average time required for the server to process the requests received this time and processing each request, the request routing device can use the first average time required to update the pre-stored average time required for the server to currently process each request, that is, replace the pre-stored average time required with the first average time required.
[0122] Through the above method, the average time consumed by the server to process each request can be calculated regularly, so that the current request processing capacity of the server can be determined in a timely and accurate manner, and the pre-stored average time consumed can be updated, effectively avoiding factors such as network instability that affect the request processing speed of the server, thereby affecting the request processing efficiency.
[0123] Based on the above-mentioned embodiment 2, in an optional implementation, before step 401, it also includes: obtaining the current time and the time for initially collecting the time consumed by the server to process the request received this time; judging whether the difference between the current time and the time for initially collecting the time consumed by the server to process the request received this time is equal to an integer multiple of a preset collection interval; if so, determining that the current time is a target time point; if not, determining that the current time is a non-target time point.
[0124] In this embodiment, before collecting the time taken by each server to process the request received this time, the request routing device first needs to determine a target time point for collection.
[0125] Specifically, in one example, the request routing device can obtain the current time from the clock unit, and obtain the time consumed by the initial acquisition server to process the request received this time from the remote dictionary server, and determine whether the difference between the current time and the time consumed by the initial acquisition server to process the request received this time is equal to an integer multiple of a preset acquisition interval.
[0126] In one possible case, the difference between the current time and the time taken by the first acquisition server to process the request received this time is equal to an integer multiple of the preset acquisition interval, and the request routing device can determine the current time as the target time point. Correspondingly, in another possible case, the difference between the current time and the time taken by the first acquisition server to process the request received this time is not equal to an integer multiple of the preset acquisition interval, and the request routing device can determine the current time as a non-target time point.
[0127] For example, if the preset collection interval is 2 minutes, and the time consumed by the server for the first collection to process the request received this time is 12:00, in one example, the current time obtained by the request routing device is 13:00, then the request routing device can determine that the difference between the current time and the time consumed by the server for the first collection to process the request received this time is equal to an integer multiple of the preset collection interval, and the request routing device can determine that the current time 13:00 is the target time point. In another example, the current time obtained by the request routing device is 13:01, then the request routing device can determine that the difference between the current time and the time consumed by the server for the first collection to process the request received this time is not equal to an integer multiple of the preset collection interval, and the request routing device can determine that the current time 13:01 is a non-target time point.
[0128] The request routing method provided in this embodiment determines whether the current time is the target time point by judging whether the difference between the current time and the time consumed by the server for the first time to process the request received is equal to an integer multiple of a preset collection interval, and collects the time consumed by the server for processing the request received at the target time point, and calculates the average time consumed by the server for processing each request. This can timely and accurately determine the current request processing capacity of the server, and update the pre-stored average consumption time, laying a foundation for determining a suitable routing rule array, thereby improving request processing efficiency.
[0129] Embodiment 3
[0130] Figure 5 A schematic diagram of the structure of a request routing device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the request routing device provided in this embodiment includes: a receiving module 51, an acquisition module 52, a sorting module 53, a storage module 54, a selection module 55 and a routing module 56. Among them, the receiving module 51 is used to receive the request sent by the client. The acquisition module 52 is used to obtain the pre-stored average consumption time of each server currently processing each request for each server. The sorting module 53 is used to sort the servers in a first order according to the average consumption time corresponding to each server, obtain a server list, sort the obtained average consumption time in a second order, and use them as the routing weight value corresponding to each server in the server list; wherein, the second order is opposite to the first order. The storage module 54 is used to repeatedly store the server numbers corresponding to the servers in the server list in an array in sequence to obtain a routing rule array; wherein, the number of times each server number is stored in the routing rule array is consistent with the routing weight value corresponding to the server corresponding to the server number. The selection module 55 is used to select a random number and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array. The routing module 56 is used to route the request to the target server corresponding to the target server number.
[0131] The request routing device provided in this embodiment determines the server list and the routing weight value of each server in the list according to the average time consumed by each server currently processing each request, establishes a routing rule array according to the server number of each server in the server list and the routing weight value of each server in the list, and after receiving the request sent by the client, randomly selects a server number corresponding to a position from the routing rule array as the target server number, and routes the request to the target server corresponding to the target server number. That is to say, in the embodiment of the present application, the request processing capacity of each server can be accurately determined by the average time consumed by each server currently processing each request, and the routing weight value of each server can be determined accordingly. Using the routing rule array established based on the routing weight value for request routing, there can be more opportunities to route requests to servers with stronger request processing capabilities, thereby effectively improving the efficiency of request processing and improving server resource utilization.
[0132] In an optional implementation manner, the sorting module 53 is specifically used to sort the servers in descending order according to the average time consumed for currently processing each request, so as to obtain a server list.
[0133] In an optional implementation, the sorting module 53 is further specifically used to sort the acquired average consumption times in ascending order; the smallest average consumption time is used as the routing weight value corresponding to the server at the first position in the server list; and the largest average consumption time is used as the routing weight value corresponding to the server at the last position in the server list.
[0134] In an optional implementation manner, the storage module 54 is specifically used to store the server numbers corresponding to the servers in the server list in the array in sequence, and subtract one from the routing weight value corresponding to the server corresponding to each server number; for each server number, determine whether the current routing weight value corresponding to the server corresponding to the server number is zero; if so, stop storing the server number in the array; if not, store the server number in the array again, subtract one from the routing weight value corresponding to the server corresponding to the server number, and return to execute the step of determining whether the current routing weight value corresponding to the server corresponding to the server number is zero for each server number; when the current routing weight values corresponding to the servers corresponding to each server number are all zero, the obtained array is a routing rule array.
[0135] In an optional implementation, the request routing device further includes: a collection module, a calculation module and an update module. The collection module is used to collect, for each server, at a target time point, the time consumed by the server to process the request currently received. The calculation module is used to calculate, based on the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, the first average consumption time for the server to process each request after processing the request currently received, using a pre-set average consumption time calculation formula. The update module is used to update the pre-stored average consumption time for the server to currently process each request using the first average consumption time.
[0136] In an optional implementation manner, the acquisition module 52 is also used to acquire the current time and the time for the first collection of the time consumed by the server to process the request received this time. The device also includes: a judgment module and a determination module. Among them, the judgment module is used to determine whether the difference between the current time and the time consumed by the server to process the request received this time for the first collection is equal to an integer multiple of a preset collection interval. The determination module is used to determine that the current time is a target time point if the difference between the current time and the time consumed by the server to process the request received this time for the first collection is equal to an integer multiple of a preset collection interval. The determination module is also used to determine that the current time is a non-target time point if the difference between the current time and the time consumed by the server to process the request received this time for the first collection is not equal to an integer multiple of a preset collection interval.
[0137] It should be noted that the technical solution and effects performed by the request routing device provided in this embodiment can be found in the relevant contents of the aforementioned method embodiment, and will not be described in detail here.
[0138] Embodiment 4
[0139] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 6 As shown, the present application also provides an electronic device 600 , including: a memory 601 , a processor 602 , and a transceiver 603 .
[0140] The memory 601 is used to store programs. Specifically, the program may include program codes, and the program codes include computer-executable instructions. The memory 601 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0141] The processor 602 is used to execute the program stored in the memory 601 .
[0142] The transceiver 603 is used to receive and forward the request sent by the client.
[0143] The computer program is stored in the memory 601 and is configured to be executed by the processor 602 to implement the request routing method provided in any embodiment of the present application. The relevant description can be understood by referring to the relevant description and effects corresponding to the steps in the accompanying drawings, and no further details are given here.
[0144] In this embodiment, the memory 601, the processor 602 and the transceiver 603 are connected via a bus. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0145] Embodiment 5
[0146] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the request routing method provided by any embodiment of the present application.
[0147] Embodiment 6
[0148] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements a request routing method provided by any embodiment of the present application.
[0149] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0150] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] In addition, each functional module in each embodiment of the present application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0152] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable request routing device, so that the program code, when executed by the processor or controller, causes the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0153] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, 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 of the foregoing.
[0154] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the application. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0155] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0156] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A request routing method, characterized in that: include: Receive the request sent by the client; For each server, obtain the pre-stored average time consumed by the server to currently process each request; According to the average consumption time corresponding to each server, the servers are sorted in a first order to obtain a server list, and the obtained average consumption time is sorted in a second order, and the obtained average consumption time is used as the routing weight value corresponding to each server in the server list; wherein the second order is opposite to the first order; The server numbers corresponding to the servers in the server list are stored in an array in sequence, and the routing weight value corresponding to each server corresponding to the server number is reduced by one; For each server number, determine whether the current routing weight value corresponding to the server corresponding to the server number is zero; If yes, stop storing the server number in the array; If not, the server number is stored in the array again, and the routing weight value corresponding to the server corresponding to the server number is reduced by one, and the step of returning to execute for each server number, determining whether the current routing weight value corresponding to the server corresponding to the server number is zero; When the current routing weight values corresponding to the servers corresponding to each server number are all zero, the obtained array is the routing rule array; Select a random number, and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array; The request is routed to the target server corresponding to the target server number.
2. The method according to claim 1, characterized in that The step of sorting the servers in a first order according to the average consumption time corresponding to each server to obtain a server list includes: Sort the servers in descending order according to the average time consumed to process each request, and obtain a server list.
3. The method according to claim 2, characterized in that The obtained average consumption times are sorted according to the second order, and the obtained average consumption times are respectively used as the routing weight values corresponding to the servers in the server list, including: Sort the average consumption times obtained from small to large. The minimum average consumption time is used as the routing weight value corresponding to the server at the top of the server list; The maximum average consumption time is used as the routing weight value corresponding to the server at the end of the server list.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: For each server, collect the time consumed by the server to process the request received this time at the target time point; According to the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, a pre-set average consumption time calculation formula is used to calculate the first average consumption time for the server to process each request after processing the request received this time; The first average consumption time is used to update the pre-stored average consumption time currently used by the server to process each request.
5. The method according to claim 4, characterized in that Before collecting the time consumed by each server for processing the request received this time at the target time point, the method further includes: Obtain the current time and the time taken by the server to process the request received this time for the first time; Determine whether the difference between the current time and the time taken for the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval; If yes, determining the current time as the target time point; If not, it is determined that the current time is a non-target time point.
6. A request routing device, characterized in that: include: A receiving module, used for receiving a request sent by a client; An acquisition module is used to acquire, for each server, an average time consumed by the server currently processing each request, which is pre-stored; A sorting module, configured to sort the servers in a first order according to the average consumption time corresponding to each server, obtain a server list, sort the obtained average consumption time in a second order, and use them as the routing weight value corresponding to each server in the server list; wherein the second order is opposite to the first order; A storage module, used for storing the server numbers corresponding to the servers in the server list in the array in sequence, and performing a decrement operation on the routing weight value corresponding to the server corresponding to each server number; for each server number, judging whether the current routing weight value corresponding to the server corresponding to the server number is zero; if so, stopping storing the server number in the array; if not, storing the server number in the array again, and performing a decrement operation on the routing weight value corresponding to the server corresponding to the server number, and returning to the step of judging whether the current routing weight value corresponding to the server corresponding to the server number is zero for each server number; when the current routing weight values corresponding to the servers corresponding to each server number are all zero, the obtained array is a routing rule array; A selection module, used to select a random number, and obtain the target server number of the corresponding position from the routing rule array according to the random number; wherein the random number is less than or equal to the number of all server numbers stored in the routing rule array; The routing module is used to route the request to the target server corresponding to the target server number.
7. The device according to claim 6, characterized in that The device also includes: A collection module is used to collect, for each server, at a target time point, the time taken by the server to process the request received this time; A calculation module, configured to calculate, based on the collected consumption time, the pre-stored average consumption time for the server to currently process each request, and the number of requests currently received by the server, a first average consumption time for the server to process each request after processing the request received this time, using a pre-set average consumption time calculation formula; An updating module is used to update the pre-stored average time consumed by the server currently processing each request using the first average time consumed.
8. The device according to claim 7, characterized in that The acquisition module is further used to acquire the current time and the time for initially collecting the time consumed by the server to process the request received this time; The device also includes: A judging module, used to judge whether the difference between the current time and the time taken for the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval; A determination module, configured to determine the current time as a target time point if the difference between the current time and the time taken by the server to initially collect the request received this time is equal to an integer multiple of a preset collection interval; The determination module is further configured to determine that the current time is a non-target time point if the difference between the current time and the time taken for the server to initially collect and process the request received this time is not equal to an integer multiple of a preset collection interval.
9. An electronic device, characterized in that: include: A processor, and a memory and a transceiver communicatively connected to the processor; The memory stores computer-executable instructions; the transceiver is used to receive and forward requests sent by the client; The processor executes the computer-executable instructions stored in the memory to implement the request routing method according to any one of claims 1 to 5.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the request routing method according to any one of claims 1 to 5.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the request routing method according to any one of claims 1 to 5 is implemented.
