Load balancing method and related device
By dynamically adjusting the number of virtual nodes and hash ring data of the game server, the problem of untimely response caused by traditional load balancing methods is solved, and game performance and user experience are improved.
Patent Information
- Application Number
- CN202510550750.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-05
AI Technical Summary
Traditional load balancing methods lead to untimely responses in game server clusters, affecting game performance and user experience.
By obtaining hash ring data, the number of virtual nodes is dynamically adjusted based on the current load value of the server and the weight coefficient of the business scenario, the hash ring data is updated, and the service request allocation is performed based on the updated data.
It achieves more timely operation response, improves server resource utilization, reduces game delays, and optimizes game performance and user experience.
Smart Images

Figure CN120434249A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a load balancing method and related devices. Background Art
[0002] In game server clusters, load balancing is a core technology that ensures high system availability and a positive player experience. Due to the complexity of gaming operations (such as real-time combat, social interaction, and log processing), traditional load balancing methods can lead to delayed game responses, impacting game performance and user experience. Summary of the Invention
[0003] In view of the above problems, this application provides a load balancing method and related devices to achieve the purpose of making operation responses more timely. The specific solution is as follows:
[0004] A first aspect of the present application provides a load balancing method, comprising:
[0005] Obtaining hash ring data; wherein the hash ring data reflects a mapping relationship between the server and the virtual nodes located on the hash ring;
[0006] Adjusting the number of virtual nodes of the server based on a current load value of the server and a weight coefficient corresponding to a business scenario to which a current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data;
[0007] Based on the adjusted number of virtual nodes, update the hash ring data;
[0008] Based on the updated hash ring data, a server is allocated to the new service request, and the new service request is sent to the allocated server for processing.
[0009] In a possible implementation, adjusting the number of virtual nodes of the server based on a current load value of the server and a weight coefficient corresponding to a business scenario to which a current business request processed by the server belongs includes:
[0010] When the current load value is less than the average load value and the weight coefficient is not reduced, increasing the number of virtual nodes; wherein the average load value is the average of the current load values of multiple servers;
[0011] When the current load value is greater than the average load value and the weight coefficient does not increase, the number of virtual nodes is reduced.
[0012] In a possible implementation, the method further includes:
[0013] Obtaining multiple performance indicators of the server;
[0014] Determining a weight coefficient for each of the performance indicators based on a business scenario to which the current business request processed by the server belongs;
[0015] The product of the performance index and the corresponding weight coefficient is accumulated to obtain the current load value of the server.
[0016] In a possible implementation, the method further includes:
[0017] Inputting the current service request into a convolutional neural network model of a scene classification model for feature extraction to obtain a first output result;
[0018] Inputting the first output result into the long short-term memory network of the scene classification model for feature extraction to obtain a second processing result;
[0019] The second processing result is input into the fully connected layer of the scene classification model for classification to obtain the business scene to which the current business request belongs.
[0020] In a possible implementation, allocating a server for a new service request based on the updated hash ring data includes:
[0021] Determine the business scenario to which the new business request belongs, and obtain a target business scenario;
[0022] Calculate a hash value based on the new service request;
[0023] Based on the updated hash ring data, searching for the virtual node pointed to by the hash value to obtain the target virtual node;
[0024] In a case where the server corresponding to the target virtual node processes a business request corresponding to the target business scenario, allocating the new business request to the server corresponding to the target virtual node;
[0025] In the case that the server corresponding to the target virtual node does not process the business request corresponding to the target business scenario, the next virtual node of the target virtual node is determined based on the updated hash ring data, and starting from the server corresponding to the next virtual node, the server that processes the business request corresponding to the target business scenario is searched, and the new business request is assigned to the found server.
[0026] In a possible implementation, allocating a server for a new service request based on the updated hash ring data further includes:
[0027] Based on the updated hash ring data, updating the locally stored hash ring data;
[0028] Obtaining the new service request;
[0029] Determine the business scenario to which the new business request belongs, and obtain a target business scenario;
[0030] Determining whether the locally stored hash ring data contains node information of a server that processes a service request corresponding to the target service scenario;
[0031] If the locally stored hash ring data has the node information of the server, allocating the server for the new service request based on the locally stored hash ring data;
[0032] If the locally stored hash ring data does not have the node information of the server, the hash ring data with the node information of the server is obtained from the target database, and the server is allocated to the new service request based on the hash ring data with the node information of the server.
[0033] In a possible implementation, after updating the hash ring data based on the adjusted number of virtual nodes, the method further includes:
[0034] Sending the updated hash ring data to the target database, so that the target database updates the stored data based on the updated hash ring data and updates the version number of the stored data; wherein the stored data is the hash ring data stored in the target database;
[0035] Comparing the version number of the locally stored hash ring data with the version number of the stored data to see if they are the same;
[0036] If they are not the same, the stored data is obtained from the target database, and the locally stored hash ring data is updated based on the stored data.
[0037] A second aspect of the present application provides a load balancing system, comprising:
[0038] A data acquisition module, configured to acquire hash ring data, wherein the hash ring data reflects a mapping relationship between the server and the virtual nodes located on the hash ring;
[0039] A virtual node quantity adjustment module, configured to adjust the number of virtual nodes of the server based on a current load value of the server and a weight coefficient corresponding to a business scenario to which a current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data;
[0040] A data updating module, configured to update the hash ring data based on the adjusted number of virtual nodes;
[0041] The request allocation module is used to allocate servers to new service requests based on the updated hash ring data, and send the new service requests to the allocated servers for processing.
[0042] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the load balancing method of the first aspect or any implementation of the first aspect.
[0043] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0044] The memory is used to store computer programs;
[0045] The processor is used to execute the computer program so that the electronic device can implement the load balancing method of the above-mentioned first aspect or any implementation manner of the first aspect.
[0046] In a fifth aspect, the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the load balancing method of the above-mentioned first aspect or any implementation of the first aspect.
[0047] With the help of the above technical solution, the load balancing method and related devices provided by the present application adjust the number of virtual nodes of the server through the current load value of the server and the weight coefficient corresponding to the business scenario to which the current business request processed by the server belongs. The load balancing method can be dynamically adjusted according to the real-time load and business needs of the server. When the number of virtual nodes corresponding to the server increases, the probability of business requests being assigned to the server increases. When the number of virtual nodes corresponding to the server decreases, the probability of business requests being assigned to the server is smaller, thereby achieving load balancing while making the operation response more timely. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.
[0049] Figure 1 A flow chart of a load balancing method provided in this application;
[0050] Figure 2 A load balancing system structure diagram provided for this application;
[0051] Figure 3 This is a schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0052] The following describes the embodiments of the present application in conjunction with the accompanying drawings. The terms used in the implementation methods of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application.
[0053] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0054] 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 terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0055] Reference Figure 1 , Figure 1 A load balancing method is provided in the embodiment of the present application. Figure 1 As shown, a load balancing method provided in an embodiment of the present application may include steps 101 to 104, and these steps are described in detail below.
[0056] Step 101: Obtain hash ring data; wherein the hash ring data reflects the mapping relationship between the server and the virtual nodes located on the hash ring.
[0057] The hash ring data may include the server's node information, virtual node information, and the mapping relationship between the server and virtual nodes on the hash ring. The server's node information may include the number of servers, and the virtual node information may include the number of virtual nodes and the hash value of each virtual node. The mapping relationship is the corresponding relationship between the server and the virtual node. A server can correspond to multiple virtual nodes. The hash ring data can reflect the position of the virtual node in the hash ring, the number of virtual nodes, and the server corresponding to each virtual node.
[0058] The obtained hash ring data can be partial hash ring data or global hash ring data, wherein the partial hash ring data can be obtained by calculating the hash values of some nodes, and the global hash ring data can be obtained by calculating the hash values of all nodes. The partial nodes are some server nodes and the virtual nodes corresponding to some server nodes, and the all nodes are all server nodes and all virtual nodes. For example, if there are 5 servers and each server corresponds to 20 virtual nodes, then the global hash ring data includes the node information of these five servers, the information of 100 virtual nodes, and the corresponding relationship between each virtual node and the server, while the partial hash ring data can only include the node information of one to four servers, the information of 20 to 80 virtual nodes, and the corresponding relationship between the virtual nodes and the server, such as the node information of three servers, the information of 60 virtual nodes, and the corresponding relationship between 60 virtual nodes and 3 servers.
[0059] Optionally, hash ring data can be obtained locally or from a target database. The local database can be a gateway node or server. The target database can be etcd, a highly available distributed key-value database. etcd uses a distributed architecture and can be used for service discovery and shared configuration. Multiple nodes achieve data consistency and synchronization through the Raft algorithm. etcd has high availability. Even if some nodes fail, the entire etcd cluster can still operate normally, ensuring reliable storage and access to hash ring data.
[0060] Step 102: Adjust the number of virtual nodes of the server based on the current load value of the server and the weight coefficient corresponding to the business scenario to which the current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data.
[0061] The number of virtual nodes on a server is dynamically adjusted based on the server's real-time load and business scenarios. When the server's current load is high, the number of virtual nodes can be reduced; when the server's current load is low, the number of virtual nodes can be increased. Furthermore, the server's load is also considered, along with the business scenario to which the current business request being processed by the server belongs. If the weight coefficient corresponding to the business scenario is high, the number of virtual nodes on the server can be increased; if the weight coefficient corresponding to the business scenario is low, the number of virtual nodes on the server can be reduced. As the number of virtual nodes associated with a server increases, the probability of business requests being assigned to that server increases. As the number of virtual nodes associated with a server decreases, the probability of business requests being assigned to that server decreases. This allows for more timely operational responses to meet the needs of different business scenarios while achieving load balancing. For example, if the business scenario is a real-time combat scenario, the corresponding weight coefficient can be high. In this case, the number of virtual nodes on the server is adjusted to a higher value. By increasing the number of virtual nodes used to process business requests in this real-time combat scenario, these requests can be responded to more promptly. Furthermore, for a server, increasing the number of virtual nodes can increase the volume of business requests handled in this real-time combat scenario, further improving operational responses.
[0062] In one possible implementation, adjusting the number of virtual nodes of a server based on the current load value of the server and the weight coefficient corresponding to the business scenario to which the current business request processed by the server belongs includes:
[0063] When the current load value is less than the average load value and the weight coefficient does not decrease, the number of virtual nodes is increased; wherein the average load value is the average of the current load values of multiple servers;
[0064] When the current load value is greater than the average load value and the weight coefficient does not increase, the number of virtual nodes is reduced.
[0065] When the server's current load is lower than the average and the weight coefficient remains unchanged, the number of virtual nodes can be increased. Similarly, when the server's current load is lower than the average and the weight coefficient increases, the number of virtual nodes can be increased. Of course, if the current load remains unchanged but the weight coefficient increases, the number of virtual nodes can be increased. Increasing the number of virtual nodes increases the probability of being assigned to a server, thereby balancing the load and ensuring more timely responses to data requests in this business scenario.
[0066] When the server's current load is higher than the average and the weight coefficient remains unchanged, the number of virtual nodes can be reduced. Similarly, when the server's current load is higher than the average and the weight coefficient decreases, the number of virtual nodes can be reduced. Of course, if the current load remains unchanged and the weight coefficient decreases, the number of virtual nodes can be reduced. By reducing the number of virtual nodes, the probability of being assigned to a server is reduced, thereby balancing the load.
[0067] The average load value may be an average of current load values of all servers.
[0068] The weight coefficient corresponding to the first type of business scenario is higher than the weight coefficient corresponding to the second type of business scenario. The first type of business scenario may be a business scenario with high real-time requirements and high server resource consumption, such as a real-time combat scenario. The second type of business scenario may be a business scenario with lower real-time requirements and low server resource consumption, such as a non-real-time social scenario, log processing, task management, etc.
[0069] The weight coefficient assigned to the first type of business scenario is higher, and the number of virtual nodes is larger, which can reduce the real-time request delay, make the game operation response more timely, and provide a better user experience. The weight coefficient assigned to the second type of business scenario is lower. Although the non-real-time request delay may increase due to the inclination of resources towards the real-time scenario, the overall performance can be guaranteed by dynamically adjusting the number of virtual nodes. In addition, in the second type of business scenario, users are basically unaware of the data return speed, which optimizes the game service performance.
[0070] Optionally, the formula for adjusting the number of virtual nodes of the server is as follows:
[0071] V=V0×(1+β×(Lavg-L))×S
[0072] Wherein, V is the number of virtual nodes of the server after adjustment, V0 is the number of virtual nodes of the initial server, that is, the number of virtual nodes corresponding to the server in the hash ring data in step 101, β is the adjustment coefficient, which is used to control the amplitude of the adjustment of the number of virtual nodes, S is the business scenario weight coefficient, which can be set according to different business scenarios, Lavg is the average load value, and L is the current load value of the server.
[0073] In one possible implementation, the process of calculating the current load value of the server may include:
[0074] Get multiple performance indicators of the server;
[0075] Determine the weight coefficient of each performance indicator based on the business scenario to which the current business request processed by the server belongs;
[0076] The product of the performance index and the corresponding weight coefficient is accumulated to obtain the current load value of the server.
[0077] The server's performance indicators may include, but are not limited to, CPU (Central Processing Unit) utilization (C), memory usage (M), network bandwidth utilization (N), request queue length (Q), and disk I / O usage (D). These performance indicators can reflect the server's real-time load status.
[0078] Based on the business scenario to which the current business request processed by the server belongs, the weight coefficient of each performance indicator is determined. Specifically, each indicator can be assigned a corresponding weight coefficient w1, w2, w3, w4, and w5. The weight coefficient corresponding to CPU utilization is w1, the weight coefficient corresponding to memory utilization is w2, the weight coefficient corresponding to network bandwidth utilization is w3, the weight coefficient corresponding to network bandwidth utilization is w4, and the weight coefficient corresponding to disk I / O utilization is w5, where w1+w2+w3+w4+w5=1.
[0079] The weighting coefficients of the above performance indicators can be adjusted based on the actual server operation and the needs of different business scenarios. For example, for real-time combat games, CPU utilization and network bandwidth utilization are more weighted; while for data storage-intensive games, disk I / O utilization may be more weighted.
[0080] The product of the performance index and the corresponding weight coefficient is accumulated to obtain the current load value of the server. The specific formula can be: L = w1C + w2M + w3N + w4Q + w5D.
[0081] In one possible implementation, the load balancing method provided in this application further includes:
[0082] Input the current business request into the convolutional neural network model of the scene classification model for feature extraction to obtain a first output result;
[0083] Inputting the first output result into the long short-term memory network of the scene classification model for feature extraction to obtain a second processing result;
[0084] The second processing result is input into the fully connected layer of the scene classification model for classification to obtain the business scene to which the current business request belongs.
[0085] This scenario classification model is constructed using a hybrid network of deep learning convolutional neural networks (CNNs) and long short-term memory networks (LSTMs). CNNs extract local features from data and effectively capture key information in business requests. LSTMs process sequential data and model the context of requests, thereby better understanding the semantics and intent of business requests. The scenario classification model can be trained using a large amount of historical business request data, covering a variety of business scenarios in the game, such as real-time combat, non-real-time social interaction, and task management. By learning from this training data, the model can identify the characteristics of different business scenarios. Therefore, when identifying the business scenario of a current business request, the current business request is fed into the scenario classification model's convolutional neural network model for feature extraction. The output is then fed into the LSTM network for feature extraction. The output is then fed into the fully connected layer for classification, resulting in the business scenario to which the current business request belongs.
[0086] Step 103: Update the hash ring data based on the adjusted number of virtual nodes.
[0087] When the number of virtual nodes corresponding to the server changes, the hash ring data also changes accordingly. Based on the adjusted number of virtual nodes, the position of each virtual node in the hash ring is determined, that is, the hash value of each virtual node is calculated, and each virtual node is matched with the server to obtain the updated hash ring data.
[0088] Step 104: Based on the updated hash ring data, the new service request is assigned to a server, and the new service request is sent to the assigned server for processing.
[0089] After receiving a new business request, the data carried by the new business request is hashed and the hash value is obtained. The hash value of the first virtual node that is greater than the hash value is determined, and the server corresponding to the virtual node is used as the assigned server. The new business request can be sent to the assigned server for processing.
[0090] In one possible implementation, assigning a server to a new service request based on the updated hash ring data includes:
[0091] Determine the business scenario to which the new business request belongs and obtain the target business scenario;
[0092] Calculate the hash value based on the new business request;
[0093] Based on the updated hash ring data, find the virtual node pointed to by the hash value and obtain the target virtual node;
[0094] In the case where the server corresponding to the target virtual node processes the business request corresponding to the target business scenario, the new business request is allocated to the server corresponding to the target virtual node;
[0095] When the server corresponding to the target virtual node does not process the business request corresponding to the target business scenario, the next virtual node of the target virtual node is determined based on the updated hash ring data, and starting from the server corresponding to the next virtual node, the server that processes the business request corresponding to the target business scenario is searched, and the new business request is assigned to the found server.
[0096] If the server corresponding to the first virtual node whose hash value is greater than the hash value is determined as the assigned server, and the business scenario to which the business request processed by the assigned server belongs does not include the business scenario corresponding to the new business request, the new business request cannot be sent to the above-mentioned assigned server.
[0097] Based on this, the target business scenario can be obtained by determining the business scenario to which the new business request belongs. If the server corresponding to the target virtual node processes the business request corresponding to the target business scenario, the new business request can be assigned to the server corresponding to the target virtual node. The target virtual node is the virtual node pointed to by the hash value calculated based on the updated hash ring data.
[0098] If the server corresponding to the target virtual node does not process the business request corresponding to the target business scenario, the next virtual node of the target virtual node is determined, and starting from the server corresponding to the next virtual node, the server corresponding to the business request of the target business scenario is searched clockwise on the hash ring, and the new business request is assigned to the found server.
[0099] For example, the updated hash ring data includes three server nodes A, B, and C. Server A has two virtual nodes (the hash values of the two virtual nodes A1 and A2 are 10 and 40 respectively), server B has three virtual nodes (the hash values of the three virtual nodes B1, B2, and B3 are 15, 30, and 45 respectively), and server C has four virtual nodes (the hash values of the three virtual nodes C1, C2, C3, and C4 are 5, 20, 35, and 50 respectively). If the hash value calculated based on the new business request is 38, then the virtual node pointed to by the hash value is found to obtain the target virtual node. Point A2 corresponds to server A, but server A is a non-instant server and processes the second type of business scenario, such as non-real-time social, task management and other business scenarios. The business scenario to which the new business request belongs is determined, and the target business scenario is the first type of business scenario, such as a real-time combat business scenario. The next virtual node of the target virtual node is determined to be B3, and the server corresponding to B3 is server B. Server B is an instant server and processes the first type of business scenario, such as a real-time combat business scenario. The new business request is assigned to the found server B.
[0100] In a possible implementation, allocating a server for a new service request based on the updated hash ring data further includes:
[0101] Based on the updated hash ring data, update the locally stored hash ring data;
[0102] Get new business requests;
[0103] Determine the business scenario to which the new business request belongs and obtain the target business scenario;
[0104] Determine whether the locally stored hash ring data contains node information of a server that processes a service request corresponding to the target service scenario;
[0105] If the locally stored hash ring data has the server's node information, the server is allocated for the new service request based on the locally stored hash ring data;
[0106] If the locally stored hash ring data does not have the server's node information, the hash ring data with the server's node information is obtained from the target database, and the server is allocated to the new service request based on the hash ring data with the server's node information.
[0107] In order to improve the data reading speed, the hash ring data can be stored locally. When the hash ring data is updated, the locally stored hash ring data is updated based on the updated hash ring data.
[0108] The hash ring data stored locally may be partial hash ring data. When a new business request is received, the new business request may be input into a scenario classification model to obtain the business scenario to which the new business request belongs, i.e., the target business scenario. Since the servers that process business requests for different types of business scenarios may be different, the locally stored hash ring data may only store servers that process business requests for one type of business scenario, and the target business scenario is not this type of business scenario, so it is possible to determine whether the locally stored hash ring data contains node information of the server that processes the business request corresponding to the target business scenario. If the locally stored hash ring data has the node information of the server, the new business request is assigned to a server based on the locally stored hash ring data; if the locally stored hash ring data does not have the node information of the server, the hash ring data with the node information of the server is obtained from the target database, which may store global hash ring data, and the target database may be etcd. After obtaining the hash ring data with the node information of the server, the new business request may be assigned to a server based on the hash ring data with the node information of the server.
[0109] In actual applications, when the server starts, it can obtain the latest partial or complete hash ring data from etcd and cache it locally. When processing a business request, it first queries the locally stored hash ring data. If the required hash ring data exists, it is used directly; if not, it obtains the data from etcd and updates the locally stored hash ring data.
[0110] In a possible implementation, after updating the hash ring data based on the adjusted number of virtual nodes, the following steps are further included:
[0111] Sending the updated hash ring data to the target database so that the target database updates the stored data based on the updated hash ring data and updates the version number of the stored data; wherein the stored data is the hash ring data stored in the target database;
[0112] Compare the version number of the locally stored hash ring data with the version number of the stored data to see if they are the same;
[0113] If they are not the same, the stored data is obtained from the target database, and the locally stored hash ring data is updated based on the stored data.
[0114] The server can send the updated hash ring data to the target database, so that the target database updates the stored data based on the updated hash ring data and updates the version number of the hash ring data stored in the target database. The hash ring data in the target database, such as etcd, has a version number, and when the data is updated, the version number can be incremented. Each server can synchronize with etcd regularly and compare the version number of the locally stored hash ring data with the version number of the data in etcd. If the version numbers are inconsistent, it means that the locally stored hash ring data is outdated. The server node obtains the latest hash ring data from etcd and updates the locally stored hash ring data. In this way, the timeliness and consistency of the locally stored hash ring data can be guaranteed.
[0115] Optionally, when new server nodes join or servers leave, etcd can send updated hash ring data to each server, ensuring that all servers maintain consistent hash ring data. etcd has high availability, ensuring reliable storage and access to hash ring data even if some servers fail.
[0116] The load balancing method of the present application realizes real-time and precise regulation of server load and efficient storage and reading of data through dynamic virtual node generation, business scenario weight distribution and etcd-based hierarchical storage, avoids excessive use of some server resources while some server resources are idle, improves server resource utilization, reduces game response delay, optimizes game server performance, provides players with a smooth and stable gaming experience, and maintains data consistency and reliability.
[0117] The load balancing method provided in this application is compared with the traditional load balancing method (such as the traditional consistent hashing algorithm), and the comparison results are shown in Table 1.
[0118] Table 1 Schematic diagram of comparison results
[0119] index Traditional methods This application method Improvement Real-time request latency 120ms 58ms 51.7% Non-real-time request latency 80ms 100ms -25% Server resource utilization 65% 82% 26% Cross-node data consistency Eventual consistency Near real-time consistency
[0120] Compared to traditional load balancing methods, the load balancing method provided by this application can significantly reduce real-time request latency, making game operations more responsive and significantly improving server resource utilization, making resource allocation more reasonable. Although the latency of non-real-time requests has increased due to the shift of resources toward real-time scenarios, dynamic scheduling ensures overall performance, is largely imperceptible to users, enhances cross-node data consistency, and optimizes game server performance. The server cluster's carrying capacity is improved, hardware costs are reduced, and operation and maintenance manpower is reduced.
[0121] The above describes a load balancing method provided by an embodiment of the present application. The following describes a system for executing the above load balancing method.
[0122] See also Figure 2 , Figure 2 This is a structural diagram of a load balancing system provided in an embodiment of the present application. Figure 2 As shown, the load balancing system includes:
[0123] The data acquisition module 201 is used to acquire hash ring data; wherein the hash ring data reflects the mapping relationship between the server and the virtual nodes located on the hash ring.
[0124] The virtual node quantity adjustment module 202 is used to adjust the number of virtual nodes of the server based on the current load value of the server and the weight coefficient corresponding to the business scenario to which the current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data.
[0125] The data updating module 203 is configured to update the hash ring data based on the adjusted number of virtual nodes.
[0126] The request allocation module 204 is configured to allocate servers to new service requests based on the updated hash ring data, and send the new service requests to the allocated servers for processing.
[0127] In a possible implementation, the virtual node quantity adjustment module 202 is specifically configured to:
[0128] When the current load value is less than the average load value and the weight coefficient does not decrease, the number of virtual nodes is increased; wherein the average load value is the average of the current load values of multiple servers;
[0129] When the current load value is greater than the average load value and the weight coefficient does not increase, the number of virtual nodes is reduced.
[0130] In one possible implementation, the load balancing system provided by this application further includes:
[0131] The load calculation module is used to obtain multiple performance indicators of the server; determine the weight coefficient of each performance indicator based on the business scenario to which the current business request processed by the server belongs; and accumulate the product of the performance indicator and the corresponding weight coefficient to obtain the current load value of the server.
[0132] In one possible implementation, the load balancing system provided by this application further includes:
[0133] The classification module is used to input the current business request into the convolutional neural network model of the scene classification model for feature extraction to obtain a first output result; input the first output result into the long short-term memory network of the scene classification model for feature extraction to obtain a second processing result; input the second processing result into the fully connected layer of the scene classification model for classification to obtain the business scenario to which the current business request belongs.
[0134] In one possible implementation, the request allocation module 204 is specifically configured to:
[0135] Determine the business scenario to which the new business request belongs and obtain the target business scenario;
[0136] Calculate the hash value based on the new business request;
[0137] Based on the updated hash ring data, find the virtual node pointed to by the hash value and obtain the target virtual node;
[0138] In the case where the server corresponding to the target virtual node processes the business request corresponding to the target business scenario, the new business request is allocated to the server corresponding to the target virtual node;
[0139] When the server corresponding to the target virtual node does not process the business request corresponding to the target business scenario, the next virtual node of the target virtual node is determined based on the updated hash ring data, and starting from the server corresponding to the next virtual node, the server that processes the business request corresponding to the target business scenario is searched, and the new business request is assigned to the found server.
[0140] In a possible implementation, the request allocation module 204 is further configured to:
[0141] Based on the updated hash ring data, update the locally stored hash ring data;
[0142] Get new business requests;
[0143] Determine the business scenario to which the new business request belongs and obtain the target business scenario;
[0144] Determine whether the locally stored hash ring data contains node information of a server that processes a service request corresponding to the target service scenario;
[0145] If the locally stored hash ring data has the server's node information, the server is allocated for the new service request based on the locally stored hash ring data;
[0146] If the locally stored hash ring data does not have the server's node information, the hash ring data with the server's node information is obtained from the target database, and the server is allocated to the new service request based on the hash ring data with the server's node information.
[0147] In one possible implementation, the load balancing system provided by this application further includes:
[0148] A comparison module is used to update the hash ring data based on the adjusted number of virtual nodes, and then send the updated hash ring data to the target database, so that the target database updates the stored data based on the updated hash ring data and updates the version number of the stored data; wherein the stored data is the hash ring data stored in the target database; compare the version number of the locally stored hash ring data with the version number of the stored data to see if they are the same; if they are not the same, obtain the stored data from the target database, and update the locally stored hash ring data based on the stored data.
[0149] An electronic device is also provided in an embodiment of the present application. Figure 3 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 3 The electronic device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0150] like Figure 3 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. When the electronic device is powered on, the RAM 303 also stores various programs and data required for the operation of the electronic device. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0151] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a memory card, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 3 The electronic device is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.
[0152] The electronic device can implement the above-mentioned load balancing method.
[0153] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any load balancing method provided in the embodiment of the present application.
[0154] An embodiment of the present application also provides a computer-readable storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any load balancing method provided in the embodiment of the present application.
[0155] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.
[0156] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.
[0157] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0158] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode to another website, computer, training device or data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center that includes one or more available media integrations. The available medium can be a magnetic medium, (for example, a floppy disk, a hard disk, a tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid-state drive (SSD)).
Claims
1. A load balancing method, characterized in that: include: Obtaining hash ring data; wherein the hash ring data reflects a mapping relationship between the server and the virtual nodes located on the hash ring; Adjusting the number of virtual nodes of the server based on a current load value of the server and a weight coefficient corresponding to a business scenario to which a current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data; Based on the adjusted number of virtual nodes, update the hash ring data; Based on the updated hash ring data, a server is allocated to the new service request, and the new service request is sent to the allocated server for processing.
2. The load balancing method according to claim 1, wherein: The adjusting the number of virtual nodes of the server based on the current load value of the server and the weight coefficient corresponding to the business scenario to which the current business request processed by the server belongs includes: When the current load value is less than the average load value and the weight coefficient is not reduced, increasing the number of virtual nodes; wherein the average load value is the average of the current load values of multiple servers; When the current load value is greater than the average load value and the weight coefficient does not increase, the number of virtual nodes is reduced.
3. The load balancing method according to claim 1, wherein: Also includes: Obtaining multiple performance indicators of the server; Determining a weight coefficient for each of the performance indicators based on a business scenario to which the current business request processed by the server belongs; The product of the performance index and the corresponding weight coefficient is accumulated to obtain the current load value of the server.
4. The load balancing method according to claim 1, wherein: Also includes: Inputting the current service request into a convolutional neural network model of a scene classification model for feature extraction to obtain a first output result; Inputting the first output result into the long short-term memory network of the scene classification model for feature extraction to obtain a second processing result; The second processing result is input into the fully connected layer of the scene classification model for classification to obtain the business scene to which the current business request belongs.
5. The load balancing method according to any one of claims 1 to 4, characterized in that: Allocating a server for a new service request based on the updated hash ring data includes: Determine the business scenario to which the new business request belongs, and obtain a target business scenario; Calculate a hash value based on the new service request; Based on the updated hash ring data, searching for the virtual node pointed to by the hash value to obtain the target virtual node; In a case where the server corresponding to the target virtual node processes a business request corresponding to the target business scenario, allocating the new business request to the server corresponding to the target virtual node; In the case that the server corresponding to the target virtual node does not process the business request corresponding to the target business scenario, the next virtual node of the target virtual node is determined based on the updated hash ring data, and starting from the server corresponding to the next virtual node, the server that processes the business request corresponding to the target business scenario is searched, and the new business request is assigned to the found server.
6. The load balancing method according to any one of claims 1 to 4, characterized in that: The server allocation for the new service request based on the updated hash ring data further includes: Based on the updated hash ring data, updating the locally stored hash ring data; Obtaining the new service request; Determine the business scenario to which the new business request belongs, and obtain a target business scenario; Determining whether the locally stored hash ring data contains node information of a server that processes a service request corresponding to the target service scenario; If the locally stored hash ring data has the node information of the server, allocating the server for the new service request based on the locally stored hash ring data; If the locally stored hash ring data does not have the node information of the server, the hash ring data with the node information of the server is obtained from the target database, and the server is allocated to the new service request based on the hash ring data with the node information of the server.
7. The load balancing method according to claim 6, wherein: After updating the hash ring data based on the adjusted number of virtual nodes, the method further includes: Sending the updated hash ring data to the target database, so that the target database updates the stored data based on the updated hash ring data and updates the version number of the stored data; wherein the stored data is the hash ring data stored in the target database; Comparing the version number of the locally stored hash ring data with the version number of the stored data to see if they are the same; If they are not the same, the stored data is obtained from the target database, and the locally stored hash ring data is updated based on the stored data.
8. A load balancing system, characterized in that: include: A data acquisition module, configured to acquire hash ring data, wherein the hash ring data reflects a mapping relationship between the server and the virtual nodes located on the hash ring; A virtual node quantity adjustment module, configured to adjust the number of virtual nodes of the server based on a current load value of the server and a weight coefficient corresponding to a business scenario to which a current business request processed by the server belongs; wherein the current business request is allocated to the server based on the hash ring data; A data updating module, configured to update the hash ring data based on the adjusted number of virtual nodes; The request allocation module is used to allocate servers to new service requests based on the updated hash ring data, and send the new service requests to the allocated servers for processing.
9. An electronic device, characterized in that: comprising at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program so that the electronic device can implement the load balancing method according to any one of claims 1 to 7.
10. A computer storage medium, characterized in that The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the load balancing method according to any one of claims 1 to 7.
Citation Information
Cited By
Server cluster load balancing method based on improved consistency Hash and Redis
CN121585666A
Big data intelligent storage system for parenteral nutrition liquid preparation
CN121687399A
A parenteral nutrition solution preparation big data intelligent storage system
CN121687399B