Load balancing method and device and load balancer
By calculating the performance weight in the load balancer based on the server's load information and configuration information, and combining the random numbers to calculate the expected weight, and dynamically scheduling the target server, the problem that the traditional load balancing method cannot dynamically schedule servers with different computing power is solved, and dynamic Load balancing.
Patent Information
- Application Number
- CN202411503736.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-10-25
AI Technical Summary
Traditional load balancing methods cannot perceive servers with different computing power, and require artificially configuring weights for different servers, so they cannot dynamically schedule the load based on server computing power.
By determining the performance weight of each server based on the load information and configuration information of multiple servers in the server cluster, using random numbers and performance weights to calculate the expected weight, the target server is dynamically scheduled to achieve load balancing.
It realizes compatibility with servers with different computing power and realizes dynamic scheduling according to the load status of the server, thereby achieving dynamic load balancing of servers with different computing power in the server cluster.
Smart Images

Figure CN119342054A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a load balancing method, device and load balancer. Background Art
[0002] With the rapid growth of Internet traffic, many websites and network services are beginning to face a large-scale user range, resulting in a sharp increase in server load. The traditional single server architecture cannot meet the requirements of high traffic and high performance.
[0003] A load balancer can distribute requests to multiple servers or computing resources, thereby reducing the load pressure on a single server and ensuring high availability, high performance, and scalability of network services.
[0004] However, traditional load balancing methods cannot perceive servers with different computing powers and require artificially configuring weights for different servers, making it impossible to dynamically schedule the load based on the server computing power. Summary of the invention
[0005] The purpose of the present application is to provide a load balancing method, device and load balancer to address the deficiencies in the above-mentioned prior art, so as to be compatible with servers with different computing powers and achieve load balancing through dynamic scheduling of servers.
[0006] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:
[0007] In a first aspect, an embodiment of the present application provides a load balancing method, which is applied to a load balancer, and the method includes:
[0008] Determining performance weights of the multiple servers respectively according to load information and configuration information of the multiple servers in the server cluster;
[0009] In response to a triggering event of a target network load, generating a random number for the target network load;
[0010] Determining an expected weight for the target network load according to the performance weights of the multiple servers and the random number;
[0011] Determining a target server from the multiple servers according to the performance weights of the multiple servers and the expected weights;
[0012] A scheduling request for the target network load is issued to the target server, so that the target server processes the target network load.
[0013] Optionally, the configuration information of each server includes: a processing configuration parameter and a network bandwidth configuration parameter of each server; and determining the performance weights of the multiple servers respectively according to the load information and configuration information of the multiple servers in the server cluster includes:
[0014] Calculating a weight numerator of each server according to the processing configuration parameters and the network bandwidth configuration parameters of each server;
[0015] The performance weight of each server is calculated according to the load information and the weight numerator of each server.
[0016] Optionally, the processing configuration parameters include: the number of processing cores and the processing frequency; and the calculating the weight numerator of each server according to the processing configuration parameters and the network bandwidth configuration parameters of each server includes:
[0017] Calculate the processing parameters of each server according to the number of processing cores and the processing frequency of each server;
[0018] The weight numerator of each server is calculated according to the processing parameters and network bandwidth configuration parameters of each server.
[0019] Optionally, the load information includes: processor utilization and network utilization; and calculating the performance weight of each server according to the load information and weight numerator of each server includes:
[0020] Calculating the load of each server according to the processor utilization and network utilization of each server;
[0021] The performance weight of each server is calculated according to the load of each server and the weight numerator.
[0022] Optionally, the generating a random number for the target network load includes:
[0023] A quantum random number generator is used to generate a quantum random number as a random number of the target network load.
[0024] Optionally, determining an expected weight for the target network load according to the performance weights of the multiple servers and the random number includes:
[0025] An expected weight for the target network load is determined according to a product of a total weight sum of the performance weights of the plurality of servers and the random number.
[0026] Optionally, determining a target server from the multiple servers according to the performance weights of the multiple servers and the expected weights includes:
[0027] According to the size of the performance weight, traversing the multiple servers in sequence;
[0028] Calculate the accumulated weight of the currently traversed server according to the performance weight of the currently traversed server and the performance weights of the traversed servers;
[0029] If the accumulated weight is greater than or equal to the expected weight, determining the current traversal server as the target server;
[0030] If the accumulated weight is less than the expected weight, the multiple servers are continuously traversed until the target server is obtained.
[0031] Optionally, the method further comprises:
[0032] Obtain configuration information and load information of the new access server;
[0033] Determining a performance weight of the new access server according to the configuration information and load information of the new access server;
[0034] The new access server is added to the server cluster, and the performance weight of the new access server is stored.
[0035] In a second aspect, an embodiment of the present application further provides a load balancing device, applied to a load balancer, the device comprising:
[0036] A weight determination module, used to determine the performance weights of the multiple servers in the server cluster according to the load information and configuration information of the multiple servers;
[0037] A random number generation module, used to generate a random number for the target network load in response to a triggering event of the target network load;
[0038] The weight determination module is further used to determine an expected weight for the target network load according to the performance weights of the multiple servers and the random number;
[0039] A server determination module, configured to determine a target server from the plurality of servers according to the performance weights of the plurality of servers and the expected weights;
[0040] The request sending module is used to send a scheduling request for the target network load to the target server, so that the target server processes the target network load.
[0041] Optionally, the configuration information of each server includes: processing configuration parameters and network bandwidth configuration parameters of each server; the weight determination module includes:
[0042] A weight numerator calculation unit, used to calculate the weight numerator of each server according to the processing configuration parameters and network bandwidth configuration parameters of each server;
[0043] The performance weight calculation unit is used to calculate the performance weight of each server according to the load information and the weight numerator of each server.
[0044] Optionally, the processing configuration parameters include: the number of processing cores and the processing frequency; the weight numerator calculation unit is specifically used to calculate the processing parameters of each server based on the number of processing cores and the processing frequency of each server; and calculate the weight numerator of each server based on the processing parameters of each server and the network bandwidth configuration parameters.
[0045] Optionally, the load information includes: processor utilization and network utilization; the performance weight calculation unit is specifically used to calculate the load of each server according to the processor utilization and network utilization of each server; and calculate the performance weight of each server according to the load and weight numerator of each server.
[0046] Optionally, the random number generation module is specifically configured to use a quantum random number generator to generate a quantum random number as a random number for the target network load.
[0047] Optionally, the weight determination module is further used to determine an expected weight for the target network load based on a product of a total weight sum of the performance weights of the multiple servers and the random number.
[0048] Optionally, the server determination module is specifically used to traverse the multiple servers in sequence according to the size of the performance weight; calculate the cumulative weight of the currently traversed server according to the performance weight of the currently traversed server and the performance weights of the traversed servers; if the cumulative weight is greater than or equal to the expected weight, determine that the currently traversed server is the target server; if the cumulative weight is less than the expected weight, continue to traverse the multiple servers until the target server is traversed.
[0049] Optionally, the device further comprises:
[0050] The server access module is used to obtain the configuration information and load information of the new access server; determine the performance weight of the new access server according to the configuration information and load information of the new access server; add the new access server to the server cluster, and store the performance weight of the new access server.
[0051] In a third aspect, an embodiment of the present application also provides a load balancer, comprising: a processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor, and when the load balancer is running, the processor communicates with the storage medium through the bus, and the processor executes the program instructions to perform the steps of the load balancing method as described in any one of the first aspects.
[0052] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the load balancing method as described in any one of the first aspects are executed.
[0053] The beneficial effects of this application are:
[0054] The load balancing method, device and load balancer provided in the present application determine the performance weight of each server based on the load information and configuration information of each server in the server cluster, determine the expected weight according to the random number generated for the target network load and the performance weights of multiple servers, determine the target server from multiple servers according to the performance weights of multiple servers and the performance weights, so that the target server processes the target network load, calculates the performance weight based on the configuration information of the server, and can achieve compatibility with servers with different computing powers. The performance weight is calculated based on the load information of the server, and the server can be dynamically scheduled according to the load status of the server, thereby achieving dynamic load balancing of servers with different computing powers in a compatible server cluster. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0056] Figure 1 A schematic diagram of the architecture of the load balancing system provided in an embodiment of the present application;
[0057] Figure 2 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 1 ;
[0058] Figure 3 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 2 ;
[0059] Figure 4 Schematic diagram of the load configuration method provided in the embodiment of the present application Figure 3 ;
[0060] Figure 5 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 4 ;
[0061] Figure 6 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 5 ;
[0062] Figure 7 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 6 ;
[0063] Figure 8 A schematic diagram of load balancing provided in an embodiment of the present application;
[0064] Fig. 9 A schematic diagram of the structure of a load balancing device provided in an embodiment of the present application;
[0065] Fig.10 A schematic diagram of a load balancer provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0067] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0068] In addition, the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0069] It should be noted that, in the absence of conflict, the features in the embodiments of the present application may be combined with each other.
[0070] The load balancing method provided in this application is applied to a load balancer in a load balancing system. Figure 1 The schematic diagram of the architecture of the load balancing system provided in the embodiment of the present application is as follows: Figure 1 As shown, the load balancing system may at least include: a load balancer 100 and multiple servers 200, and the multiple servers 200 constitute a server cluster.
[0071] Among them, the load balancer can be deployed on a Linux server, and the load balancing program is run through the Linux server to execute the load balancing method provided in this application.
[0072] Figure 2 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 1 ,like Figure 2 As shown, the method may include:
[0073] S201: Determine performance weights of the multiple servers respectively according to load information and configuration information of the multiple servers in the server cluster.
[0074] In this embodiment, the server cluster includes multiple servers, which can be servers of the same type or servers of different types. The configuration information of the server is the computing power information configured when the server accesses the server cluster, and the computing power information is used to indicate the amount of load that the server can bear. The load information of the server is the load status information of the load task currently being executed by the server, that is, the computing power utilization rate of the server.
[0075] The load balancer can determine the performance weight of the server by parsing the server's load information and configuration information and calculating the server's load information and configuration information. The performance weight is used to indicate the server's remaining computing power information that can bear the load. The more load tasks the server is currently executing and the more complex the load tasks are, the smaller the server's performance weight is. The fewer load tasks the server is currently executing and the simpler the load tasks are, the greater the server's performance weight is.
[0076] For example, the performance weight of the server may be determined based on the ratio of the configuration information to the load information of the server.
[0077] In some embodiments, the load balancer may obtain load information of multiple servers each time a new network load is received, and calculate performance weights of the multiple servers based on configuration information saved when the multiple servers are connected to the server cluster.
[0078] In other embodiments, the load balancer may calculate the performance weights of the multiple servers based on the load information reported by the multiple servers through periodic heartbeats and the configuration information saved when the multiple servers are connected to the server cluster.
[0079] S202: In response to a triggering event of a target network load, generate a random number for the target network load.
[0080] In this embodiment, the target network load is the target work task received by the server cluster, the trigger event of the target network load is the processing request for the target work task received by the server cluster, and the load balancer generates a random number for the target network load after receiving the trigger event for the target network load, wherein the random number is a random number in the interval [0-1].
[0081] In some embodiments, the load balancer may also include a random number generator, and after receiving a trigger event of the target network load, the load balancer uses the random number generator to generate a random number for the target network load. Based on the random number generator, a different random number can be generated for each network load that requests the server cluster to process, so as to ensure that different network loads can be allocated to different servers for processing.
[0082] S203: Determine an expected weight for the target network load according to the performance weights of the multiple servers and the random number.
[0083] In this embodiment, the expected weight may be a performance weight that can be satisfied by the target network load and is determined according to a random number. The performance weights of multiple servers may be calculated according to the random number to determine the expected weight.
[0084] In some embodiments, the expected weight may be calculated by determining the random performance weights of multiple servers based on the product of the performance weights of the multiple servers and a random number, and determining the expected weight based on the random performance weights of the multiple servers. The expected weight may be the maximum value, the middle value, or the average value of the random performance weights of the multiple servers.
[0085] In other embodiments, the expected weight may be calculated by determining the average performance weight of a server cluster based on the performance weights of multiple servers, and determining the expected weight of the target network load based on the average performance weight and a random number, wherein the expected weight of the target network load may be determined based on the product of the average performance weight and the random number.
[0086] For example, the average performance weight may be an arithmetic mean, a weighted mean, a mean square average, etc. of the performance weights of multiple servers, which is not limited in this embodiment.
[0087] S204: Determine a target server from the multiple servers according to the performance weights and expected weights of the multiple servers.
[0088] In this embodiment, the performance weights of multiple servers are compared with expected weights, and the server corresponding to the performance weight that meets the conditions is determined as the target server.
[0089] In some embodiments, the difference between the performance weights and expected weights of multiple servers may be calculated, and the server corresponding to the performance weight having a performance weight greater than the expected weight and the smallest difference with the expected weight may be determined as the target server.
[0090] In other embodiments, the performance weights of multiple servers may be sorted from small to large, and the relationship between the performance weight and the expected weight of each server may be determined in turn, and the first server corresponding to a performance weight greater than the expected weight may be determined as the target server.
[0091] S205: Sending a scheduling request for the target network load to the target server, so that the target server processes the target network load.
[0092] In this implementation, after the load balancer determines the target server from multiple servers in the server cluster, it sends a scheduling request for the target network load to the target server, and the target server executes the target network load to obtain a load execution result.
[0093] The load balancing method provided in the above embodiment determines the performance weight of each server based on the load information and configuration information of each server in the server cluster, determines the expected weight based on the random number generated for the target network load and the performance weights of multiple servers, determines the target server from multiple servers based on the performance weights of multiple servers and the performance weights, so that the target network load is processed by the target server, and calculates the performance weight based on the configuration information of the server, so as to achieve compatibility with servers with different computing powers. The performance weight is calculated based on the load information of the server, and the server can be dynamically scheduled according to the load status of the server, thereby achieving dynamic load balancing of servers with different computing powers in a compatible server cluster.
[0094] In one possible implementation, Figure 3 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 2 ,like Figure 3 As shown, the process of respectively determining the performance weights of the multiple servers according to the load information and configuration information of the multiple servers in the server cluster in S201 may include:
[0095] S211: Calculate the weight numerator of each server according to the processing configuration parameters and network bandwidth configuration parameters of each server.
[0096] The configuration information of each server includes: processing configuration parameters and network bandwidth configuration parameters of each server.
[0097] In this embodiment, the processing configuration parameter of the server is a parameter indicating the hardware processing performance of the server, and the processing configuration parameter is a fixed value. The network bandwidth configuration parameter of the server indicates the network bandwidth of the server.
[0098] The server's hardware processing performance and network bandwidth determine the server's computing power, that is, the amount of load the server can bear. When calculating the server's performance weight based on the server's load information and configuration information, the server's configuration information is used as the weight numerator. Specifically, the weight numerator can be calculated based on the processing configuration parameters and the network bandwidth configuration parameters.
[0099] For example, the calculation formula of the weight numerator can be expressed as: weight numerator = processing configuration parameter + network bandwidth configuration parameter.
[0100] S212: Calculate the performance weight of each server according to the load information and weight numerator of each server.
[0101] In this embodiment, a weight denominator is generated based on the load information of the processor. The performance weight of each server can be calculated based on the ratio of the weight numerator and the weight denominator of each server, wherein the load information of the server indicates the computing power utilization of the server, and the computing power utilization is a value less than 1. In order to determine that the more load tasks the server is currently executing and the more complex the load tasks are, the smaller the performance weight of the server is, it is necessary to obtain a weight denominator greater than 1 based on the load information of the processor and the preset value.
[0102] For example, the calculation formula of the performance weight of the server can be expressed as: performance weight=weight numerator / (1+load information), where 1+load information is the weight denominator.
[0103] In one possible implementation, Figure 4 Schematic diagram of the load configuration method provided in the embodiment of the present application Figure 3 ,like Figure 4 As shown, the process of calculating the weight numerator of each server according to the processing configuration parameters and network bandwidth configuration parameters of each server in S211 may include:
[0104] S301: Calculate the processing parameters of each server according to the number of processing cores and processing frequency of each server.
[0105] S302: Calculate the weight numerator of each server according to the processing parameters and network bandwidth configuration parameters of each server.
[0106] The processing configuration parameters of the processor include: the number of processing cores and the processing frequency.
[0107] In this embodiment, the number of processing cores is the number of integrated computing cores of the central processing unit (CPU) of the server, such as single core, multi-core, etc., and the processing frequency is the computing frequency of the central processing unit, such as 1GHZ, 2GHZ, etc.
[0108] The number of processing cores and processing frequency of the server determine the processing efficiency of the server. The processing parameters of the server are calculated based on the number of processing cores and processing frequency of the server. The calculation formula of the processing parameters can be expressed as: number of processing cores*processing frequency.
[0109] The processing parameters of the server indicate the hardware processing performance of the server. The network bandwidth configuration parameters of the server indicate the network bandwidth of the server. The hardware processing performance and network bandwidth of the server determine the computing power of the server, that is, the amount of load that the server can bear. Specifically, the weight numerator can be calculated based on the processing parameters and the network bandwidth configuration parameters.
[0110] The load balancing method provided in the above embodiment calculates the weight numerator of each server according to the processing configuration parameters and network bandwidth configuration parameters of each server, and calculates the performance weight according to the load information and weight numerator of each server. Servers with different processing configuration parameters and network bandwidth configuration parameters can be connected to the server cluster, thereby achieving compatibility with servers with different computing powers and improving the processing efficiency of the network load.
[0111] In one possible implementation, Figure 5 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 4 ,like Figure 5 As shown, the process of calculating the performance weight of each server according to the load information and the weight numerator of each server in S212 may include:
[0112] S303: Calculate the load of each server according to the processor utilization and network utilization of each server.
[0113] S304: Calculate the performance weight of each server according to the load and weight numerator of each server.
[0114] The load information includes: processor utilization and network utilization.
[0115] In this embodiment, the processor utilization of the server is calculated based on the processing parameters of the server and the computing power occupied by the load task currently being executed by the server, and the network utilization of the server is calculated based on the network bandwidth configuration parameters of the server and the network bandwidth occupied by the load task currently being executed by the server. The load of the server can be determined based on the processor utilization and network utilization of the server. For example, the calculation formula of the load can be expressed as: (processor utilization + network utilization) / 2.
[0116] The weight denominator is generated according to the processor load. The performance weight of each server can be calculated according to the ratio of the weight numerator and the weight denominator of each server, where the server load is a value less than 1. In order to determine that the more load tasks the server is currently executing and the more complex the load tasks are, the smaller the performance weight of the server is, it is necessary to obtain a weight denominator greater than 1 based on the processor load and the preset value.
[0117] For example, the calculation formula of the performance weight of the server can be expressed as: performance weight=weight numerator / (1+load), where 1+load information is the weight denominator.
[0118] The load balancing method provided in the above embodiment calculates the server load based on the server's processor utilization and network utilization, and then calculates the server's performance weight based on the server's load and the weight numerator. By dynamically calculating the server's performance weight based on the server's processor utilization and network utilization, dynamic scheduling of the server can be achieved, thereby achieving load balancing.
[0119] In a possible implementation, the process of generating a random number for the target network load in S202 may include:
[0120] A quantum random number generator is used to generate quantum random numbers as random numbers for target network loads.
[0121] In this embodiment, the load balancer also includes a quantum random number generator. The quantum random number uses the uncertainty principle of quantum mechanics to generate real random numbers. Its randomness is determined by the unpredictability and uncertainty of the quantum system. The quantum random number generator is used to generate quantum random numbers as random numbers for the target network load. Its randomness is higher than that of the random numbers generated by the pseudo-random number generation method. It can ensure a high degree of randomness when calculating the expected weight based on the random number, so that the server scheduling is more uniform when determining the target server based on the expected weight. Moreover, since the performance of the quantum random number generator is higher than that of the traditional pseudo-random number generation method, it can greatly improve the efficiency of the load balancer in scheduling the server and improve the efficiency of the servers in the server cluster in processing the network load.
[0122] In a possible implementation, the process of determining the expected weight for the target network load according to the performance weights of the multiple servers and the random number in S203 may include:
[0123] An expected weight for a target network load is determined according to a total weight sum of the performance weights of a plurality of servers multiplied by a random number.
[0124] In this embodiment, the performance weights of multiple servers in the server cluster are summed to obtain the total weight of the server cluster, and the expected weight for the target network load is obtained based on the product of the total weight and the random number.
[0125] In some embodiments, the expected weight for the target network load is obtained according to the product of the total weight and the quantum random number.
[0126] In one possible implementation, Figure 6 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 5 ,like Figure 6 As shown, based on the above-mentioned obtaining the expected weight according to the product of the total weight and the random number, the above-mentioned process of determining the target server from multiple servers according to the performance weights and the expected weights of multiple servers in S204 may include:
[0127] S401: Traverse multiple servers in sequence according to performance weights.
[0128] S402: Calculate the cumulative weight of the current traversal server according to the performance weight of the current traversal server and the performance weights of the traversed servers.
[0129] S403: If the accumulated weight is greater than or equal to the expected weight, the current traversal server is determined to be the target server.
[0130] S404: If the accumulated weight is less than the expected weight, continue to traverse multiple servers until the target server is obtained.
[0131] In this embodiment, in order to achieve load balancing, a server with a large performance weight needs to be selected as the target server. Therefore, according to the sizes of the performance weights of the multiple servers, the multiple servers are sorted in reverse order, with the servers with large performance weights sorted first and the servers with small performance weights sorted last.
[0132] Traverse multiple servers sorted in reverse order in turn to determine whether the performance weight of the first server is greater than or equal to the expected weight. If the performance weight of the first server is greater than or equal to the expected weight, determine that the first server is the target server. If the performance weight of the first server is less than the expected weight, continue to traverse the second server. According to the performance weight of the second server and the performance weight of the first server that has been traversed, calculate the cumulative weight of the first server and the second server, and determine whether the cumulative weight of the first server and the second server is greater than or equal to the expected weight. If the cumulative weight of the first server and the second server is greater than or equal to the expected weight, determine that the second server is the target server. If the cumulative weight of the first server and the second server is less than the expected weight, continue to traverse the third server until a server with a cumulative weight greater than or equal to the expected weight is obtained as the target server.
[0133] The load balancing method provided in the above embodiment traverses the servers sorted in reverse order in turn, determines whether the performance weight of the currently traversed server and the cumulative weight of the performance weights of the traversed servers are greater than or equal to the expected weight, thereby determining the target server, and realizing load balancing of the servers based on the cumulative weight and the expected weight, so that the scheduling of each server in the server cluster is more uniform.
[0134] In one possible implementation, Figure 7 Schematic diagram of the load balancing method provided in the embodiment of the present application Figure 6 ,like Figure 7 As shown, the method may also include:
[0135] S501: Acquire configuration information and load information of a new access server.
[0136] S502: Determine a performance weight of the new access server according to the configuration information and load information of the new access server.
[0137] S503: Add the new access server to the server cluster, and store the performance weight of the new access server.
[0138] In this embodiment, when a new server needs to be connected to the server cluster, the new server actively reports configuration information and load information to the load balancer. The load balancer calculates the performance weight based on the configuration information and load information of the new server. The performance weight at this time is the initial performance weight when the new server is connected to the server cluster. The method for calculating the performance weight will not be repeated here.
[0139] After the load balancer calculates the performance weight of the new access server, it adds the new access server to the server cluster and reorders the servers according to the performance weight of the new access server and the performance weights of the existing servers in the server cluster.
[0140] Afterwards, the newly connected server will report load information regularly, and the load balancer will update the performance weight of the newly connected server based on the regularly reported load information and configuration.
[0141] It should be noted that each time each server in the server cluster reports load information, the load balancing calculation obtains an updated performance weight, and each server needs to be re-sorted according to the updated performance weight.
[0142] The load balancing method provided in the above embodiment calculates the performance weight of the new access server based on the configuration information and load information of the new access server, adds the new access server to the server cluster and stores the performance weight of the new access server, thereby realizing dynamic scaling of the server cluster. There is no need for users to manually add servers and configure the performance weights of the servers, so that the load balancer can more flexibly schedule servers in the server cluster.
[0143] For example, Figure 8 A load balancing diagram provided in the embodiment of the present application is shown in FIG. Figure 8 As shown, the number of processing cores of server 1 is single-core, the processing frequency is 1GHZ, and the network bandwidth configuration parameter is 500Mbps upstream bandwidth. The number of processing cores of server 2 is dual-core, the processing frequency is 2GHZ, and the network bandwidth configuration parameter is 500Mbps upstream bandwidth. The number of processing cores of server 3 is single-core, the processing frequency is 1GHZ, and the network bandwidth configuration parameter is 200Mbps upstream bandwidth. Taking server 1 as an example, the performance weight of server 1 = weight numerator / (1+load) = (processing parameter+network bandwidth configuration parameter) / (1+(processor utilization+network utilization) / 2) = [(number of processing cores*processing frequency)+network bandwidth configuration parameter] / (1+(processor utilization+network utilization) / 2) = [(1*1000)+500] / (1+(0.5+0.5) / 2) = 1000.
[0144] According to the performance weight, the servers in the server cluster are sorted to obtain the sorted servers. The performance weight of server 2 is greater than the performance weight of server 1, and the performance weight of server 1 is greater than the performance weight of server 3.
[0145] The expected weight is obtained by multiplying the performance weights of the three servers by a random number. The performance weight of server 2 is less than the expected weight. The cumulative weight of the performance weight of server 2 and the performance weight of server 1 is greater than the expected weight. Server 1 is determined to be the target server.
[0146] Based on the above method embodiment, the embodiment of the present application also provides a load balancing device, which is applied to a load balancer. Fig. 9 A schematic diagram of the structure of the load balancing device provided in the embodiment of the present application is shown in FIG. Fig. 9 As shown, the device may include:
[0147] The weight determination module 601 is used to determine the performance weights of the multiple servers according to the load information and configuration information of the multiple servers in the server cluster;
[0148] A random number generation module 602, for generating a random number for the target network load in response to a triggering event of the target network load;
[0149] The weight determination module 601 is further used to determine the expected weight for the target network load according to the performance weights of the multiple servers and the random number;
[0150] A server determination module 603, configured to determine a target server from a plurality of servers according to performance weights and expected weights of the plurality of servers;
[0151] The request sending module 604 is used to send a scheduling request for the target network load to the target server, so that the target server processes the target network load.
[0152] Optionally, the configuration information of each server includes: processing configuration parameters and network bandwidth configuration parameters of each server; the weight determination module 601 includes:
[0153] A weight numerator calculation unit, used to calculate the weight numerator of each server according to the processing configuration parameters and network bandwidth configuration parameters of each server;
[0154] The performance weight calculation unit is used to calculate the performance weight of each server according to the load information and weight numerator of each server.
[0155] Optionally, the processing configuration parameters include: the number of processing cores and the processing frequency; a weight numerator calculation unit, specifically used to calculate the processing parameters of each server based on the number of processing cores and the processing frequency of each server; and calculate the weight numerator of each server based on the processing parameters of each server and the network bandwidth configuration parameters.
[0156] Optionally, the load information includes: processor utilization and network utilization; a performance weight calculation unit, specifically used to calculate the load of each server based on the processor utilization and network utilization of each server; and calculate the performance weight of each server based on the load and weight numerator of each server.
[0157] Optionally, the random number generation module 602 is specifically configured to use a quantum random number generator to generate a quantum random number as a random number for the target network load.
[0158] Optionally, the weight determination module 601 is further configured to determine an expected weight for the target network load according to a product of a total weight sum of performance weights of multiple servers and a random number.
[0159] Optionally, the server determination module 603 is specifically used to traverse multiple servers in sequence according to the size of the performance weight; calculate the cumulative weight of the current traversal server according to the performance weight of the current traversal server and the performance weights of the traversed servers; if the cumulative weight is greater than or equal to the expected weight, determine that the current traversal server is the target server; if the cumulative weight is less than the expected weight, continue to traverse multiple servers until the target server is traversed.
[0160] Optionally, the device may further include:
[0161] The server access module is used to obtain the configuration information and load information of the new access server; determine the performance weight of the new access server according to the configuration information and load information of the new access server; add the new access server to the server cluster, and store the performance weight of the new access server.
[0162] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0163] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASICs), or one or more microprocessors, or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0164] Fig.10 A schematic diagram of a load balancer provided in an embodiment of the present application, such as Fig.10 As shown, the load balancer 100 may include: a processor 101, a storage medium 102 and a bus, the storage medium 102 stores program instructions executable by the processor 101, when the load balancer 100 is running, the processor 101 and the storage medium 102 communicate through the bus, and the processor 101 executes the program instructions to execute the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.
[0165] Optionally, the present application also provides a program product, such as a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the above method embodiments are executed.
[0166] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0167] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0168] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0169] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, abbreviated: ROM), random access memory (English: Random Access Memory, abbreviated: RAM), disk or optical disk and other media that can store program codes.
[0170] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A load balancing method, characterized in that: Applied to a load balancer, the method comprises: Determining performance weights of the multiple servers respectively according to load information and configuration information of the multiple servers in the server cluster; In response to a triggering event of a target network load, generating a random number for the target network load; Determining an expected weight for the target network load according to the performance weights of the multiple servers and the random number; Determining a target server from the multiple servers according to the performance weights of the multiple servers and the expected weights; A scheduling request for the target network load is issued to the target server, so that the target server processes the target network load.
2. The method according to claim 1, characterized in that The configuration information of each server includes: processing configuration parameters and network bandwidth configuration parameters of each server; and the performance weights of the multiple servers are determined according to the load information and configuration information of the multiple servers in the server cluster, including: Calculating a weight numerator of each server according to the processing configuration parameters and the network bandwidth configuration parameters of each server; The performance weight of each server is calculated according to the load information and the weight numerator of each server.
3. The method according to claim 2, characterized in that The processing configuration parameters include: the number of processing cores and the processing frequency; the weight numerator of each server is calculated according to the processing configuration parameters and the network bandwidth configuration parameters of each server, including: Calculate the processing parameters of each server according to the number of processing cores and the processing frequency of each server; The weight numerator of each server is calculated according to the processing parameters and network bandwidth configuration parameters of each server.
4. The method according to claim 2, characterized in that: The load information includes: processor utilization and network utilization; the performance weight of each server is calculated according to the load information and weight numerator of each server, including: Calculating the load of each server according to the processor utilization and network utilization of each server; The performance weight of each server is calculated according to the load of each server and the weight numerator.
5. The method according to claim 1, characterized in that The generating a random number for the target network load includes: A quantum random number generator is used to generate a quantum random number as a random number of the target network load.
6. The method according to claim 1, characterized in that The determining, according to the performance weights of the plurality of servers and the random number, an expected weight for the target network load comprises: An expected weight for the target network load is determined according to a product of a total weight sum of the performance weights of the plurality of servers and the random number.
7. The method according to claim 6, characterized in that The step of determining a target server from the multiple servers according to the performance weights of the multiple servers and the expected weights includes: According to the size of the performance weight, traversing the multiple servers in sequence; Calculate the accumulated weight of the currently traversed server according to the performance weight of the currently traversed server and the performance weights of the traversed servers; If the accumulated weight is greater than or equal to the expected weight, determining the current traversal server as the target server; If the accumulated weight is less than the expected weight, the multiple servers are continuously traversed until the target server is obtained.
8. The method according to claim 1, characterized in that The method further comprises: Obtain configuration information and load information of the new access server; Determining a performance weight of the new access server according to the configuration information and load information of the new access server; The new access server is added to the server cluster, and the performance weight of the new access server is stored.
9. A load balancing device, characterized in that: Applied to a load balancer, the device comprises: A weight determination module, used to determine the performance weights of the multiple servers in the server cluster according to the load information and configuration information of the multiple servers; A random number generation module, used to generate a random number for the target network load in response to a triggering event of the target network load; The weight determination module is further used to determine an expected weight for the target network load according to the performance weights of the multiple servers and the random number; A server determination module, configured to determine a target server from the plurality of servers according to the performance weights of the plurality of servers and the expected weights; The request sending module is used to send a scheduling request for the target network load to the target server, so that the target server processes the target network load.
10. A load balancer, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor, and when the load balancer is running, the processor communicates with the storage medium via the bus, and the processor executes the program instructions to perform the steps of the load balancing method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Server load balancing method and apparatus
CN108093009A
Load balancing system based on dynamic weight
CN112217894A
Load balancing method based on HTTP cluster server
CN113923202A
Task scheduling method and device, electronic equipment and storage medium
CN117215773A
Dynamic weight load balancing method for heterogeneous system
CN118502955A