Load balancing method and device, equipment, storage medium and product
By calculating the processing capabilities of microservice nodes and performing heartbeat checks, the node load imbalance problem caused by the existing load balancing algorithm is solved, and the request response speed and resource utilization are improved.
Patent Information
- Application Number
- CN202410750569.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-10-22
AI Technical Summary
Existing load balancing algorithms lead to node load imbalance, resulting in poor request response timeliness or resource waste.
By obtaining the request information of the microservice nodes, the processing capacity of each node is calculated, and the pending requests are forwarded to the appropriate nodes based on the processing capacity. Heartbeat checks and alarm threshold management are also performed to ensure node health and resource utilization.
It improves the request response speed, avoids the situation where the node load is too high or too low, and optimizes the utilization efficiency of system resources.
Smart Images

Figure CN118819822A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network service technology, and in particular to a load balancing method, device, equipment, storage medium and product. Background Art
[0002] With the development of the Internet, server clusters can be used to respond to requests from terminal devices and provide services to terminal devices. In order to ensure the response speed of the server cluster, the requests received in the server cluster are usually distributed to the nodes in the corresponding microservices according to the load balancing algorithm, so as to achieve high availability and better performance.
[0003] The existing load balancing algorithm mainly adopts the polling method, whose basic principle is to distribute the request to each node in turn, and then distribute the request to the next node in a loop. However, this may cause some nodes to be overloaded, resulting in poor timeliness of the request response, or some nodes to be underloaded, resulting in a waste of service resources. Summary of the invention
[0004] The present application provides a load balancing method to solve the problems of poor timeliness of request response and waste of service resources in the prior art.
[0005] In a first aspect, an embodiment of the present application provides a load balancing method, including:
[0006] According to the received pending request, confirm the microservice to which the pending request needs to be forwarded;
[0007] Obtain request information for each node in the microservice;
[0008] Calculating the processing capacity of each node according to each request information;
[0009] Based on each of the processing capabilities, the to-be-executed requests are forwarded to corresponding nodes within the microservice.
[0010] Further, the calculating the processing capability of each node according to each request information includes:
[0011] Calculate, according to each of the request information, a first average request response time of each of the nodes within a first preset time period and a proportion of the number of requests received within the first preset time period;
[0012] The processing capacity of each of the nodes is calculated according to each of the first average request response times and the number of times ratio.
[0013] Furthermore, before confirming the microservice to which the request to be executed needs to be forwarded based on the received request to be executed, the load balancing method further includes: performing a heartbeat check on the microservice;
[0014] The performing a heartbeat check on the microservice includes:
[0015] For each of the nodes, calculating a second average request response duration of the node within a second preset duration and a third average request response duration within a third preset duration, and calculating a difference between the second average request response duration and the third average request response duration;
[0016] Obtaining a first total number of the nodes whose difference is greater than a preset difference threshold;
[0017] According to the first total number, a health status of the microservice is obtained.
[0018] Further, obtaining the health status of the microservice according to the first total number includes:
[0019] Obtaining a second total number of all the nodes in the microservice;
[0020] If the ratio between the first total number and the second total number is greater than a preset ratio threshold, the microservice is marked as an unhealthy service and the microservice is taken offline;
[0021] If the ratio between the first total number and the second total number is less than or equal to the preset ratio threshold, the microservice is marked as a healthy service.
[0022] Furthermore, after forwarding the request to be executed to the corresponding node in the microservice, the load balancing method further includes:
[0023] For any of the nodes, the alarm threshold of the node is confirmed based on the request response duration of each request received by the node within a fourth preset time period, and a warning is issued if the current request response duration of the node is greater than the alarm threshold.
[0024] Furthermore, the request information includes a request response duration of each request received by the node within a first preset duration, and a request count of all requests received by the node within the first preset duration.
[0025] In a second aspect, an embodiment of the present application provides a load balancing device, including:
[0026] A request receiving module is used to confirm the microservice to which the pending request needs to be forwarded based on the received pending request;
[0027] A request information acquisition module, used to obtain request information of each node in the microservice;
[0028] A processing capacity calculation module, used to calculate the processing capacity of each node according to each request information;
[0029] A request forwarding module is used to forward the to-be-executed request to a corresponding node in the microservice based on each of the processing capabilities.
[0030] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0031] Memory for storing computer programs;
[0032] A processor, configured to execute the computer program;
[0033] Wherein, when the processor executes the computer program, the load balancing method described in any one of the first aspects above is implemented.
[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the load balancing method described in any one of the first aspects above is implemented.
[0035] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising computer instructions, which, when executed by a processor, implement the load balancing method described in any one of the first aspects above.
[0036] Compared with the prior art, a load balancing method provided by an embodiment of the present application has the beneficial effect of: by confirming the microservice to which the request to be executed needs to be forwarded based on the received request to be executed, obtaining the request information of each node in the microservice, calculating the processing capacity of each node based on each request information, and forwarding the request to be executed to the corresponding node in the microservice based on each processing capacity, the response speed of the request can be improved, and the situation that some nodes are overloaded, resulting in poor response timeliness, or some nodes are underloaded, resulting in waste of service resources, can be avoided, thereby making more efficient use of system resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical features of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0038] Figure 1It is a flow chart of an embodiment of a load balancing method provided by the present application;
[0039] Figure 2 This is a schematic diagram of a microservice architecture of an embodiment of a load balancing method provided by the present application;
[0040] Figure 3 It is a structural diagram of an embodiment of a load balancing device provided by the present application;
[0041] Figure 4 It is a structural schematic diagram of an embodiment of an electronic device provided by the present application. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] See also Figure 1 , Figure 1 : is a flow chart of a load balancing method provided in an embodiment of the present application, wherein the load balancing method comprises the following steps:
[0044] S1: According to the received pending request, confirm the microservice to which the pending request needs to be forwarded;
[0045] S2: Obtain request information of each node in the microservice;
[0046] S3: Calculate the processing capacity of each node according to each request information;
[0047] S4: Based on each of the processing capabilities, forward the request to be executed to a corresponding node in the microservice.
[0048] It is understandable that after receiving the request to be executed, the microservice to which the request to be executed needs to be forwarded is confirmed by analyzing the request to be executed, so as to forward the request to be executed to the node in the microservice for processing. For example, the microservice to which the request to be executed needs to be forwarded can be confirmed according to the functional requirements of the request to be executed, or according to the microservice ID carried in the request to be executed. Then, the request information of each node in the microservice is obtained, and the processing capacity of all nodes is calculated according to each of the request information. Based on the processing capacity of each node, the request to be executed is forwarded to the corresponding node in the microservice, for example, the request to be executed is forwarded to the node with the strongest processing capacity in the microservice.
[0049] The embodiment of the present application can be secondary developed on the IRule interface to implement the load balancing method provided by the embodiment of the present application. It only needs to re-customize the load balancing rules of the IRule interface to the load balancing method provided by the embodiment of the present application. There is no need to deploy additional load balancing modules or modify Nginx forwarding rules, etc., and no additional server resources will be consumed. It is very convenient to integrate with any Java application.
[0050] For example, see Figure 2 , Figure 2 This is a schematic diagram of the microservice architecture of the embodiment of the present application. The microservice architecture includes several microservices and a secondary gateway. The secondary gateway is used to uniformly manage and schedule these microservices. The request to be executed first reaches the secondary gateway, and the secondary gateway executes the load balancing method provided by the embodiment of the present application, so that the load balancing related functions are combined with the secondary gateway, and do not occupy server resources alone, and the load balancing management will also be more convenient. Specifically, the secondary gateway uses the LoadBalancerInterceptor class to pull the node list of the microservice from NACOS, obtains the ip and port of the microservice node according to the microservice ID, and after determining the node of the request to be processed by the load balancing method provided by the present application, the request to be executed is forwarded to the node.
[0051] In the microservice architecture, microservices may call each other, for example, microservice A calls microservice C and microservice D, and microservice B calls microservice D. Different microservices call each other, forming a complex calling chain.
[0052] The microservice architecture also includes a NACOS registration center, a computing service cluster and a message queue cluster. The NACOS registration center is responsible for registering microservices, and the computing service cluster is responsible for executing complex computing tasks. Each node in the computing service cluster has powerful computing capabilities and can process multiple tasks in parallel. For some requests that require real-time responses, the secondary gateway can directly route the request to a node in the computing service cluster for processing. After the processing is completed, the result can be directly returned to the client through the secondary gateway. The message queue cluster allows different microservices to communicate through messages. For some tasks that require asynchronous processing, the secondary gateway can send the request to the message queue cluster, which will be processed asynchronously by the background microservices. Through asynchronous processing, the direct dependence between microservices is reduced. The message queue cluster can also serve as a task source for the computing service cluster. When the computing service cluster needs to process a new computing task, it can obtain task data from the message queue. After the processing is completed, the computing service cluster sends the result back to another message queue for use by other microservices.
[0053] In an optional implementation manner, the calculating the processing capability of each node according to each of the request information includes:
[0054] According to each of the request information, calculate a first average request response time of each node within a first preset time and a proportion of the number of requests received within the first preset time;
[0055] The processing capacity of each of the nodes is calculated according to each of the first average request response times and the number of times ratio.
[0056] Optionally, the first preset duration can be set to within 5 minutes before the current time, that is, from the current time to the past 5 minutes, first obtain the request information of all requests received by each node from the current time to the past 5 minutes, calculate the first average request response duration of each node from the current time to the past 5 minutes and the proportion of the number of requests received from the current time to the past 5 minutes; calculate the processing capacity of each node based on the first average request response duration and the proportion of the number of times. Of course, the first preset duration can be set according to actual needs, and no specific limitation is made here.
[0057] Optionally, the request information includes a request response duration of each request received by the node within a first preset duration, and a request count of all requests received by the node within the first preset duration.
[0058] Specifically, the calculating, according to each of the request information, a first average request response time of each node within a first preset time and a proportion of the number of requests received within the first preset time includes:
[0059] Calculate a first average request response duration of each node within the first preset time period according to the request response duration of each request received by each node within the first preset time period;
[0060] Exemplarily, the first average request response time is calculated according to the following formula:
[0061] AVG m =(T1+T2+,...,+T N ) / N m ;
[0062] Among them, T1, T2, ..., T N is the request response time of the 1st, 2nd, ..., Nth request received by the mth node within the first preset time, N m is the number of requests received by the mth node within the first preset time. N It is the request response duration of the last request received by the mth node within the first preset duration.
[0063] According to the number of requests, calculate the total number of requests received by all the nodes in the microservice within the first preset time period;
[0064] According to the number of requests and the total number of requests, the proportion of the number of requests received by each node within the first preset time period is calculated.
[0065] Exemplarily, the frequency ratio is calculated according to the following formula:
[0066] W m =N m / (N1+N2+,...,+N M );
[0067] Among them, there are M nodes in the microservice, N1, N2, ..., N M is the number of requests of all requests received by the 1st, 2nd, ..., Mth nodes within the first preset time period.
[0068] Finally, according to the ratio of the first average request response time to the number of requests, the processing capacity of each node is obtained; for example, the first average request response time AVG m The ratio of requests to W m Multiply them together to get the processing capacity of the mth node. The smaller the value of the multiplication result is, the stronger the processing capacity of the node is. When a pending request is received, the pending request is forwarded to the node with the strongest processing capacity in the microservice for processing.
[0069] In an optional implementation, before confirming the microservice to which the request to be executed needs to be forwarded based on the received request to be executed, the load balancing method further includes: performing a heartbeat check on the microservice;
[0070] The performing a heartbeat check on the microservice includes:
[0071] For each of the nodes, calculating a second average request response duration of the node within a second preset duration and a third average request response duration within a third preset duration, and calculating a difference between the second average request response duration and the third average request response duration;
[0072] Obtaining a first total number of the nodes whose difference is greater than a preset difference threshold;
[0073] According to the first total number, a health status of the microservice is obtained.
[0074] It is understandable that microservices are registered through the microservice registration center of NACOS. Microservices are registered to the service registry when they are started and unregistered when they are shut down. The client can query the registry to find available instances of the service. First, the microservice registration center receives the microservice registration request sent by the microservice, that is, the / nacos / v1 / ns / instance POST request. The microservice registration request includes the metadata information of the microservice, including the microservice ID, IP address and port information, etc. The microservice registration center stores this metadata information in a double-layer memory Map object, namely Map <namespace,Map<group::serviceName,Service> >.
[0075] When registering a microservice, a heartbeat check scheduled task will be executed first (executed every 5 seconds by default) to check whether the microservice is in an available state, execute the addBeatInfo() method of BeatReactor, and call the NACOS server API: / nacos / v1 / ns / instance / beat for a heartbeat check. Specifically, the difference between the second average request response time of the node within the second preset time length and the third average request response time within the third preset time length is calculated, and the first total number of nodes whose difference is greater than the preset difference threshold is counted. Based on the first total number, the health status of the microservice is obtained.
[0076] Optionally, the second preset time length can be set to within 1 hour before the current time, that is, from the current time to the past 1 hour, and the third preset time length can be set to within 30 seconds before the current time, that is, from the current time to the past 30 seconds, and the preset difference threshold is 5s; of course, the second preset time length, the third preset time length and the preset difference threshold can be set according to actual needs, and no specific limitation is made here.
[0077] First, obtain the request information of all requests received by each node in the past hour, calculate the average of all request response times according to the request response time in the request information, and use it as the second average request response time of the node. Calculate the average of all request response times in the past 30 seconds as the third average request response time of the node, and calculate the difference between the second average request response time and the third average request response time.
[0078] The total number of all nodes whose difference is greater than 5 seconds is obtained, recorded as the first total number, and the health status of the microservice is judged according to the first total number. For example, if the first total number is less than the preset number threshold, the microservice is judged to be in a healthy state; if the first total number is greater than or equal to the preset number threshold, the microservice is judged to be in an unhealthy state. Microservices in an unhealthy state will be offline and will not be able to receive and process pending requests.
[0079] In an optional implementation, obtaining the health status of the microservice according to the first total number includes:
[0080] Obtaining a second total number of all the nodes in the microservice;
[0081] If the ratio between the first total number and the second total number is greater than a preset ratio threshold, the microservice is marked as an unhealthy service and the microservice is taken offline;
[0082] If the ratio between the first total number and the second total number is less than or equal to the preset ratio threshold, the microservice is marked as a healthy service.
[0083] In an embodiment of the present application, in order to further improve the judgment of the health status of a microservice, the number of all nodes within the microservice is obtained and recorded as the second total number, and the ratio between the first total number and the second total number is calculated; optionally, the preset ratio threshold is 20%. When the ratio is greater than 20%, it indicates that the microservice node is unhealthy, and the microservice is marked as an unhealthy service and taken offline. When the ratio is less than or equal to 20%, it indicates that the microservice node is healthy, and the microservice is marked as a healthy service. Of course, the value of the preset ratio threshold can be set according to actual needs and is not specifically limited here.
[0084] It should be noted that the NACOS microservice registration center has a thread class ClientBeatProcessor for processing microservices. This thread class is mainly used to set the health status of the microservice node. This thread class can be used to mark the microservice node as an unhealthy service.
[0085] In an optional implementation, after forwarding the request to be executed to a corresponding node in the microservice, the method further includes:
[0086] For any of the nodes, the alarm threshold of the node is confirmed based on the request response duration of each request received by the node within a fourth preset time period, and a warning is issued if the current request response duration of the node is greater than the alarm threshold.
[0087] Optionally, the fourth preset time length can be set to within 1 hour before the current time, that is, from the current time to the past 1 hour. Of course, the fourth preset time length can be set according to actual needs and is not specifically limited here.
[0088] For any node, obtain the request response time of all requests received by the node in the past hour, and confirm the alarm threshold of the node based on these request response times. Optionally, confirm the alarm threshold of the node based on the median of these request response times. Further, confirm 4 times of the median as the alarm threshold. When it is detected that the current request response time of the node is greater than the alarm threshold, it indicates that the performance of the node has obviously declined. Send an alarm message to R&D personnel, who will evaluate the impact of the performance decline, determine optimization plans or add nodes, etc., to ensure the continuous availability of microservices and promptly improve the processing efficiency bottleneck of microservices and the stability of the system.
[0089] Optionally, the request response duration of each request received by the node is obtained by the following steps:
[0090] Obtaining a request execution start timestamp and a request execution end timestamp of each request received by the node;
[0091] The difference between the request execution end timestamp and the request execution start timestamp is calculated to obtain the request response duration of each request received by the node.
[0092] Specifically, the request response time of each request of the node is calculated by the request execution start timestamp and request execution end timestamp of the request. Spring AOP aspect programming is used to uniformly record the execution time of the request. Using the Spring framework, first create a class and add two annotations, @Componentbr and @Aspect, to the class name. The @Component annotation allows this class to be managed as a bean by spring. The @Aspect annotation indicates that this class is an aspect object. The @Pointcut method in the class is used to define the matching rules of the aspect. Use the @Before and @After annotations to record the timestamps before and after the method execution, that is, the request execution start timestamp and the request execution end timestamp. Calculate the difference between the request execution end timestamp and the request execution start timestamp to obtain the request response time of each request of the node, and push the node's URL path, request response time, etc. to the api-cost-time topic of the Kafka cluster through the sending method of the Kafka tool class. For example, the node URL path is path1 and the request response time is t1.
[0093] Compared with the prior art, the present application confirms the microservice to which the pending request needs to be forwarded based on the received pending request, obtains the request information of each node in the microservice, calculates the processing capacity of each node based on each request information, and forwards the pending request to the corresponding node in the microservice based on each processing capacity. This can improve the response speed and processing capacity of the request, avoid the situation where some nodes are overloaded, resulting in poor response timeliness, or some nodes are underloaded, resulting in waste of service resources, thereby more efficiently utilizing system resources.
[0094] In a second aspect, the present application embodiment provides a load balancing device, see Figure 3 , which is a schematic diagram of the structure of a load balancing device provided in an embodiment of the present application.
[0095] like Figure 3 As shown, the load balancing device includes:
[0096] The request receiving module 21 is used to confirm the microservice to which the request to be executed needs to be forwarded according to the received request to be executed;
[0097] A request information acquisition module 22, used to obtain request information of each node in the microservice;
[0098] A processing capacity calculation module 23, used to calculate the processing capacity of each node according to each request information;
[0099] The request forwarding module 24 is used to forward the to-be-executed request to a corresponding node in the microservice based on each of the processing capabilities.
[0100] In an optional implementation, the processing capacity calculation module 23 is specifically used for:
[0101] According to each of the request information, calculate a first average request response time of each node within a first preset time and a proportion of the number of requests received within the first preset time;
[0102] The processing capacity of each of the nodes is calculated according to each of the first average request response times and the number of times ratio.
[0103] In an optional implementation, the load balancing device further includes a heartbeat checking module;
[0104] The heartbeat check module is used for:
[0105] For each of the nodes, calculating a second average request response duration of the node within a second preset duration and a third average request response duration within a third preset duration, and calculating a difference between the second average request response duration and the third average request response duration;
[0106] Obtaining a first total number of the nodes whose difference is greater than a preset difference threshold;
[0107] According to the first total number, a health status of the microservice is obtained.
[0108] In an optional implementation, the heartbeat checking module is further used for:
[0109] Obtaining a second total number of all the nodes in the microservice;
[0110] If the ratio between the first total number and the second total number is greater than a preset ratio threshold, the microservice is marked as an unhealthy service and the microservice is taken offline;
[0111] If the ratio between the first total number and the second total number is less than or equal to the preset ratio threshold, the microservice is marked as a healthy service.
[0112] In an optional implementation, the load balancing device further includes an alarm module;
[0113] The alarm module is used to confirm the alarm threshold of any of the nodes based on the request response time of each request received by the node within a fourth preset time period, and issue a warning if the current request response time of the node is greater than the alarm threshold.
[0114] In an optional implementation, the request information includes a request response duration of each request received by the node within a first preset duration, and a request count of all requests received by the node within the first preset duration.
[0115] In a third aspect, the present application provides an electronic device, see Figure 4 As shown, it is a structural schematic diagram of an electronic device provided by the present application.
[0116] like Figure 4 As shown, the device includes:
[0117] A memory 31, used for storing computer programs;
[0118] A processor 32, configured to execute the computer program;
[0119] Wherein, when the processor 32 executes the computer program, the load balancing method as described in any of the above embodiments is implemented.
[0120] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 31 and executed by the processor 32 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the electronic device.
[0121] The processor 32 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0122] The memory 31 can be used to store the computer program and / or module, and the processor 32 realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory 31, and calling the data stored in the memory 31. The memory 31 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 31 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0123] It should be noted that the above electronic device includes, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 4The structural diagram is merely an example of the electronic device described above and does not constitute a limitation on the electronic device, and may include more components than shown in the figure, or a combination of certain components, or different components.
[0124] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the load balancing method described in any of the above embodiments is implemented.
[0125] It should be understood that the present application implements all or part of the processes in the above-mentioned load balancing method, and can also be completed by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned load balancing method can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0126] In a fifth aspect, an embodiment of the present application further provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the load balancing method described in any of the above embodiments.
[0127] The above is only a preferred implementation of the present application, but the protection scope of the present application is not limited thereto. It should be pointed out that for those skilled in the art, several equivalent obvious variations and / or equivalent replacements can be made without departing from the technical principles of the present application. These obvious variations and / or equivalent replacements should also be regarded as the protection scope of the present application.
Claims
1. A load balancing method, characterized in that: include: According to the received pending request, confirm the microservice to which the pending request needs to be forwarded; Obtain request information for each node in the microservice; Calculating the processing capacity of each node according to each request information; Based on each of the processing capabilities, the to-be-executed requests are forwarded to corresponding nodes within the microservice.
2. The load balancing method according to claim 1, characterized in that: The calculating the processing capacity of each node according to each request information includes: According to each of the request information, calculating a first average request response time of each of the nodes within a first preset time and a proportion of the number of requests received within the first preset time; The processing capacity of each of the nodes is calculated according to each of the first average request response times and the number of times ratio.
3. The load balancing method according to claim 1, wherein: Before confirming the microservice to which the request to be executed needs to be forwarded based on the received request to be executed, the load balancing method further includes: performing a heartbeat check on the microservice; The performing a heartbeat check on the microservice includes: For each of the nodes, calculating a second average request response duration of the node within a second preset duration and a third average request response duration within a third preset duration, and calculating a difference between the second average request response duration and the third average request response duration; Obtaining a first total number of the nodes whose difference is greater than a preset difference threshold; According to the first total number, a health status of the microservice is obtained.
4. The load balancing method according to claim 3, characterized in that: The acquiring the health status of the microservice according to the first total quantity includes: Obtaining a second total number of all the nodes in the microservice; If the ratio between the first total number and the second total number is greater than a preset ratio threshold, the microservice is marked as an unhealthy service and the microservice is taken offline; If the ratio between the first total number and the second total number is less than or equal to the preset ratio threshold, the microservice is marked as a healthy service.
5. The load balancing method according to claim 1, wherein: After forwarding the request to be executed to the corresponding node in the microservice, the load balancing method further includes: For any of the nodes, the alarm threshold of the node is confirmed based on the request response duration of each request received by the node within a fourth preset time period, and a warning is issued if the current request response duration of the node is greater than the alarm threshold.
6. The load balancing method according to claim 1, characterized in that: The request information includes a request response duration of each request received by the node within a first preset duration, and a request count of all requests received by the node within the first preset duration.
7. A load balancing device, characterized in that: include: A request receiving module is used to confirm the microservice to which the pending request needs to be forwarded based on the received pending request; A request information acquisition module, used to obtain request information of each node in the microservice; A processing capacity calculation module, used to calculate the processing capacity of each node according to each request information; A request forwarding module is used to forward the to-be-executed request to a corresponding node in the microservice based on each of the processing capabilities.
8. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program; Wherein, when the processor executes the computer program, the load balancing method as described in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the load balancing method according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that It comprises computer instructions, which, when executed by a processor, implement the load balancing method as described in any one of claims 1 to 6.
