A load balancing method, device, equipment and medium

By obtaining the average response time of instances in the sidecar proxy and performing weighted random processing, the instance with the fastest response is selected for request forwarding, which solves the problem of inability to effectively implement load balancing in the existing technology and ensures that requests receive the fastest response.

CN115580618BActive Publication Date: 2024-10-29JINAN INSPUR DATA TECH CO LTD
View PDF 13 Cites 0 Cited by

Patent Information

Application Number
CN202211259568.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-14
Publication Date
2024-10-29
Estimated Expiration
2042-10-14

AI Technical Summary

Technical Problem

The existing sidecar mode load balancing method cannot effectively guarantee that requests are forwarded to the backend instance with the fastest response. Especially when the performance of the backend instance is inconsistent or a performance bottleneck occurs, traffic will still be forwarded to instances with poor performance.

Method used

By obtaining the target request and determining the average response time of multiple instances, weighted random processing is performed to obtain the response time score, thereby filtering out the instance with the fastest response for request forwarding.

Benefits of technology

It implements load balancing based on the response time of the instance to ensure that requests receive the fastest response possible and avoid traffic being forwarded to instances with poor performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115580618B_ABST
    Figure CN115580618B_ABST
Patent Text Reader

Abstract

The present application discloses a load balancing method, apparatus, device and medium, which relates to the field of server technology and is applied to a sidecar proxy, including: obtaining a target request sent by a first target service, and determining a number of instances in a second target service based on the target request; determining the average response time of each instance to a request within a preset historical time period, and performing weighted random processing on the average response time of each instance to obtain a response time score value for each instance; filtering out a target instance from a number of instances based on the response time score value, and forwarding the target request to the target instance. By utilizing the statistical capabilities of the sidecar proxy, it is possible to determine the response time of each instance to a request, and perform weighted random processing on the response time to determine the target instance for responding to the target request, thereby achieving load balancing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of servers, and in particular to a load balancing method, device, equipment and medium. Background Art

[0002] The Sidecar pattern is used to divide the functionality of an application into separate processes, providing isolation and encapsulation by deploying the components of the application into separate processes or containers. In the sidecar pattern, the sidecar service is attached to the main application and provides the application with the features it supports. The sidecar also has the same life cycle as the main application, and is created and exited with the main application. With the sidecar, all incoming and outgoing network traffic from a single service passes through the Sidecar proxy, completing traffic management between microservices, telemetry data collection, policy enforcement, and so on. In a sense, the service is unaware of the network and only knows about the attached sidecar proxy.

[0003] Load balancing is to "evenly distribute" network requests or other forms of load to different machines to avoid the situation where some servers in the cluster are overloaded while other servers are relatively idle. Through load balancing, each server can obtain a load that suits its own processing capacity. While diverting high-load servers, it can also avoid waste of resources, killing two birds with one stone. Load balancing can be divided into software load balancing and hardware load balancing. The load balancer generally decides which server to forward the request to based on two factors. First, make sure that the selected server can respond to the request, and then select from the healthy server pool according to pre-configured rules. Common load balancing algorithms include Round Robin (polling), Least Connections (least connection), etc.

[0004] Currently, most service mesh technologies that use the sidecar model implement load balancing in three main ways: (1) random, where requests are randomly transferred to instances in the pool; (2) weighted, where requests are transferred to instances based on a specified percentage; and (3) least-request, where requests are transferred to the least-accessed instance. In fact, such load balancing can only ensure that the proportion of traffic forwarded to backend instances is roughly the same, but it cannot guarantee that requests are forwarded to the backend instance with the fastest response. Even when a backend instance responds very slowly due to various reasons, such as memory exhaustion or network jitter, traffic will still be forwarded to this instance.

[0005] In summary, how to make requests get the fastest response possible and achieve load balancing is a problem that needs to be solved. Summary of the invention

[0006] In view of this, the purpose of the present invention is to provide a load balancing method, device, equipment and medium, which can enable requests to get the fastest response possible and achieve load balancing. The specific scheme is as follows:

[0007] In a first aspect, the present application discloses a load balancing method, which is applied to a sidecar proxy, including:

[0008] Obtaining a target request sent by a first target service, and determining a number of instances of a second target service based on the target request;

[0009] Determine the average response time of each instance for requests within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance;

[0010] A target instance is screened out from a plurality of the instances based on the response duration score, and the target request is forwarded to the target instance.

[0011] Optionally, determining a number of instances of the second target service based on the target request includes:

[0012] Obtaining the destination address of the target request;

[0013] A corresponding number of instances of the second target service are determined based on the destination address.

[0014] Optionally, after determining a number of instances of the second target service based on the target request, the method further includes:

[0015] If the second target service is in the first service request state, randomly determining a target instance from a number of the instances;

[0016] The target request is forwarded to the target instance.

[0017] Optionally, after determining the average response time of each instance to requests within a preset historical time period, the method further includes:

[0018] Determining whether the average response time of each of the instances is the same;

[0019] If not, the step of performing weighted random processing on the average response time of each of the instances to obtain a response time score value of each of the instances is executed.

[0020] Optionally, after determining whether the average response time of each of the instances is the same, the method further includes:

[0021] If the average response time of each of the instances is the same, randomly determining a target instance from a number of the instances;

[0022] The target request is forwarded to the target instance.

[0023] Optionally, the load balancing method further includes:

[0024] Recording a first time of obtaining the request, and recording a second time of forwarding the request to a corresponding instance in the second target service;

[0025] The request response duration of each instance is determined based on the first time and the second time, so as to determine the average response duration of each instance in a preset historical time period based on the request response duration.

[0026] Optionally, the step of selecting a target instance from a plurality of instances based on the response duration score includes:

[0027] A minimum score value is screened out from the response duration score values ​​of each of the instances, and the instance corresponding to the minimum score value is determined as a target instance for responding to the target request.

[0028] In a second aspect, the present application discloses a load balancing device, which is applied to a sidecar proxy, including:

[0029] An instance determination module, configured to obtain a target request sent by a first target service, and determine a number of instances in a second target service based on the target request;

[0030] A weighted random module is used to determine the average response time of each instance to the request within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance;

[0031] A request forwarding module is used to filter out a target instance from a number of the instances based on the response duration score value, and forward the target request to the target instance.

[0032] In a third aspect, the present application discloses an electronic device, comprising:

[0033] Memory, used to store computer programs;

[0034] The processor is used to execute the computer program to implement the steps of the aforementioned load balancing method disclosed above.

[0035] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed load balancing method are implemented.

[0036] It can be seen that the present application discloses a load balancing method applied to a sidecar proxy, including: obtaining a target request sent by a first target service, and determining a number of instances in a second target service based on the target request; determining the average response time of each instance for requests within a preset historical time period, and performing weighted random processing on the average response time of each instance to obtain a response time score for each instance; based on the response time score, a target instance is screened out from a number of instances, and the target request is forwarded to the target instance. It can be seen that after obtaining the target request sent by the first target service, the present application determines a number of instances in a second target service based on the obtained target request, determines the average response time of each instance for requests within a preset historical time period, and then weights the average response time and then processes it to obtain a response time score for each instance, and finally screens out the target instance based on the response time score, and forwards the target request to the target instance. The above technical solution can determine the response time of each instance to a request by utilizing the statistical capabilities of the sidecar proxy, and implements a load balancing strategy based on the response time. By selecting instances based on the response time score, the response time of the request can be shortened. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0038] Figure 1 A flow chart of a load balancing method disclosed in this application;

[0039] Figure 2 A schematic diagram of a load balancing process disclosed in this application;

[0040] Figure 3 A specific sidecar proxy traffic interception schematic diagram disclosed in this application;

[0041] Figure 4 A flow chart of a specific load balancing method disclosed in this application;

[0042] Figure 5A schematic diagram of the structure of a load balancing device disclosed in this application;

[0043] Figure 6 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0044] 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 invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0045] Currently, most service mesh technologies that use the sidecar model implement load balancing in three main ways: (1) Random, requests are randomly transferred to instances in the pool; (2) Weighted: requests are transferred to instances according to a specified percentage; (3) Least requests: requests are transferred to the least accessed instance. In fact, such load balancing can only ensure that the proportion of traffic forwarded to the backend instances is roughly the same, but it cannot guarantee that requests are forwarded to the fastest responding backend instances as much as possible. Even when a certain instance of the backend responds very slowly due to various reasons, such as memory exhaustion or network jitter, traffic will still be forwarded to this instance. To this end, the embodiments of the present application disclose a load balancing method, apparatus, device and medium, which can enable requests to get the fastest response possible and achieve load balancing.

[0046] See also Figure 1 and Figure 2 As shown, an embodiment of the present application discloses a load balancing method, which is applied to a sidecar proxy. The method includes:

[0047] Step S11: obtaining a target request sent by a first target service, and determining a number of instances of a second target service based on the target request.

[0048] In this embodiment, the first target service makes a request to the second target service. During this process, the sidecar proxy first obtains the target request generated by the first target service, and then determines the corresponding number of instances from all instances of the second target service based on the obtained target request.

[0049] Further, it should be pointed out that after determining a number of instances in the second target service based on the target request, the method also includes: if the second target service is in the first service request state, then randomly determine the target instance from the number of instances; forward the target request to the target instance. It can be understood that if the second target service is used for the service request for the first time, that is, the service interface is called for the first time, then the time when the instance in the second target service responds to the request cannot be determined at this time, then the target instance is randomly determined from the number of instances, and the target request is forwarded to the target instance. For example, assuming that the first target service is recorded as service A (i.e., serviceA), the second target service is recorded as service B (i.e., serviceB), and there are three instances under service B corresponding to the target request sent by service A, and service B is in the first service request state, then one instance is randomly selected from the three instances as the target instance, and the target request is forwarded to this target instance.

[0050] Step S12: Determine the average response time of each instance to requests within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance.

[0051] In this embodiment, the average response time of each instance for requests within a preset historical time period is determined, wherein the preset historical time period can be specifically set to 5 minutes, that is, the request response time within the past 5 minutes is counted, and the average response time of each instance for requests is calculated, and then the average response time of each instance is weighted and randomly processed to obtain the response time score value of each instance. It should be pointed out that in the process of calculating the final score value, other factors can also be combined for comprehensive calculation. In addition, before executing this method, it is necessary to develop the sidecar proxy and write a load balancing algorithm program for the sidecar proxy so that the sidecar proxy can count the request response time within a certain period of time in the past and calculate the average response time of the request. In the specific implementation method, the program can also be compiled into images of multiple architectures and made into manifests, so as to achieve simultaneous support for multiple architectures. In addition, it should be pointed out that the weighted random algorithm is used to achieve load balancing. Since the access probabilities are roughly the same, if the performance of some servers is inconsistent, it is easy to cause excessive pressure on servers with poor performance. Therefore, according to the inconsistency of server performance, more requests can be allocated to servers with better performance, while fewer requests can be allocated to servers with poorer performance. Therefore, the weighted random algorithm achieves load balancing by setting weights for each server on the basis of the random algorithm. Similarly, the principles used in this embodiment are similar.

[0052] It is understandable that the sidecar proxy technology has the ability to calculate the response time. Figure 3 As shown in , in the software architecture, Sidecar is attached to the main application, which can also be understood as the parent application, to expand / enhance functional features, and Sidecar is loosely coupled with the main application. For example, the service mesh software istio uses a sidecar proxy called envoy. After the request enters service A, it will first be intercepted and enter the sidecar proxy, and then enter the service A container after being processed by the proxy. Similarly, when the traffic goes out of service A, it will also be intercepted by the sidecar proxy and enter the proxy. The proxy will forward the traffic to the corresponding service B according to the settings. Among them, the sidecar proxy and the business container need to be deployed in a pod (i.e., a container group) to achieve the purpose of sidecar intercepting traffic. That is to say, the proxy can intercept the incoming and outgoing traffic. In this process, the sidecar proxy will count the response time of the request, but this response time statistics is only used for monitoring and operation and maintenance in the prior art, and this embodiment uses the response time data counted by the sidecar proxy as the original data of the load balancing algorithm.

[0053] In a specific implementation, the above-mentioned step of determining the request response time may specifically include: recording the first time of obtaining the request, and recording the second time of forwarding the request to the corresponding instance in the second target service; determining the request response time of each instance based on the first time and the second time, so as to determine the average response time of each instance in a preset historical time period based on the request response time. That is, it can be concluded from the aforementioned disclosed content that the sidecar can intercept incoming and outgoing traffic, so when the request is obtained, the first time at this time can be recorded, and when the request is responded to by the instance in the second target service, the second time is recorded, and the time period between the first time and the second time is the request response time of the instance, so that the average response time of each instance in the past 5 minutes can be determined based on the request response time.

[0054] Step S13: Filtering a target instance from a number of instances based on the response duration score, and forwarding the target request to the target instance.

[0055] In this embodiment, based on the response time score obtained after weighted random processing, the best instance is selected from a number of instances as the target instance, and the target request is forwarded to the target instance. In this way, a load balancing process based on response time is completed.

[0056] It can be seen that the present application discloses a load balancing method applied to a sidecar proxy, including: obtaining a target request sent by a first target service, and determining a number of instances in a second target service based on the target request; determining the average response time of each instance for requests within a preset historical time period, and performing weighted random processing on the average response time of each instance to obtain a response time score for each instance; based on the response time score, a target instance is screened out from a number of instances, and the target request is forwarded to the target instance. It can be seen that after obtaining the target request sent by the first target service, the present application determines a number of instances in a second target service based on the obtained target request, determines the average response time of each instance for requests within a preset historical time period, and then weights the average response time and then processes it to obtain a response time score for each instance, and finally screens out the target instance based on the response time score, and forwards the target request to the target instance. The above technical solution can determine the response time of each instance to a request by utilizing the statistical capabilities of the sidecar proxy, and implements a load balancing strategy based on the response time. By selecting instances based on the response time score, the response time of the request can be shortened.

[0057] See also Figure 4 As shown, the embodiment of the present application discloses a specific load balancing method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, it includes:

[0058] Step S21: obtaining a target request sent by a first target service, and obtaining a destination address of the target request, so as to determine a corresponding number of instances in a second target service based on the destination address.

[0059] In this embodiment, after the first target service sends a target request, the sidecar proxy intercepts it to obtain the sent target request, and then further obtains the destination address carried in the target request, so that the sidecar proxy can determine the corresponding number of instances from the second target service based on the target address. That is, this embodiment specifically finds a matching instance from the second target service according to the destination address of the target request.

[0060] Step S22: determining the average response time of each instance to the request within a preset historical time period, and determining whether the average response time of each instance is the same;

[0061] In this embodiment, after determining the average response time of each instance to requests within a preset historical time period, it is necessary to further determine whether the average response times of each instance are the same.

[0062] Step S23: If not, weighted random processing is performed on the average response time of each of the instances to obtain a response time score value of each of the instances.

[0063] In a specific implementation, if the average response time of each instance is not the same, a weighted random processing is performed on the average response time of each instance to obtain a response time score value corresponding to each instance. It is understandable that the average response time of each instance is not the same, which may include that the average response time of each instance is different, and that the average response time of some instances is the same, but there are still instances that are different from them.

[0064] In another specific implementation, after determining whether the average response time of each of the instances is the same, the method further includes: if the average response time of each of the instances is the same, randomly determining a target instance from a number of the instances; and forwarding the target request to the target instance. It is understandable that if the average response time of each instance is the same, it means that the response speed of each instance to the request is roughly the same, then one instance can be randomly selected from a number of instances as the target instance, and then the target request can be forwarded to the target instance.

[0065] Step S24: Filter out the minimum score value from the response duration score values ​​of each of the instances, determine the instance corresponding to the minimum score value as the target instance for responding to the target request, and then forward the target request to the target instance.

[0066] In this embodiment, the minimum score value is screened out from the response time score values ​​of each instance, and the instance corresponding to the minimum score value is determined as the target instance for responding to the target request, and then the target request is forwarded to the target instance. Through the above scheme, the target request can be forwarded to the instance with the shortest response time to achieve load balancing.

[0067] For a more specific processing procedure of the above step S22, reference may be made to the corresponding contents disclosed in the above embodiments, which will not be described in detail here.

[0068] It can be seen that the embodiment of the present application obtains a target request sent by the first target service, and obtains the destination address of the target request, so as to determine a corresponding number of instances in the second target service based on the destination address; determines the average response time of each of the instances for requests within a preset historical time period, and determines whether the average response time of each of the instances is the same; if not, performs weighted random processing on the average response time of each of the instances to obtain a response time score value for each of the instances; filters out the minimum score value from the response time score values ​​of each of the instances, and determines the instance corresponding to the minimum score value as the target instance for responding to the target request, and then forwards the target request to the target instance. It can be seen that the corresponding number of instances can be determined from the second target service through the destination address of the target request, and then the average response time of each instance can be counted through the sidecar proxy, and it is determined whether the average response time of each instance is the same. If not, the average response time of each instance is weighted and randomly processed to obtain the corresponding response time score value, and then the instance corresponding to the minimum score value in the response time score value is used as the target instance for serving the target request, so as to make the response time of the request shorter, thereby achieving load balancing based on response time. If the average response time of each instance is the same, it means that the response speed of each instance to the request is roughly the same, then an instance can be randomly selected from a number of instances as the target instance, and then the target request is forwarded to the target instance.

[0069] The following takes the first target service as serviceA and the second target service as serviceB as an example to describe the load balancing method in this application in detail:

[0070] The target request is sent from serviceA to serviceB. After the target request is sent from serviceA, it is first intercepted by the sidecar proxy. After interception, the sidecar proxy filters out three instances in serviceB according to the destination address in the target request, which are recorded as serviceB-1, serviceB-2, and serviceB-3 respectively. Then the sidecar proxy obtains the average response time of the three instances of serviceB-1, serviceB-2, and serviceB-3 in the past five minutes, and further determines whether the three average response times are the same. If not, the average response times of the three instances are weighted and randomly processed to obtain the corresponding response time score values, and then the instance corresponding to the minimum score value in the response time score value is used as the target instance for serving the target request, so as to make the response of the request shorter and achieve load balancing. For example, if the final calculation result is that the response time score value of serviceB-2 is the smallest, serviceB-2 is used as the final target instance and the target request is forwarded to serviceB-2.

[0071] In a specific implementation, if the average response times of the three instances serviceB-1, serviceB-2, and serviceB-3 are the same, it means that the response speeds of the three instances serviceB-1, serviceB-2, and serviceB-3 to requests are roughly the same. Then, one instance can be randomly selected from the three instances as the target instance, and then the target request can be forwarded to the target instance. For example, the randomly selected target instance can be serviceB-1, and then the target request is forwarded to serviceB-1.

[0072] In a specific implementation, if serviceB is in the initial service request state, that is, serviceB is used for the service request for the first time, then one instance is randomly selected from serviceB-1, serviceB-2, and serviceB-3 as the target instance, and the target request is forwarded to this target instance. For example, the randomly selected target instance may be serviceB-3, and the target request is forwarded to serviceB-3.

[0073] join Figure 5 As shown, an embodiment of the present application discloses a load balancing device, which is applied to a sidecar proxy, and the device includes:

[0074] An instance determination module 11 is used to obtain a target request sent by a first target service, and determine a number of instances in a second target service based on the target request;

[0075] The weighted random module 12 is used to determine the average response time of each instance to the request in a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance;

[0076] The request forwarding module 13 is used to filter out a target instance from a number of the instances based on the response duration score value, and forward the target request to the target instance.

[0077] It can be seen that the present application discloses a load balancing device applied to a sidecar proxy, including: an instance determination module, which is used to obtain a target request sent by a first target service, and determine a number of instances in a second target service based on the target request; a weighted random module, which is used to determine the average response time of each instance for a request within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value for each instance; a request forwarding module, which is used to filter out a target instance from a number of instances based on the response time score value, and forward the target request to the target instance. It can be seen that after obtaining the target request sent by the first target service, the present application determines a number of instances in the second target service based on the obtained target request, determines the average response time of each instance for a request within a preset historical time period, and then weights the average response time and then processes it to obtain a response time score value for each instance, and finally filters out the target instance based on the response time score value, and forwards the target request to the target instance. The above technical solution can determine the response time of each instance to a request by utilizing the statistical capabilities of the sidecar proxy, and implements a load balancing strategy based on the response time. By selecting instances based on the response time score, the response time of the request can be shortened.

[0078] In some specific embodiments, the instance determination module 11 may specifically include:

[0079] A destination address acquisition module, used to acquire the destination address of the target request;

[0080] The instance screening unit is used to determine a corresponding number of instances in the second target service based on the destination address.

[0081] In some specific embodiments, after the instance determination module 11, the following may also be included:

[0082] A first random determination unit, configured to randomly determine a target instance from a plurality of instances if the second target service is in a first service request state;

[0083] The first forwarding unit is configured to forward the target request to the target instance.

[0084] In some specific embodiments, the process of the weighted random module 12 may also include:

[0085] A judging unit, used to judge whether the average response time of each of the instances is the same;

[0086] The weighted random processing unit is used to, if not, execute the step of performing weighted random processing on the average response time of each of the instances to obtain a response time score value of each of the instances.

[0087] In some specific embodiments, after the judging unit, the following may also be included:

[0088] A second random determination unit is used to randomly determine a target instance from a number of the instances if the average response time of each of the instances is the same;

[0089] The second forwarding unit is configured to forward the target request to the target instance.

[0090] In some specific embodiments, the load balancing device may further include:

[0091] a request time recording unit, configured to record a first time of obtaining a request, and to record a second time of forwarding the request to a corresponding instance in the second target service;

[0092] The average response duration determining unit is used to determine the request response duration of each instance based on the first time and the second time, so as to determine the average response duration of each instance within a preset historical time period based on the request response duration.

[0093] In some specific embodiments, the request forwarding module 13 may specifically include:

[0094] The target instance determination unit is used to filter out a minimum score value from the response duration score values ​​of each of the instances, and determine the instance corresponding to the minimum score value as the target instance for responding to the target request.

[0095] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the following steps:

[0096] Obtaining a target request sent by a first target service, and determining a number of instances of a second target service based on the target request;

[0097] Determine the average response time of each instance for requests within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance;

[0098] A target instance is screened out from a plurality of the instances based on the response duration score, and the target request is forwarded to the target instance.

[0099] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0100] Obtaining the destination address of the target request;

[0101] A corresponding number of instances of the second target service are determined based on the destination address.

[0102] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0103] If the second target service is in the first service request state, randomly determining a target instance from a number of the instances;

[0104] The target request is forwarded to the target instance.

[0105] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0106] Determining whether the average response time of each of the instances is the same;

[0107] If not, the step of performing weighted random processing on the average response time of each of the instances to obtain a response time score value of each of the instances is executed.

[0108] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0109] If the average response time of each of the instances is the same, randomly determining a target instance from a number of the instances;

[0110] The target request is forwarded to the target instance.

[0111] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0112] Recording a first time of obtaining the request, and recording a second time of forwarding the request to a corresponding instance in the second target service;

[0113] The request response duration of each instance is determined based on the first time and the second time, so as to determine the average response duration of each instance in a preset historical time period based on the request response duration.

[0114] In some specific implementations, the processor can implement the following steps by executing the computer program stored in the memory:

[0115] A minimum score value is screened out from the response duration score values ​​of each of the instances, and the instance corresponding to the minimum score value is determined as a target instance for responding to the target request.

[0116] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0117] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0118] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.

[0119] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows, Unix, Linux, etc. In addition to including a computer program that can be used to complete the load balancing method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data transmitted from an external device received by the electronic device, the data 223 can also include data collected by its own input and output interface 25, etc.

[0120] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the method steps performed in the load balancing process disclosed in any of the aforementioned embodiments are implemented.

[0121] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0122] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0123] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0124] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0125] The load balancing method, device, equipment and storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A load balancing method, characterized in that: Applicable to sidecar proxy, including: Obtaining a target request sent by a first target service, and determining a number of instances of a second target service based on the target request; Determine the average response time of each instance for requests within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance; Filtering a target instance from a number of the instances based on the response duration score, and forwarding the target request to the target instance; After determining the average response time of each instance to the request in the preset historical time period, the method further includes: Determining whether the average response time of each of the instances is the same; If not, executing the step of performing weighted random processing on the average response time of each of the instances to obtain a response time score value of each of the instances; After determining whether the average response time of each of the instances is the same, the method further includes: If the average response time of each of the instances is the same, randomly determining a target instance from a number of the instances; forwarding the target request to the target instance; The method further comprises: The sidecar proxy is used to intercept requests entering the first target service and process the requests to store the processed requests in a business container corresponding to the first target service; wherein the sidecar proxy and the business container are located in the same container group; The sidecar proxy is used to intercept requests flowing from the first target service and forward the requests to the second target service.

2. The load balancing method according to claim 1, characterized in that: The determining a number of instances of the second target service based on the target request includes: Obtaining the destination address of the target request; A corresponding number of instances of the second target service are determined based on the destination address.

3. The load balancing method according to claim 1, characterized in that: After determining a number of instances of the second target service based on the target request, the method further includes: If the second target service is in the first service request state, randomly determining a target instance from a number of the instances; The target request is forwarded to the target instance.

4. The load balancing method according to claim 1, characterized in that: Also includes: Recording a first time of obtaining the request, and recording a second time of forwarding the request to a corresponding instance in the second target service; The request response duration of each instance is determined based on the first time and the second time, so as to determine the average response duration of each instance in a preset historical time period based on the request response duration.

5. The load balancing method according to any one of claims 1 to 4, characterized in that: The step of selecting a target instance from a plurality of instances based on the response duration score includes: A minimum score value is screened out from the response duration score values ​​of each of the instances, and the instance corresponding to the minimum score value is determined as a target instance for responding to the target request.

6. A load balancing device, characterized in that: Applicable to sidecar proxy, including: An instance determination module, configured to obtain a target request sent by a first target service, and determine a number of instances in a second target service based on the target request; A weighted random module is used to determine the average response time of each instance to the request within a preset historical time period, and perform weighted random processing on the average response time of each instance to obtain a response time score value of each instance; A request forwarding module, configured to filter out a target instance from a plurality of instances based on the response duration score, and forward the target request to the target instance; After determining the average response time of each instance to the request within a preset historical time period, the device further includes: A judging unit, used to judge whether the average response time of each of the instances is the same; A weighted random processing unit, configured to, if no, execute the step of performing weighted random processing on the average response time of each of the instances to obtain a response time score value of each of the instances; After determining whether the average response time of each of the instances is the same, the device further includes: A second random determination unit is used to randomly determine a target instance from a number of the instances if the average response time of each of the instances is the same; A second forwarding unit, configured to forward the target request to the target instance; The sidecar proxy is used to intercept requests entering the first target service and process the requests to store the processed requests in a business container corresponding to the first target service; wherein the sidecar proxy and the business container are located in the same container group; The sidecar proxy is used to intercept requests flowing from the first target service and forward the requests to the second target service.

7. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the load balancing method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the load balancing method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Information interacting method and device

    CN104618429A

  • Load balancing algorithm based on Docker container cluster

    CN107888708A

  • Load balancing method, device and storage medium

    CN109408227A

  • Load balancing method and device and storage medium

    CN111355814A

  • Diagnosis request processing method, device, system and equipment and readable storage medium

    CN111521408A