Load balancing method, device, computer equipment, storage medium and product
By determining token generation rates and bucket capacities based on device status, the method enhances load balancing by reducing request loss rates through intelligent distribution of processing tasks among service providers.
Patent Information
- Application Number
- CN202210957691.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-10
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2042-08-10
AI Technical Summary
Current load balancing methods suffer from load imbalance and high loss rates in processing requests due to the inability to accurately assess and distribute processing tasks among service providers.
A load balancing method that involves obtaining device status information to determine a token generation rate and capacity of a token bucket, generating tokens based on this rate, and using the token bucket to distribute processing requests, with balancing coefficients sent to the service consumer to select the most appropriate service provider.
This approach effectively reduces the loss rate of processing requests by accurately evaluating the processing capacity of each service provider, avoiding timeouts and improving load distribution efficiency.
Smart Images

Figure CN115334082B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and in particular to a load balancing method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] Load balancing can refer to evenly distributing work tasks to multiple operation units for processing, so as to achieve collaborative completion of work tasks. In order to prevent the loss of service consumer processing requests due to timeout, load balancing methods can be used for corresponding processing.
[0003] In traditional technology, load balancing can be achieved by using a load balancing server. The load balancing server can maintain a service list, which records available service providers. When receiving a processing request sent by a service consumer, the load balancing server can determine an available service provider based on the service list, and the available service provider responds to the processing request of the service consumer, thereby reducing the pressure on the system.
[0004] However, current load balancing methods still suffer from load imbalance and a high loss rate in processing requests. Summary of the invention
[0005] Based on this, it is necessary to provide a load balancing method, apparatus, computer device, computer-readable storage medium and computer program product that can reduce the loss rate of processing requests in order to address the above technical problems.
[0006] In a first aspect, the present application provides a load balancing method. The method comprises:
[0007] Obtaining device status information of the service provider itself, and determining a token generation rate and a capacity of a token bucket based on the device status information;
[0008] Generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the tokens are used to instruct the service provider to process the received processing request;
[0009] Based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the balancing coefficient of the service provider is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing requests sent by the service consumer.
[0010] In one embodiment, obtaining the device status information of the service provider itself includes:
[0011] Obtaining current hardware usage rates of multiple hardware in the service provider, and determining a current request processing efficiency of the service provider for processing requests;
[0012] According to the multiple hardware utilization rates and the request processing efficiency, the current multiple device status information of the service provider is obtained
[0013] In one embodiment, determining a token generation rate and a capacity of a token bucket based on the device status information includes:
[0014] Obtaining a weight coefficient of each device status information, and determining a token generation rate based on each device status information and the weight coefficient of each device status information;
[0015] The capacity of the token bucket is determined based on the token generation rate and a preset processing cycle for processing requests.
[0016] In one embodiment, obtaining a weight coefficient of each device status information and determining a token generation rate based on each device status information and the weight coefficient of each device status information includes:
[0017] Determine the processing resources of the service provider based on the status information of each device and the weight coefficient of the status information of each device;
[0018] The token generation rate is obtained by determining a ratio of processing resources of the service provider to a predetermined processing time of a single processing request.
[0019] In one embodiment, the step of obtaining the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sending the balancing coefficient to the service consumer includes:
[0020] The number of tokens in the token bucket and the capacity of the token bucket are sent to a preset registration center, and the registration center obtains the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sends the balancing coefficient to the service consumer.
[0021] In one of the embodiments, after sending the equalization coefficient to the service consumer, the method further includes:
[0022] receiving a processing request sent by the service consumer, obtaining a token from the token bucket, and allocating the token to the processing request;
[0023] When a trigger condition for responding to a received processing request is met, the received processing request is responded to, and when it is detected that the received processing request carries a token, the received processing request is processed.
[0024] In a second aspect, the present application also provides a load balancing device. The device comprises:
[0025] An acquisition module, used to acquire device status information of the service provider itself, and determine a token generation rate and a capacity of a token bucket based on the device status information;
[0026] a token generation module, configured to generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the tokens are used to instruct the service provider to process the received processing request;
[0027] A balancing processing module is used to obtain a balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and send the balancing coefficient to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing request sent by the service consumer.
[0028] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of any of the above methods are implemented.
[0029] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0030] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0031] The load balancing method, device, computer equipment, storage medium and computer program product obtain the device status information of the service provider itself, and determine the token generation rate and the capacity of the token bucket based on the device status information; generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request; based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the balance coefficient of the service provider is obtained, and the balance coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balance coefficients of each service provider and then trigger the target service provider, obtain the token from the token bucket, and allocate it to the processing request sent by the service consumer. Before receiving the processing request, the service provider first obtains its own device status information, and then determines the token generation rate and the capacity of the token bucket based on its own device status information, thereby determining the balance coefficient of the service provider, and then determining the processing capacity of the service provider itself, so that the service consumer can select the corresponding target service provider according to the processing capacity of the service provider. On the one hand, compared with the existing load balancing server that evenly distributes the load to each service provider, this solution can effectively evaluate the processing capacity of each service provider, thereby avoiding the loss caused by the timeout of the processing request, and thus reducing the loss rate of the processing request. On the other hand, the present application converts the device status information into tokens, stores the converted tokens into a token bucket, and distributes the tokens in the token bucket to the service consumer, so that the balancing coefficient determined by the ratio of the number of tokens in the current token bucket to the capacity of the token bucket can more accurately determine the processing capacity of the service provider, and further reduce the loss rate of the processing request. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 An application environment diagram of a load balancing method in an embodiment;
[0033] Figure 2 A schematic diagram of a load balancing method in one embodiment;
[0034] Figure 3 is an application environment diagram of a load balancing method in another embodiment;
[0035] Figure 4 is a flow chart of a load balancing method in another embodiment;
[0036] Figure 5 is a structural block diagram of a load balancing device in one embodiment;
[0037] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0039] The load balancing method, apparatus, computer equipment, storage medium and computer program product of the present application can be used in the field of financial technology, and can also be used in other related fields besides the field of financial technology. The application field of the load balancing method, apparatus, computer equipment, storage medium and computer program product of the present application is not limited.
[0040] The load balancing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. The application environment may include: a service consumer 110 and a service provider 120; wherein the service consumer 110 communicates with the service provider 120 via a network. The service consumer may be a client or a server; the service provider may be a server or a server cluster.
[0041] In actual applications, the service provider can first obtain its own device status information, and determine the token generation rate and the capacity of the token bucket based on the device status information; then, generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; then, the service provider can determine the balancing coefficient of the service provider based on the ratio of the number of tokens in the current token bucket to the capacity of the token bucket, and send the balancing coefficient to the service consumer.
[0042] After receiving the balancing coefficients sent by each service provider, the server consumer can determine the target service provider based on the balancing coefficients of each service provider and trigger the target service provider to obtain tokens from the token bucket and allocate the tokens to the processing requests sent by the service consumer.
[0043] In one embodiment, Figure 2 As shown, a load balancing method is provided, which is applied to Figure 1 Taking the service provider 120 in the example as an example, the following steps are included:
[0044] Step S202: Acquire the device status information of the service provider itself, and determine the token generation rate and the capacity of the token bucket based on the device status information.
[0045] As an example, the device status information may be an indicator that affects the processing efficiency of the processing request. For example, it may be an indicator of hardware resources that affect the processing efficiency of the processing request, or it may be an indicator of software resources that affect the processing efficiency of the processing request. The token generation rate may be the number of tokens generated per unit time. The capacity of the token bucket may be the number of tokens that can be accommodated.
[0046] In actual applications, the service provider can obtain multiple device status information of itself at the current moment, and use the multiple device status information to determine the token generation rate and the capacity of the token bucket.
[0047] Step S204, generating tokens according to the token generation rate, and storing the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request.
[0048] In the specific implementation, the service provider generates tokens according to the token generation rate and determines whether the number of tokens in the current token bucket is less than the capacity of the token bucket; if so, the currently generated token is stored in the token bucket; if not, the currently generated token is discarded.
[0049] Step S206, based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, obtain the balancing coefficient of the service provider, and send the balancing coefficient to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing request sent by the service consumer.
[0050] As an example, the balancing coefficient may be information reflecting the occupancy of the service provider's own available resources (such as software resources and hardware resources), and the balancing coefficient may be positively correlated with the occupancy rate of the service provider's own available resources, that is, the larger the balancing coefficient, the higher the occupancy rate of the service provider's own available resources. The balancing coefficient may also be negatively correlated with the occupancy rate of the service provider's own available resources, that is, the larger the balancing coefficient, the lower the occupancy rate of the service provider's own available resources.
[0051] After storing the newly generated tokens in the token bucket, the service provider can count the tokens currently stored in the token bucket to determine the number of tokens in the token bucket, and then the service provider can calculate the ratio of the number of tokens in the token bucket at the current moment to the capacity of the token bucket, thereby obtaining the balancing coefficient; then, the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider according to the balancing coefficients sent by each service provider, and then trigger the target service provider to obtain tokens from its own token bucket and allocate them to the processing request sent by the service consumer.
[0052] It can be understood that the token in the present application can indicate the token of the service provider to process the processing request from the service consumer, and the token can be assigned to the corresponding processing request, so that the service provider can only process the processing request assigned with the token, and the token generation rate and the number of tokens (i.e., the capacity of the token bucket) of the token can be adjusted according to the device status information of the service provider itself. In other words, by adjusting the generation method of the token (i.e., the token generation rate and the number of tokens) according to the device status information of the service provider, the service provider can adjust the number of tokens that can be allocated to the processing request and the speed of allocation accordingly, thereby adjusting the number of processing requests that the service provider processes from the service consumer, and can limit the flow of processing requests that need to be processed, avoiding excessive traffic and increasing the load pressure of the service provider. On the other hand, the service provider determines the balancing coefficient based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket and sends it to the service consumer, so that the service consumer can determine the target service provider that supplies tokens as soon as possible from multiple service providers according to the balancing coefficient, avoiding sending the processing request to the service provider that is already in a high load state.
[0053] The load balancing method obtains the device status information of the service provider itself, and determines the token generation rate and the capacity of the token bucket based on the device status information; generates tokens according to the token generation rate, and stores the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request; based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the service provider's balancing coefficient is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider, obtain the token from the token bucket, and allocate it to the processing request sent by the service consumer. Before receiving the processing request, the service provider first obtains its own device status information, and then determines the token generation rate and the capacity of the token bucket based on its own device status information, thereby determining the service provider's balancing coefficient, and then determining the service provider's own processing capacity, so that the service consumer can select the corresponding target service provider according to the processing capacity of the service provider. On the one hand, compared with the existing load balancing server that evenly distributes the load to each service provider, this solution can effectively evaluate the processing capacity of each service provider, thereby avoiding the loss caused by the timeout of the processing request, and thus reducing the loss rate of the processing request. On the other hand, the present application converts the device status information into tokens, stores the converted tokens into a token bucket, and distributes the tokens in the token bucket to the service consumer, so that the balancing coefficient determined by the ratio of the number of tokens in the current token bucket to the capacity of the token bucket can more accurately determine the processing capacity of the service provider, and further reduce the loss rate of the processing request.
[0054] In one embodiment, the step of obtaining the device status information of the service provider itself in step 202 includes:
[0055] Step 2021, obtaining the current hardware usage rate of multiple hardware in the service provider, and determining the request processing efficiency of the service provider for processing requests.
[0056] As an example, the service provider includes multiple hardware, such as CPU, memory, disk, and network equipment. The hardware usage rate can be at least two of the CPU usage rate, memory usage rate, disk IO usage rate, and network bandwidth usage rate. The request processing efficiency can be one or more of the concurrent number of processing requests, transaction throughput, and request processing success rate.
[0057] Step 2022: obtaining the current status information of multiple devices of the service provider according to multiple hardware utilization rates and request processing efficiencies.
[0058] In actual applications, the service provider's current multiple device status information may be composed of multiple hardware utilization rates and request processing efficiencies.
[0059] In this embodiment, by using multiple hardware utilization rates and request processing efficiencies as multiple device status information, the token generation rate and the capacity of the token bucket can be accurately determined, thereby accurately determining the balance coefficient of the service provider, thereby reducing the loss rate of processing requests.
[0060] In one embodiment, the step of determining the token generation rate and the capacity of the token bucket based on the device status information in step 202 includes:
[0061] Step 2023, obtaining the weight coefficient of each device status information, and determining the token generation rate based on each device status information and the weight coefficient of each device status information.
[0062] In actual applications, different hardware devices or software conditions have different degrees of influence on the processing capabilities of the service provider. Corresponding weight coefficients can be pre-assigned to different device status information. For example, the weight coefficient can be determined based on the degree of influence of the device status information on the token generation rate. Each weight coefficient can also be determined based on the business scenario. If it is a CPU-intensive scenario, the weight coefficient corresponding to the CPU usage rate can be increased. If it is a scenario with high memory requirements, the weight coefficient corresponding to the memory usage rate can be increased. After obtaining the current multiple device status information of the service provider, the weight coefficients corresponding to each device status information can be obtained respectively, and then the token generation rate can be determined based on each device status information and the weight coefficient of each device status information.
[0063] Step 2024, determining the capacity of the token bucket based on the token generation rate and the preset processing cycle for processing requests.
[0064] As an example, the product of the token generation rate and the preset processing cycle of the processing request can be used as the capacity of the token bucket. The size of the processing cycle of the processing request can be defined according to business requirements. Exemplarily, the capacity of the token bucket can be obtained according to the following formula.
[0065] Bc=Tc×CIR
[0066]
[0067] Wherein, Bc is the capacity of the token bucket, Tc is the preset processing cycle for processing requests, and CIR is the token generation rate. u is the hardware utilization rate, such as CPU utilization rate, memory utilization rate, disk IO utilization rate, and network bandwidth utilization rate; when any one of the CPU utilization rate, memory utilization rate, disk IO utilization rate, and network bandwidth utilization rate is 1, u is equal to 1, and at this time, the capacity of the token bucket is 0. When the values of CPU utilization rate, memory utilization rate, disk IO utilization rate, and network bandwidth utilization rate are all 0, u = 0, and at this time, the theoretical maximum token bucket capacity can be obtained.
[0068] In this embodiment, the capacity of the token bucket can be determined by the token generation rate, which can avoid the value of the token bucket capacity being set too large or too small, making the token bucket capacity setting more reasonable, thereby facilitating accurate assessment of the processing capacity of the service provider and further reducing the loss rate of processing requests.
[0069] In one embodiment, the step of obtaining the weight coefficient of each device status information in step 2023 and determining the token generation rate based on each device status information and the weight coefficient of each device status information includes:
[0070] Step 20231, based on the status information of each device and the weight coefficient of the status information of each device, determine the processing resources of the service provider.
[0071] In one example, the device status information may also include the number of CPU cores.
[0072] In a specific application, the processing resources of the service provider can be calculated according to the following formula.
[0073]
[0074] Among them, Y is the processing resource, δ C is the weight coefficient of CPU usage, δ m is the weight coefficient of memory usage, δ io is the weight coefficient of disk IO usage, δw is the weight coefficient of network bandwidth utilization, δ Co is the weight coefficient for the concurrent processing of requests, c C is the number of CPU cores, u C is the CPU usage, u m is the memory usage, u io is the disk IO usage, u w is the network bandwidth utilization rate, co is the concurrent number of processing requests. And, 0≤δ C , δ m , δ io , δ w , δ Co , and 0≤u C 、u m 、u io 、u w ≤1. Since these indicators are constantly changing, the token generation rate and the capacity of the token bucket are also constantly changing.
[0075] Step 20232, determine the ratio of the processing resources of the service provider to the predetermined processing time of a single processing request to obtain a token generation rate.
[0076] In a specific application, the token generation rate can be calculated according to the following formula.
[0077]
[0078] Where CIR is the token generation rate, t p is the processing time of a single processing request, preferably, t p The average processing time for processing requests.
[0079] In this embodiment, through the above hardware utilization rate and request processing efficiency, the token generation rate and the capacity of the token bucket are not fixed, which can better reflect the processing capacity of the current service provider, accurately evaluate the processing capacity of the service provider, and reduce the loss rate of processing requests. In addition, the service provider calculates the token generation rate and the capacity of the token bucket by itself, which can eliminate time errors in scenarios with large transaction volumes and high concurrency, thereby improving the effectiveness and accuracy of the evaluation of the service provider's processing capacity.
[0080] In one embodiment, the step of obtaining the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket and sending the balancing coefficient to the service consumer in step 204 includes:
[0081] The number of tokens in the token bucket and the capacity of the token bucket are sent to the preset registration center, which obtains the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sends the balancing coefficient to the service consumer.
[0082] In one example, the registration center may calculate the balancing coefficient of the service provider according to the following formula.
[0083]
[0084] Among them, W p (i) is the equilibrium coefficient of the current service provider, T p (i) is the number of tokens in the token bucket of the current service provider, that is, the token inventory, V b (i) is the capacity of the token bucket of the current service provider. The larger the balancing coefficient, the smaller the probability of the service provider being called.
[0085] In this embodiment, the registration center determines the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and then sends the balancing coefficient to the service consumer, which can alleviate the processing pressure of the service provider and thus reduce the loss rate of processing requests.
[0086] In one example, multiple registration centers may be set up, and the registration centers may be set up outside the service providers. Each registration center may be connected to multiple service providers, and one service provider is only connected to one registration center.
[0087] In this embodiment, since the token generation rate and the token bucket capacity are determined based on the device status information of the service provider, when the device status information of the service provider changes, the token generation rate and the capacity of the token bucket also change. When the token generation rate is slower, the number of generated tokens is smaller, and the number of tokens in the token bucket decreases accordingly. When the token generation rate is faster, the number of generated tokens increases, and the number of tokens in the token bucket increases accordingly. This can accurately reflect the current processing capacity of the service provider and is more conducive to achieving load balancing.
[0088] In one embodiment, the method further comprises:
[0089] Step S208, receiving a processing request sent by a service consumer, obtaining a token from a token bucket, and allocating the token to the processing request.
[0090] In specific applications, the processing requests can be sorted according to the order of the processing requests sent by the service consumer. If the sorting queue is full, the service consumer can be fed back with information that the token acquisition queue is full, so that the service consumer can re-determine a new target service provider to avoid the loss of processing requests. Then, it can be detected whether there are tokens in the token bucket; if so, a token is obtained and assigned to the current processing request. If not, a token acquisition failure message is sent to the service consumer so that the service consumer can re-determine a new target service provider to avoid the loss of processing requests.
[0091] Step S210, when the triggering condition for responding to the received processing request is met, respond to the received processing request, and when it is detected that the received processing request carries a token, process the received processing request.
[0092] In specific applications, after the service provider assigns a token to a processing request, it may not process it immediately, but instead process the previously received processing request after a certain period of triggering conditions are met. If the processing request currently responding to the demand carries a token, the request will be processed; if the processing request does not carry a token, the processing request will not be processed, and a busy processing message will be returned to the service consumer so that the service consumer can re-determine a new target service provider to avoid the loss of the processing request due to too long waiting time.
[0093] In this embodiment, the service provider allocates tokens to processing requests and processes the processing requests carrying the tokens, and can determine the processing requests according to its own processing capabilities, reduce the accumulation of processing requests, and further reduce the loss rate of processing requests.
[0094] In order to enable those skilled in the art to better understand the above steps, the embodiment of the present application is illustrated below by using an example, but it should be understood that the embodiment of the present application is not limited to this.
[0095] This embodiment can be applied to Figure 3-4 In the application environment shown, the application environment may include a service provider, a registration center, and a service consumer.
[0096] The service provider first determines the token generation rate and the capacity of the token bucket based on the device status information; then generates tokens according to the token generation rate, and determines whether the number of tokens in the token bucket is less than the capacity of the token bucket. If so, the currently generated token is stored in the token bucket. If not, the currently generated token is discarded. Then, the service provider's identification information and token registration information are sent to the registration center. The token registration information is the number of tokens in the current token bucket and the capacity of the token bucket.
[0097] Each registration center can register after receiving the number of tokens in the token bucket and the capacity of the token bucket sent by the service provider, and then determine the weight of the service provider based on the number of tokens in the token bucket and the capacity of the token bucket sent by the service provider, that is, determine the balance coefficient of the service provider.
[0098] When a service consumer needs to discover and subscribe to messages from a service provider, the service consumer can determine the target registry from multiple registry centers through a load balancing server; then obtain multiple balancing coefficients in the target registry from the target registry; and then determine the target service provider based on the size of the balancing coefficient. Then, the processing request (i.e., service request) can be sent to the target service provider.
[0099] The service provider may also receive a processing request from the service consumer, and then detect whether there is any remaining space in the request queue of the current processing request. If so, the processing request is added to the request queue; if not, the processing request is discarded.
[0100] Then the service provider can sequentially obtain processing requests from the request queue and allocate tokens. Specifically, the service provider can detect whether there are tokens in the token bucket. If so, it can obtain a token and allocate the token to the current processing request and update the information of the token in the token bucket. If not, it will send a message to the service consumer that the token acquisition failed and refuse to process the processing request sent by the service consumer. The service provider can also process the processing request when it detects that the processing request carries a token, and return the processing result to the service consumer.
[0101] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0102] Based on the same inventive concept, the embodiment of the present application also provides a load balancing device for implementing the load balancing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the two load balancing device embodiments provided below can refer to the limitations on the load balancing method above, and will not be repeated here.
[0103] In one embodiment, Figure 5 As shown, a load balancing device is provided, comprising:
[0104] The acquisition module 31 is used to acquire the device status information of the service provider itself, and determine the token generation rate and the capacity of the token bucket based on the device status information;
[0105] The token generation module 32 is used to generate tokens according to the token generation rate and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request;
[0106] The balancing processing module 33 is used to obtain the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and send the balancing coefficient to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing requests sent by the service consumer.
[0107] In one embodiment, the acquisition module 31 is specifically configured to:
[0108] Obtain current hardware utilization rates of multiple hardware in the service provider, and determine the current request processing efficiency of the service provider for processing requests;
[0109] According to multiple hardware utilization rates and request processing efficiencies, the current multiple device status information of the service provider is obtained.
[0110] In one embodiment, the acquisition module 31 is specifically configured to:
[0111] Obtaining a weight coefficient of each device status information, and determining a token generation rate based on each device status information and the weight coefficient of each device status information;
[0112] The capacity of the token bucket is determined based on the token generation rate and a preset processing cycle for processing requests.
[0113] In one embodiment, the acquisition module 31 is specifically configured to:
[0114] Obtaining a weight coefficient of each device status information, and determining a token generation rate based on each device status information and the weight coefficient of each device status information, including:
[0115] Determine the processing resources of the service provider based on the status information of each device and the weight coefficient of the status information of each device;
[0116] The ratio of the processing resources of the service provider to the predetermined single processing time is determined to obtain the token generation rate.
[0117] In one embodiment, the equalization processing module 33 is specifically used to:
[0118] The steps of obtaining a balancing coefficient of a service provider based on a ratio of the number of tokens in a token bucket to the capacity of the token bucket and sending the balancing coefficient to a service consumer include:
[0119] The number of tokens in the token bucket and the capacity of the token bucket are sent to the preset registration center, which obtains the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sends the balancing coefficient to the service consumer.
[0120] In one embodiment, the apparatus further comprises:
[0121] The token allocation module is used to receive the processing request sent by the service consumer, obtain the token from the token bucket, and allocate the token to the processing request;
[0122] The processing module is used to respond to the received processing request when a triggering condition for responding to the received processing request is met, and to process the received processing request when it is detected that the received processing request carries a token.
[0123] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a load balancing method is implemented.
[0124] Those skilled in the art will understand that Figure 6The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0125] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0126] Obtain the service provider's own device status information, and determine the token generation rate and token bucket capacity based on the device status information;
[0127] Generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request;
[0128] Based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the balancing coefficient of the service provider is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing requests sent by the service consumer.
[0129] In one embodiment, when the processor executes the computer program, the steps in the other embodiments described above are also implemented.
[0130] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0131] Obtain the service provider's own device status information, and determine the token generation rate and token bucket capacity based on the device status information;
[0132] Generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request;
[0133] Based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the balancing coefficient of the service provider is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing requests sent by the service consumer.
[0134] In one embodiment, when the processor executes the computer program, the steps in the other embodiments described above are also implemented.
[0135] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0136] Obtain the service provider's own device status information, and determine the token generation rate and token bucket capacity based on the device status information;
[0137] Generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the token is used to instruct the service provider to process the received processing request;
[0138] Based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, the balancing coefficient of the service provider is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing requests sent by the service consumer.
[0139] In one embodiment, when the processor executes the computer program, the steps in the other embodiments described above are also implemented.
[0140] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0141] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0142] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A load balancing method, characterized in that: The method comprises: Obtaining device status information of the service provider itself, and determining a token generation rate and a capacity of a token bucket based on the device status information; Generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the tokens are used to instruct the service provider to process the received processing request; Based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, a balancing coefficient of the service provider is obtained, and the balancing coefficient is sent to the service consumer, so that the service consumer determines the target service provider based on the balancing coefficients of each service provider and then triggers the target service provider to obtain tokens from the token bucket and allocate them to the processing request sent by the service consumer; The obtaining of the device status information of the service provider itself includes: Obtaining current hardware usage rates of multiple hardware in the service provider, and determining a current request processing efficiency of the service provider for processing requests; According to multiple hardware usage rates and the request processing efficiency, obtaining multiple device status information of the service provider; The determining of a token generation rate and a capacity of a token bucket based on the device status information includes: Obtaining a weight coefficient of each device status information, and determining a token generation rate based on each device status information and the weight coefficient of each device status information; The capacity of the token bucket is determined based on the token generation rate and a preset processing cycle for processing requests.
2. The method according to claim 1, characterized in that The obtaining of the weight coefficient of each device status information and determining the token generation rate based on each device status information and the weight coefficient of each device status information includes: Determine the processing resources of the service provider based on the status information of each device and the weight coefficient of the status information of each device; The token generation rate is obtained by determining a ratio of processing resources of the service provider to a predetermined processing time of a single processing request.
3. The method according to claim 1, characterized in that: The step of obtaining the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sending the balancing coefficient to the service consumer comprises: The number of tokens in the token bucket and the capacity of the token bucket are sent to a preset registration center, and the registration center obtains the balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and sends the balancing coefficient to the service consumer.
4. The method according to claim 1, characterized in that: After sending the equalization coefficient to the service consumer, the method further includes: receiving a processing request sent by the service consumer, obtaining a token from the token bucket, and allocating the token to the processing request; When a trigger condition for responding to a received processing request is met, the received processing request is responded to, and when it is detected that the received processing request carries a token, the received processing request is processed.
5. A load balancing device, characterized in that: The device comprises: An acquisition module, used to acquire device status information of the service provider itself, and determine a token generation rate and a capacity of a token bucket based on the device status information; a token generation module, configured to generate tokens according to the token generation rate, and store the tokens in the token bucket when the number of tokens in the token bucket is less than the capacity of the token bucket; the tokens are used to instruct the service provider to process the received processing request; A balancing processing module, used to obtain a balancing coefficient of the service provider based on the ratio of the number of tokens in the token bucket to the capacity of the token bucket, and send the balancing coefficient to the service consumer, so that the service consumer can determine the target service provider based on the balancing coefficients of each service provider and then trigger the target service provider to obtain tokens from the token bucket and allocate them to the processing request sent by the service consumer; The acquisition module is used to acquire the current hardware usage rate of multiple hardware in the service provider, and determine the current request processing efficiency of the service provider for processing requests; According to multiple hardware usage rates and the request processing efficiency, obtaining multiple device status information of the service provider; The acquisition module is used to acquire the weight coefficient of each device status information, and determine the token generation rate based on each device status information and the weight coefficient of each device status information; The capacity of the token bucket is determined based on the token generation rate and a preset processing cycle for processing requests.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
