Load balancing method and device, electronic equipment and storage medium
By dynamically allocating client requests to the appropriate server cluster, the problem that the existing L4 load balancing architecture cannot automatically allocate new server traffic, and the balancing allocation and performance improvement of server load is achieved.
Patent Information
- Application Number
- CN202411542011.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-14
AI Technical Summary
The existing L4 load balancing architecture cannot dynamically adjust the routing of client requests, resulting in the inability to automatically allocate traffic on the new server, and some servers have no requests for a long time, affecting the performance and resource utilization of the server.
By receiving the client's service request, analyzing the request information, selecting the appropriate server cluster based on the service information, and dynamically allocating the requests according to the preset load balancing rules, ensuring that the requests can be balanced according to the real-time status of the server.
It realizes balancing distribution of server load, improves server performance and resource utilization, avoids the situation where some servers have no requests for a long time, thereby improving response speed and stability.
Smart Images

Figure CN119449892A_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, electronic device and storage medium. Background Art
[0002] In the process of using deep learning models for content understanding, when faced with the load balancing problem of model deployment and service calls, the inference platform used relies on the gRPC service framework and is deployed on the internal platform using the L4 load balancing solution.
[0003] However, the existing L4 load balancing architecture scheduler selects a server based on the connection scheduling algorithm, and the message is sent to the selected server. Once the TCP connection is established, the client's request will be fixedly routed to the same server. Since L4 performs load balancing based on TCP connections, once the client connection is established, the message routing is also fixed and cannot be dynamically adjusted. As a result, when a new server is started, the client traffic cannot be automatically distributed to the new server. At the same time, when the number of clients is less than the number of servers, some servers on the server never receive client requests. As a result, the client cannot be evenly distributed according to the real-time status of the server, affecting the performance and resource utilization of the server.
[0004] Therefore, there is an urgent need to develop a load balancing method, device, electronic device and storage medium to solve one or more of the above-mentioned problems. Summary of the invention
[0005] In view of this, in order to solve the above technical problems or part of the technical problems, the embodiments of the present invention provide a load balancing method, device, electronic device and storage medium.
[0006] In a first aspect, the present application provides a load balancing method, the method comprising:
[0007] Receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client;
[0008] Parsing the service request to obtain service information;
[0009] Selecting a server cluster corresponding to the service request from the service end according to the service information;
[0010] According to a preset load balancing rule, the service request is distributed to a server cluster, so that the server cluster provides the target service to the client based on the load balancing rule.
[0011] In a possible implementation manner, the service information includes: service type information and service flow information;
[0012] The selecting, from the server end according to the service information, a server cluster corresponding to the service request comprises:
[0013] Selecting a first server that matches the service type information from the server, and generating a first server list;
[0014] Based on the service flow information, determine whether the first server in the first server list meets the load requirement, and obtain a determination result;
[0015] According to the judgment result, a server meeting the preset load condition is selected from the first server set as the second server;
[0016] A server cluster is established using the second server.
[0017] In a possible implementation manner, judging, based on the service traffic information, whether the first server in the first server list meets the load requirement includes:
[0018] Obtaining a load margin of each first server in the first service list and a server quantity of the first servers in the first service list;
[0019] determining a service load of the first server according to the service flow information and the number of servers of the first server;
[0020] Comparing the load margin of each first server in the first service list with the service load in turn to obtain a first comparison result;
[0021] According to the first comparison result, it is determined whether the first server in the first server list meets the load requirement.
[0022] In a possible implementation, the method further includes:
[0023] In the case where there is a faulty server in the service end, deactivating the faulty server, and determining whether there is the faulty server in the server cluster;
[0024] In the case that the faulty server exists in the server cluster, a server cluster corresponding to the service request is reselected from the non-faulty servers at the service end.
[0025] In a possible implementation, the method further includes:
[0026] When the server is expanded, determine whether the newly added server meets the service type information;
[0027] In a case where the service type information is met, updating the first server list based on the newly added server;
[0028] The step of establishing a server cluster is re-executed using the updated first server list.
[0029] In a possible implementation manner, after selecting, according to the judgment result, a server that meets a preset load condition from the first server set as the second server, the method further includes:
[0030] Obtaining the server quantity of the second server;
[0031] determining a service load of the second server according to the service flow information and the number of servers of the second server;
[0032] Comparing the load margin of each second server with the service load in turn to obtain a second comparison result;
[0033] When the second comparison results do not exceed, the step of using the second server to establish a server cluster is performed.
[0034] In a possible implementation, allocating the service request to a server cluster according to a preset load balancing rule includes:
[0035] Determine the number of servers in the server cluster;
[0036] According to a preset load balancing strategy, the service request is divided into a plurality of service sub-requests matching the number of the servers;
[0037] The plurality of service sub-requests are sequentially distributed to the plurality of servers in the server cluster.
[0038] In a first aspect, the present application provides a load balancing device, the device comprising:
[0039] A receiving module, used to receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client;
[0040] An acquisition module, used to acquire service information of the client according to the service request;
[0041] A selection module, configured to select a server cluster corresponding to the service request from the server according to the service information;
[0042] The allocation module is used to allocate the service request to the server cluster according to a preset load balancing rule, so that the server cluster provides the target service to the client based on the load balancing rule.
[0043] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the load balancing steps described in any one of the embodiments of the first aspect when executing the computer program.
[0044] In a fourth aspect, the present application further provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a processor, the load balancing steps described in any embodiment of the first aspect are implemented.
[0045] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the load balancing method provided by the embodiment of the present application, after receiving the service request initiated by the client, selects the server cluster corresponding to the service request from the server according to the service information, and then distributes the service request to the server cluster according to the pre-set load balancing rules, ensuring the load balancing of the server, thereby improving the performance and resource utilization of the server, and by dynamically adjusting the routing of the service request, the client request can be evenly distributed according to the real-time status of the server, avoiding the situation where some servers have no requests for a long time, thereby improving the response speed and stability of the server. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0048] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0049] Figure 1 A flow chart of a load balancing method provided in an embodiment of the present application;
[0050] Figure 2 A flow chart of another load balancing method provided in an embodiment of the present application;
[0051] Figure 3A schematic diagram of the steps of a load balancing method provided in an embodiment of the present application;
[0052] Figure 4 A schematic diagram of the structure of a load balancing device provided in an embodiment of the present application;
[0053] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0055] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0056] In order to solve the technical problems in the prior art that when a new server instance is started (including restart and new scenarios), the client traffic cannot be automatically allocated to the new server instance, and the client needs to be restarted to redistribute the traffic; or when the number of clients is less than the number of servers, some servers never receive client requests, the present application provides a load balancing method, device, electronic device and storage medium, which can select a server cluster corresponding to the service request from the server according to the service information after receiving the service request initiated by the client, and then allocate the service request to the server cluster according to the pre-set load balancing rules, to ensure the load balancing of the server, thereby improving the performance and resource utilization of the server. In addition, by dynamically adjusting the routing of the service request, the client request can be evenly distributed according to the real-time status of the server, avoiding the situation where some servers have no requests for a long time, thereby improving the response speed and stability of the server.
[0057] Figure 1 A flow chart of a load balancing method provided in an embodiment of the present application is shown as follows: Figure 1 As shown, the method specifically includes:
[0058] S101, receiving a service request initiated by a client, wherein the service request is used to request a server to provide a target service to the client;
[0059] In this embodiment, this party applies a load balancing component to connect the client to the server. For example, the gRPC client sends a service request to the client through the Consul Agent; the load balancing component receives the service request initiated by the client and evenly distributes the client's service request to the client to achieve load balancing.
[0060] S102, parsing the service request to obtain service information;
[0061] In this embodiment, after receiving the service request, the load balancing component will parse the content of the service request to obtain service information related to the client request, which may include but is not limited to the client's IP address, the requested service type, the requested resource identifier, etc. By parsing the service request, the load balancing component can more accurately understand the client's needs, laying the foundation for subsequent selection of an appropriate server cluster and processing of the request.
[0062] For example, in the process of parsing a service request, the client identifier of the service request is parsed to identify the identity and location of the client initiating the request. The client identifier includes but is not limited to the IP address, port number, etc. of the client;
[0063] For another example, in the process of parsing a service request, the service type of the service request is parsed so that the load balancing component determines to which type of server cluster the request should be forwarded. The service type includes but is not limited to database query, file transfer, API call, etc.;
[0064] For another example, in the process of parsing a service request, the resource identifier of the service request is parsed so that the load balancing component determines the specific target resource of the request. The resource identifier includes but is not limited to a database table name, a file path, an API interface name, and the like.
[0065] In addition, the service request may also contain a series of parameters to refine the specific requirements of the service request, such as query conditions, requested data volume, etc.; or the communication protocol version followed by the service request, which helps the load balancing component to ensure that the request is forwarded to the server instance that supports the protocol version; or authentication information, such as user name, password, token, etc., which is used to verify the identity and authority of the client, so that the load balancing component can obtain enough information to accurately understand the client's needs, and make appropriate load balancing decisions based on this, and forward the request to the most appropriate server instance for processing.
[0066] S103, selecting a server cluster corresponding to the service request from the server according to the service information;
[0067] In this embodiment, after obtaining the above service information, the load balancing component considers multiple dimensions, including but not limited to factors such as the server's processing power, storage capacity, network bandwidth, and geographical location; selects a server cluster corresponding to the service request from the server side to maximize service quality and response speed.
[0068] During this process, the load balancing component can use a variety of strategies to select the server cluster, including but not limited to polling, random, minimum number of connections, and most recent response time. Among them, the polling strategy is simple and fair, but may not fully utilize the processing power differences of the servers; the minimum number of connections strategy can ensure that the request is assigned to the server with the least current number of connections, thereby improving the overall processing efficiency. In order to ensure that the selected server cluster can meet the needs of the service request, the load balancing component also needs to perform a series of checks and verifications. For example, verify the health status of the server cluster to ensure that the selected servers are operating normally; verify the load situation of the server cluster to avoid assigning requests to overloaded servers; verify the resource matching of the server cluster to ensure that the selected server cluster has the resources and capabilities required to process the request.
[0069] S104: Distribute the service request to a server cluster according to a preset load balancing rule, so that the server cluster provides the target service to the client based on the load balancing rule.
[0070] In this embodiment, the load balancing component dynamically distributes service requests to servers in the server cluster according to pre-set load balancing rules to achieve load balancing. In this process, by real-time monitoring of the cluster load, overloaded or idle server resources can be discovered and processed in a timely manner to ensure the stability of service quality and user experience.
[0071] Specifically, the latest service node information in the server cluster is obtained, and service requests are assigned to appropriate server instances based on the service node information. During this process, monitoring tools are used to monitor each node in the server cluster in real time. The monitoring data includes but is not limited to key performance indicators such as CPU usage, memory usage, disk I / O speed, network bandwidth, etc. Then, based on the results of data analysis, the service node information in the server cluster is updated, where the node information includes key information such as the current load status, remaining processing capacity, and health status of each node.
[0072] During this process, it is also necessary to ensure that service requests can be evenly distributed to each server instance to prevent a node from becoming a bottleneck due to excessive load; and on the basis of load balancing, service requests are preferentially allocated to server instances with stronger processing capabilities and better health, which helps to improve the overall service response speed and user experience; and when a server instance fails or has performance abnormalities, the service requests originally assigned to the instance are promptly transferred to other normal instances, ensuring high availability and continuity of the service.
[0073] The load balancing method provided in this embodiment first captures the service requests initiated by the client, and then accurately matches and configures the corresponding server cluster through in-depth analysis of these requests; on this basis, according to the pre-established load balancing strategy, not only the basic goal of load balancing is achieved, but also the performance and resource utilization efficiency of the server are further improved. In addition, by dynamically adjusting the routing path of the service request in real time, it ensures that the client's request can be evenly and efficiently distributed according to the real-time status of the server, thereby effectively avoiding the problem of some servers being idle and request-free for a long time, greatly enhancing the response agility and system stability of the server.
[0074] In an optional solution of the embodiment of the present invention, the service information includes: service type information and service flow information;
[0075] In this embodiment, the service information mainly includes service type information and service flow information; wherein, the service type information is used to identify the specific service category requested by the client; each service type has different requirements for server resources, processing speed and stability. By identifying the service type information, the load balancing component can more accurately evaluate the service request's requirements for server resources, thereby selecting the server cluster that is most suitable for processing this type of request.
[0076] For example, for video streaming services, you may need to select a server cluster with a large network bandwidth and sufficient storage capacity to ensure smooth and stable video transmission.
[0077] The service traffic information reflects the traffic status of the current service request, including the frequency of the request, the amount of data, etc. By monitoring and analyzing the service traffic information, the load balancing component can grasp the load pressure of the service request in real time, and then dynamically adjust the load balancing strategy to ensure that the service can still maintain high availability and stability in high concurrency scenarios.
[0078] For example, when a surge in service traffic is detected, the load balancing component can quickly start more server instances or redirect some requests to other relatively idle server clusters to alleviate the load pressure on the current cluster.
[0079] It should be noted that this embodiment uses service type information and service flow information as examples to discuss the determination process of the server cluster based on type and flow; service information includes not only service type information and service flow information, but may also include service priority information, client geographic location information, and historical access records, etc. This information together constitutes a comprehensive description of the service request, allowing the load balancing component to make more accurate and efficient decisions.
[0080] Figure 2 A flow chart of another load balancing method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, the method specifically includes:
[0081] S201, selecting a first server that meets the service type information from the server, and generating a first server list;
[0082] In this embodiment, the types of the service-side servers are first analyzed, and then the first servers matching the service type information are selected from the server, the screened first servers are organized into a first server list, and the first server list is used for subsequent service deployment.
[0083] It should be noted that in the screening process of the first server, in addition to requiring the server type of the first server to comply with the service type information to meet the service requirements, factors such as the performance, stability, availability and geographical location of the first server also need to be considered to ensure that the first server can provide the target service efficiently and stably.
[0084] For example, if the service type information indicates a service with extremely high real-time requirements, then when selecting the first server, special attention should be paid to the server's network latency and data processing speed; if the service request comes from a specific area, in order to optimize the access speed, priority can be given to servers with close geographical locations.
[0085] S202: Based on the service flow information, determine whether the first server in the first server list meets the load requirement, and obtain a determination result;
[0086] In this embodiment, after the first server list is generated, the service traffic information is further analyzed to obtain the load pressure and traffic distribution of the current service request, and the combined load pressure and traffic distribution are important bases for load balancing decisions.
[0087] Specifically, the current load status of each first server is evaluated based on the service traffic information, and its load change trend in the future is predicted to ensure that service requests are intelligently allocated to servers with lower loads, thereby avoiding overload.
[0088] In addition, the server's historical performance will also be taken into consideration. By analyzing the server's historical access records, failure records, and performance data, the server's stability and reliability will be evaluated. When selecting a server, giving priority to servers with good historical performance can further improve service stability and user experience.
[0089] S203: According to the judgment result, select a server that meets the preset load condition from the first server set as the second server;
[0090] S204: Establish a server cluster using the second server.
[0091] In this embodiment, before building a server cluster, the load requirement is clarified, that is, a preset load condition is formulated, and the second server can be selected from the first server cluster according to business characteristics and historical data;
[0092] Specifically, different business scenarios have different requirements for server performance. For example, online games require low latency and high concurrency processing capabilities, while big data analysis focuses more on storage capacity and computing speed. By analyzing the load conditions over a period of time, we can predict future load trends and provide a basis for setting preset load conditions.
[0093] After the preset load conditions are determined, select qualified servers from the existing first server set as the second server to ensure the performance and stability of the subsequent server cluster. The server cluster can be established from the dimensions of CPU performance, memory size, network bandwidth, and storage capacity.
[0094] Specifically, select a CPU with sufficient computing power to ensure good response speed under high load, allocate sufficient memory resources according to business needs, avoid performance degradation caused by frequent memory swapping, ensure that the network connection between servers has sufficient bandwidth and stability to meet data transmission needs, and select the appropriate hard disk type and capacity based on the storage requirements of business data.
[0095] After selecting the second server that meets the preset load conditions, a server cluster can be established through network planning, load balancing configuration, high availability design, and monitoring and management.
[0096] Specifically, design a reasonable network topology to ensure efficient and reliable communication between servers, deploy a load balancer to evenly distribute external requests to each server to improve the overall processing capability, and ensure that services can continue to be provided when some servers fail through redundant deployment, failover and other mechanisms. Deploy a monitoring system to monitor the operating status of the cluster in real time and promptly discover and resolve problems.
[0097] The server cluster establishment method provided in this embodiment selects a server that meets the preset load conditions from the first server cluster as the second server. It not only considers the basic information of the service type and service traffic, but also comprehensively considers multiple factors such as the server's performance, stability, availability and geographical location. Through comprehensive evaluation and analysis, it can accurately select the server cluster that is most suitable for processing the current service request and achieve efficient load balancing, which not only improves the overall performance and response speed of the service, but also enhances the stability and reliability of the system.
[0098] In a possible implementation manner, judging, based on the service traffic information, whether the first server in the first server list meets the load requirement includes:
[0099] Obtaining a load margin of each first server in the first service list and a server quantity of the first servers in the first service list;
[0100] determining a service load of the first server according to the service flow information and the number of servers of the first server;
[0101] Comparing the load margin of each first server in the first service list with the service load in turn to obtain a first comparison result;
[0102] According to the first comparison result, it is determined whether the first server in the first server list meets the load requirement.
[0103] In this embodiment, the server needs to collect the load margin information of each first server in the first service list to determine the server's ability to handle additional workload under the current load, wherein the load margin information includes but is not limited to key indicators such as CPU usage, memory occupancy, and disk I / O rate; in addition, in order to more accurately reflect the server status, historical data trends are also considered to make more reasonable predictions of future loads; then, after determining the server load margin and service flow information, the number of servers of the first server is determined by calculation, and then the service load of each server in the first service list is determined, and the load margin of each first server is further compared with the service load to obtain a first comparison result, which is the key to determining whether the server meets the load requirement;
[0104] Specifically, if the load margin of a server is greater than or equal to its service load, it means that the server has sufficient processing capacity to meet current and future demand; otherwise, it may be necessary to increase resources or perform load balancing adjustments.
[0105] In one possible implementation, the method further includes:
[0106] In the case where there is a faulty server in the service end, deactivating the faulty server, and determining whether there is the faulty server in the server cluster;
[0107] In the case that the faulty server exists in the server cluster, a server cluster corresponding to the service request is reselected from the non-faulty servers at the service end.
[0108] In this embodiment, when monitoring or client feedback indicates that there is a faulty server on the service side, a deactivation operation is immediately performed to ensure that the faulty server does not continue to have a negative impact on the system, such as data corruption, service interruption, etc., and troubleshooting and repair work is started.
[0109] like Figure 3 As shown in the figure, taking Consul Agent as an example, when the server instance starts, it registers itself with Consul Agent; after the server instance starts, it calls the Consul API to register the service, including the service name, IP address and port information. Consul Agent periodically sends health check requests to the registered server instance to ensure the availability of the service instance. If the service instance is unavailable, Consul Agent will remove it from the service list.
[0110] Specifically, through cluster management tools or custom scripts, the system can traverse the status information of all servers in the cluster, including operating status, load conditions, health check results, etc., to determine whether the server cluster contains disabled faulty servers.
[0111] After determining that the server cluster contains a disabled faulty server, the system will reselect a server cluster that matches the current service request from the non-faulty servers on the server side through resource assessment, load balancing strategy, business continuity planning, etc., based on factors such as the type, priority, and resource requirements of the service request, and taking into account factors such as the remaining capacity, performance, and geographical location of the non-faulty servers.
[0112] For example, for online transaction services with high concurrency and low latency requirements, the system may give priority to server clusters that are geographically close to users and have lower current loads; while for batch processing tasks with large data processing volumes and low real-time requirements, the system may pay more attention to the server's computing power and storage resources.
[0113] In addition, in order to further improve the flexibility of the service, a dynamic expansion and reduction mechanism can be introduced. When the system detects that the load of a server cluster is continuously high, the expansion process can be automatically triggered, and new servers can be scheduled from the backup resource pool to join the cluster; on the contrary, when the cluster load drops to a certain level, the reduction operation can be automatically performed to save resource costs. This not only helps to cope with sudden traffic peaks, but also achieves optimal resource allocation while ensuring service quality.
[0114] The load balancing method provided in the embodiment of the present application can ensure that the system can maintain an efficient and stable operating state when facing a faulty server problem on the server side by performing a series of refined operations such as deactivating the faulty server, judging the cluster status, and reselecting the server cluster. At the same time, combined with advanced technical means such as automated monitoring, troubleshooting, and resource scheduling, it can achieve optimal resource allocation while ensuring service quality.
[0115] In a possible implementation, the method further includes:
[0116] When the server is expanded, determine whether the newly added server meets the service type information;
[0117] In a case where the service type information is met, updating the first server list based on the newly added server;
[0118] The step of establishing a server cluster is re-executed using the updated first server list.
[0119] In this embodiment, when there is capacity expansion on the server side, the purpose and demand of the capacity expansion are clarified to cope with the growing user access volume, improve data processing capabilities, or optimize the response speed of specific services; then the configuration, performance parameters and compatibility of the newly added server are comprehensively evaluated to determine whether it meets the information requirements of the current service type, and then after confirming that the newly added server meets the service type information, the next step is to add it to the first server list for updating to ensure that the newly added server can work with other servers to jointly undertake service tasks, and finally re-establish the server cluster through the updated first server list.
[0120] like Figure 3 As shown in the figure, taking Consul Agent as an example, the gRPC client sends a service discovery request through Consul Agent to obtain the information of all healthy service instance nodes of a specific service name; the client sends requests to Consul Agent regularly to ensure real-time updates of the service list.
[0121] Maintain service list: The gRPC client sends requests to Consul regularly to update the service list and maintain the validity of the service list. The service list contains information about all healthy service instances, including IP addresses and ports.
[0122] Create a transmission channel: The client load balancer creates a transmission channel based on the service list; the channel is used for communication between the client and the server.
[0123] In a possible implementation manner, after selecting, according to the judgment result, a server that meets a preset load condition from the first server set as the second server, the method further includes:
[0124] Obtaining the server quantity of the second server;
[0125] determining a service load of the second server according to the service flow information and the number of servers of the second server;
[0126] In this embodiment, the total load of the server is determined according to the traffic information, and then based on the principle of load balancing, the service load of each second server is determined according to the number of second servers.
[0127] Comparing the load margin of each second server with the service load in turn to obtain a second comparison result;
[0128] When the second comparison results do not exceed, the step of using the second server to establish a server cluster is performed.
[0129] Specifically, service traffic information usually comes from monitoring systems and log analysis. Based on service traffic information and the processing capacity of the second server (which can be obtained through benchmark tests or historical data predictions), the load of each second server under current or expected traffic can be calculated. For example, if the number of visits to a service surges during a certain period of time, the IT team needs to quickly evaluate the impact of this change on the load of the second server so that timely adjustments can be made.
[0130] Subsequently, by comparing the load margin and actual service load of each server, it is possible to clearly identify which servers are in a high-load state and which servers have remaining processing capacity, which helps avoid service interruptions caused by overload and provides data support for subsequent load balancing strategies.
[0131] Finally, when the load margin of all second servers can meet the current or expected service load, a server cluster is built by comprehensively considering various factors, such as the cluster's architectural design (such as master-slave replication, distributed storage, etc.), fault-tolerant mechanisms (such as automatic failover, data backup, etc.) and performance optimization (such as the selection of load balancing algorithms, the implementation of caching strategies, etc.).
[0132] In a possible implementation, allocating the service request to a server cluster according to a preset load balancing rule includes:
[0133] Determine the number of servers in the server cluster;
[0134] In this embodiment, the number of servers is determined by considering resource utilization and cost effectiveness.
[0135] Specifically, too many servers will lead to waste of resources and increased costs, while too few servers may not be able to meet business needs, causing system crashes or performance degradation. Therefore, it is necessary to maximize resource utilization and reduce operation and maintenance costs while meeting business needs.
[0136] According to a preset load balancing strategy, the service request is divided into a plurality of service sub-requests matching the number of the servers;
[0137] The plurality of service sub-requests are sequentially distributed to the plurality of servers in the server cluster.
[0138] like Figure 3 As shown, taking Consul Agent as an example, selecting a server and sending a request: the client load balancer selects a server based on a specific load balancing algorithm; the client sends an RPC request to the selected server.
[0139] In this embodiment, a service request is divided into a plurality of service sub-requests matching the number of servers according to a preset load balancing strategy, and these sub-requests are sequentially distributed to a plurality of servers in the cluster.
[0140] It should be noted that when configuring a load balancer, you need to set corresponding policy parameters and rules to ensure that service requests can be correctly distributed to each server in the server cluster according to the predetermined policy. In addition, the load balancer needs to be monitored and maintained to ensure its stable operation and efficient work.
[0141] The load balancing method of the embodiment of the present application can scientifically and reasonably determine the number of servers by comprehensively considering factors such as business needs, resource utilization, cost-effectiveness, redundancy and fault tolerance; by selecting a suitable load balancing strategy and reasonably configuring the load balancer, balanced distribution of service requests and stable operation of the system can be achieved.
[0142] like Figure 3 As shown, the specific implementation steps of the load balancing method include:
[0143] Step 1: Consul cluster preparation: Maintain a consul cluster, connect it to the company's consul cluster (join), and obtain the grpc server registration information.
[0144] Step 2: When the server instance starts, register the instance with Consul Agent.
[0145] Step 3: Service health check: Consul Agent performs health checks regularly to ensure the availability of the server instance.
[0146] Step 4: Client service discovery: The gRPC client obtains service node information from Consul Agent.
[0147] Step 5: Service list update: The gRPC client periodically sends requests to Consul to obtain the latest service list to ensure the validity of the service list.
[0148] Step 6: The client load balancer creates a transmission channel for the service list and selects a server based on the load balancing algorithm.
[0149] Step 7: Send RPC request: The client sends an RPC request to the selected server.
[0150] Figure 4 A schematic diagram of a load balancing device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the device specifically includes:
[0151] Receiving module 401, used to receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client;
[0152] The acquisition module 402 is used to acquire the service information of the client according to the service request;
[0153] A selection module 403 is used to select a server cluster corresponding to the service request from the server according to the service information;
[0154] The allocation module 404 is used to allocate the service request to the server cluster according to a preset load balancing rule, so that the server cluster provides the target service to the client based on the load balancing rule.
[0155] In one possible implementation, the selection module 403 is also used to select a first server that meets the service type information from the service end to generate a first server list; based on the service traffic information, determine whether the first server in the first server list meets the load requirements to obtain a judgment result; based on the judgment result, select a server that meets the preset load conditions from the first server set as the second server; and use the second server to establish a server cluster.
[0156] In one possible implementation, the selection module 403 is also used to obtain the load margin of each first server in the first service list and the number of servers in the first service list; determine the service load of the first server based on the service traffic information and the number of servers in the first server; compare the load margin of each first server in the first service list with the service load in turn to obtain a first comparison result; and determine whether the first server in the first server list meets the load requirements based on the first comparison result.
[0157] In one possible implementation, the method further includes a fault handling module 405 (not shown in the figure), which is used to, when a faulty server exists in the server end, deactivate the faulty server and determine whether the faulty server exists in the server cluster; when the faulty server exists in the server cluster, reselect a server cluster corresponding to the service request from the non-faulty servers on the server end.
[0158] In one possible implementation, the method further includes an expansion processing module 406 (not shown in the figure), which is used to determine whether a newly added server complies with the service type information when there is capacity expansion on the server side; if it complies with the service type information, update the first server list based on the newly added server; and re-execute the step of establishing a server cluster using the updated first server list.
[0159] In one possible implementation, the selection module 403 is also used to obtain the number of servers of the second server; determine the service load of the second server based on the service traffic information and the number of servers of the second server; compare the load margin of each second server with the service load in turn to obtain a second comparison result; and when the second comparison results are not exceeded, execute the step of establishing a server cluster using the second server.
[0160] In one possible implementation, the allocation module 404 is also used to determine the number of servers in the server cluster; divide the service request into multiple service sub-requests matching the number of servers according to a pre-set load balancing strategy; and sequentially allocate the multiple service sub-requests to the multiple servers in the server cluster.
[0161] The load balancing device provided in this embodiment may be as follows Figure 4 The load balancing device shown in FIG. 1 may execute the following Figure 1-3 All the steps of load balancing in Figure 1-3 The technical effect of load balancing is shown in the figure. For details, please refer to Figure 1-3 For the sake of brevity, the relevant description is not repeated here.
[0162] The device embodiments described above are merely illustrative, wherein 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 modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, an embodiment of the present application provides an electronic device, including a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504; the memory 503 is used to store computer programs; the processor 501 is used to execute the program stored in the memory 503, and implement the steps of the load balancing method provided by any of the above method embodiments:
[0164] Receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client; parse the service request to obtain service information; based on the service information, select a server cluster corresponding to the service request from the server; and according to a pre-set load balancing rule, distribute the service request to the server cluster so that the server cluster provides the target service to the client based on the load balancing rule.
[0165] In one possible implementation, a first server that meets the service type information is selected from the service end to generate a first server list; based on the service traffic information, it is determined whether the first server in the first server list meets the load requirements to obtain a determination result; based on the determination result, a server that meets the preset load conditions is selected from the first server set as a second server; and a server cluster is established using the second server.
[0166] In one possible implementation, the load margin of each first server in the first service list and the number of servers in the first service list are obtained; the service load of the first server is determined based on the service traffic information and the number of servers of the first server; the load margin of each first server in the first service list is compared with the service load in turn to obtain a first comparison result; and based on the first comparison result, it is determined whether the first server in the first server list meets the load requirement.
[0167] In one possible implementation, when there is a faulty server in the service end, the faulty server is disabled, and it is determined whether the faulty server exists in the server cluster; when there is a faulty server in the server cluster, a server cluster corresponding to the service request is reselected from the non-faulty servers on the service end.
[0168] In one possible implementation, when the service end is expanded, it is determined whether the newly added server complies with the service type information; if it complies with the service type information, the first server list is updated based on the newly added server; and the step of establishing the server cluster is re-executed using the updated first server list.
[0169] In one possible implementation, the number of servers of the second server is obtained; the service load of the second server is determined based on the service traffic information and the number of servers of the second server; the load margin of each second server is compared with the service load in turn to obtain a second comparison result; when the second comparison results are not exceeded, the step of establishing a server cluster using the second server is executed.
[0170] In one possible implementation, the number of servers in a server cluster is determined; based on a preset load balancing strategy, a service request is divided into a plurality of service sub-requests matching the number of servers; and the plurality of service sub-requests are sequentially distributed to a plurality of servers in the server cluster.
[0171] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0172] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0173] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A load balancing method, characterized in that: include: Receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client; Parsing the service request to obtain service information; Selecting a server cluster corresponding to the service request from the service end according to the service information; According to a preset load balancing rule, the service request is distributed to a server cluster, so that the server cluster provides the target service to the client based on the load balancing rule.
2. The method according to claim 1, characterized in that The service information includes: service type information and service flow information; The selecting, from the server end according to the service information, a server cluster corresponding to the service request comprises: Selecting a first server that matches the service type information from the server, and generating a first server list; Based on the service flow information, determine whether the first server in the first server list meets the load requirement, and obtain a determination result; According to the judgment result, a server meeting the preset load condition is selected from the first server set as the second server; A server cluster is established using the second server.
3. The method according to claim 2, characterized in that The determining, based on the service flow information, whether the first server in the first server list meets the load requirement includes: Obtaining a load margin of each first server in the first service list and a server quantity of the first servers in the first service list; determining a service load of the first server according to the service flow information and the number of servers of the first server; Comparing the load margin of each first server in the first service list with the service load in turn to obtain a first comparison result; According to the first comparison result, it is determined whether the first server in the first server list meets the load requirement.
4. The method according to claim 1, characterized in that: The method further comprises: In the case where there is a faulty server in the service end, deactivating the faulty server, and determining whether there is the faulty server in the server cluster; In the case that the faulty server exists in the server cluster, a server cluster corresponding to the service request is reselected from the non-faulty servers at the service end.
5. The method according to claim 2, characterized in that: The method further comprises: When the server is expanded, determine whether the newly added server meets the service type information; If the service type information is met, updating the first server list based on the newly added server; The step of establishing a server cluster is re-executed using the updated first server list.
6. The method according to claim 2, characterized in that After selecting a server that meets a preset load condition from the first server set as the second server according to the judgment result, the method further includes: Obtaining the server quantity of the second server; determining a service load of the second server according to the service flow information and the number of servers of the second server; Comparing the load margin of each second server with the service load in turn to obtain a second comparison result; When the second comparison results are both within the range, the step of using the second server to establish a server cluster is performed.
7. The method according to claim 1, characterized in that The allocating the service request to the server cluster according to a preset load balancing rule includes: Determine the number of servers in the server cluster; According to a preset load balancing strategy, the service request is divided into a plurality of service sub-requests matching the number of the servers; The plurality of service sub-requests are sequentially distributed to the plurality of servers in the server cluster.
8. A load balancing device, characterized in that: include: A receiving module, used to receive a service request initiated by a client, wherein the service request is used to request the server to provide a target service to the client; An acquisition module, used to acquire service information of the client according to the service request; A selection module, configured to select a server cluster corresponding to the service request from the server according to the service information; The allocation module is used to allocate the service request to the server cluster according to a preset load balancing rule, so that the server cluster provides the target service to the client based on the load balancing rule.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the load balancing method according to any one of claims 1 to 7 are implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the load balancing method according to any one of claims 1 to 7 are implemented.