Load balancing method, proxy node, electronic equipment, medium and master-slave system

By configuring dynamic weights for slave nodes, the problem of request routing in master-slave data storage architecture when the network delay is large is solved, and data consistency and business logic correctness in network jitter scenarios are achieved.

CN119496742APending Publication Date: 2025-02-21BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311048701.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-18
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

In master-slave data storage architecture, especially systems such as Redis and MySql, when reading and writing separation is enabled, the general load balancing strategy cannot effectively utilize the database characteristics, resulting in the request being routed to the data delay when the network is large. nodes affect the correctness of business logic.

Method used

A load balancing method is proposed. By configuring dynamic weights for each slave node, updating historical weights based on dynamic weights, determining the optimal slave node, and routing the request to the node, reducing the impact of network jitter on load balancing.

Benefits of technology

In the network jitter scenario, the slave node with the lowest data delay is selected to process the request, ensure that the data obtained by the service is the latest and the correct operation of the business logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119496742A_ABST
    Figure CN119496742A_ABST
Patent Text Reader

Abstract

The invention relates to a load balancing method, a proxy node, electronic equipment, a medium and a master-slave system. In at least one embodiment of the invention, the received requests are distributed to the specific nodes in the master-slave system to realize the routing function of the requests, the first request is directly sent to the master node, and for the sending of the second request, the corresponding dynamic weight is configured for each slave node, and the optimal slave node is determined by using the dynamic weight, so that the routing function of the requests is realized. In addition, the dynamic weight can reflect the influence of the network jitter on the weight configuration, so that the optimal slave node determined by using the dynamic weight is the optimal slave node in the current network jitter scene, the data delay with the master node is minimum, and the load balancing is realized. And the second request is routed to the optimal slave node for processing, so that the influence caused by network jitter can be reduced, the data acquired by the service is the latest data, and the correct proceeding of the service logic is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of data processing technology, and in particular to a load balancing method, a proxy node, an electronic device, a medium, and a master-slave system. Background Art

[0002] In the process of data storage, a general load balancing strategy is usually used for load balancing in different scenarios that require load balancing. However, for data storage with non-strong consistency between master and slave data in a one-master-multiple-slave storage architecture, such as Redis (Remote dictionary server), MySql (a relational database management system), etc., some characteristics of the database itself are not well utilized in the scenario of enabling read-write separation (master-write-slave-read or master-read-slave-write). For example, when there is a large deviation in the consistency of master-slave data due to network delay, adopting a general load balancing strategy may cause the request to be routed to a node with a large data delay, resulting in the data obtained by the business not being the latest data, affecting the correct execution of the business logic. Summary of the invention

[0003] At least one embodiment of the present disclosure provides a load balancing method, a proxy node, an electronic device, a medium, and a master-slave system.

[0004] In a first aspect, an embodiment of the present disclosure provides a load balancing method, which is applied to a master-slave system, wherein the master-slave system includes at least one master node and a plurality of slave nodes connected to the master node, and the method includes:

[0005] In response to receiving the first request, sending the first request to the master node;

[0006] In response to receiving the second request, a corresponding dynamic weight is configured for each slave node; the historical weight of the corresponding slave node is updated based on the dynamic weight to obtain the current weight of each slave node; the second request is sent to the slave node corresponding to the maximum current weight, and the current weight of the slave node corresponding to the maximum current weight is reduced.

[0007] In some embodiments, in response to receiving the second request, configuring a corresponding dynamic weight for each slave node includes:

[0008] In response to receiving the second request, obtaining a first data offset maintained by the master node and a second data offset maintained by each slave node;

[0009] Based on the first data offset and each second data offset, a corresponding dynamic weight is configured for each slave node.

[0010] In some embodiments, configuring a corresponding dynamic weight for each slave node based on the first data offset and each second data offset includes:

[0011] Determine a change in the data offset of each slave node relative to the master node; wherein the change in the data offset of the slave node relative to the master node is a difference between a second data offset maintained by the slave node and the first data offset;

[0012] A corresponding dynamic weight is configured for each slave node, and the dynamic weight is inversely correlated with the change in the data offset of the corresponding slave node relative to the master node.

[0013] In some embodiments, updating the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node includes:

[0014] The dynamic weight is added to the historical weight of the corresponding slave node to obtain the current weight of the corresponding slave node.

[0015] In some embodiments, reducing the current weight of the slave node corresponding to the maximum current weight includes:

[0016] Determine the sum of the dynamic weights of each slave node to obtain the total dynamic weight;

[0017] Subtract the total dynamic weight from the current weight of the slave node corresponding to the maximum current weight.

[0018] In some embodiments, the load balancing method further includes:

[0019] The current weights of the slave nodes that have not received the second request are maintained unchanged.

[0020] In a second aspect, the embodiment of the present disclosure further proposes a proxy node, which is applied to a master-slave system, wherein the master-slave system includes at least one master node and a plurality of slave nodes connected to the master node, and the proxy node includes:

[0021] A first unit, in response to receiving the first request, sends the first request to the master node in English;

[0022] The second unit is used to configure a corresponding dynamic weight for each slave node in response to receiving a second request; update the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node; send the second request to the slave node corresponding to the maximum current weight, and reduce the current weight of the slave node corresponding to the maximum current weight.

[0023] In a third aspect, an embodiment of the present disclosure further proposes an electronic device, which includes a memory, a processor, and a computer program stored on the memory, wherein the processor executes the computer program to implement the steps of the load balancing method described in the first aspect.

[0024] In a fourth aspect, an embodiment of the present disclosure further proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a program or instructions, and the program or instructions enable a computer to execute the steps of the load balancing method described in the first aspect.

[0025] In a fifth aspect, an embodiment of the present disclosure further proposes a master-slave system, comprising at least one master node, and multiple slave nodes connected to the master node, and a proxy node as described in the second aspect, wherein the proxy node is connected to the master node and each slave node respectively.

[0026] In the sixth aspect, an embodiment of the present disclosure further provides a computer program product, wherein the computer program product includes a computer program, the computer program is stored in a computer-readable storage medium, and at least one processor of a computer reads and executes the computer program from the computer-readable storage medium, so that the computer performs the steps of the load balancing method described in the first aspect.

[0027] It can be seen that in at least one embodiment of the present disclosure, the received request is assigned to a specific node in the master-slave system (which can be a master node or a slave node) to realize the routing function of the request, wherein the first request is sent directly to the master node, and for the sending of the second request, by configuring the corresponding dynamic weight for each slave node, the optimal slave node is determined by using the dynamic weight, that is, the slave node corresponding to the maximum current weight, and then the second request is sent to the optimal slave node to realize load balancing. The load can be understood as the number of second requests received by the slave node. In addition, since the dynamic weight can reflect the impact of network jitter on the weight configuration, the optimal slave node determined by the dynamic weight is the optimal slave node in the current network jitter scenario. "Optimal" can be understood as the slave node with the smallest data delay with the master node in the current network jitter scenario. Routing the second request to the optimal slave node for processing can reduce the impact caused by network jitter, and the data delay between the optimal slave node and the master node is minimized, so that the data obtained by the business is the latest data, thereby ensuring the correct execution of the business logic. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure, and a person skilled in the art can also obtain other drawings based on these drawings.

[0029] Figure 1 A flow chart of a load balancing method provided in an embodiment of the present disclosure;

[0030] Figure 2A schematic diagram of a process for configuring dynamic weights provided in an embodiment of the present disclosure;

[0031] Figure 3 A schematic diagram of a proxy node provided in an embodiment of the present disclosure;

[0032] Figure 4 A schematic diagram of a master-slave system provided in an embodiment of the present disclosure;

[0033] Figure 5 An exemplary block diagram of an electronic device provided for an embodiment of the present disclosure. DETAILED DESCRIPTION

[0034] In order to more clearly understand the above-mentioned purposes, features and advantages of the present disclosure, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. The specific embodiments described herein are only used to explain the present disclosure, rather than to limit the present disclosure. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in the field belong to the scope of protection of the present disclosure.

[0035] It should be noted that, in this document, relational terms such as “first” and “second” are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.

[0036] Currently, common load balancing strategies include but are not limited to the following:

[0037] Simple random strategy: The service consumer will randomly access a service provider each time, and from a probability perspective, the probability of each provider being accessed is the same.

[0038] Weighted random strategy: Weighted random adds the concept of weight on the basis of simple random. The larger the weight, the greater the probability of being randomly selected. The weight can be set through many factors, such as server performance, etc.

[0039] Simple polling strategy: The service consumer will visit one service provider at a time, and from a probability perspective, the probability of each provider being visited is the same.

[0040] Simple weighted polling strategy: Simple weighted polling adds the concept of weight based on simple polling. The larger the weight, the greater the probability of being randomly selected during polling. The weight can be set based on many factors, such as server performance.

[0041] Smooth weighted polling strategy: Simple weighted polling will cause the problem of concentrated access. The smooth weighted polling strategy adjusts the polling order by configuring weights and combining them with the current weights, making the polling strategy smoother.

[0042] Consistent hashing strategy: First, the hash value of the storage node is calculated, which abstracts the storage space into a ring and configures the storage node on the ring. All nodes on the ring have a value. Secondly, the data is hashed and mapped to the node closest to it in a clockwise direction. The consistent hashing strategy has three significant characteristics: First, the same client can always access the same provider without adding or deleting providers. Second, consistent hashing can effectively disperse the volatility caused by adding or deleting service providers. Third, consistent hashing virtual nodes can more effectively disperse the volatility of feature two.

[0043] Minimum active number strategy: Each provider maintains the number of concurrently processed tasks. The larger the number of tasks, the higher the activity. When the service consumer performs load balancing, the first step is to query the provider load situation, and the second step is to select the provider with the lowest activity.

[0044] When network delays cause a large deviation in master-slave data consistency, adopting a general load balancing strategy may cause requests to be routed to nodes with large data delays, resulting in the business obtaining data that is not the latest data, affecting the correct execution of business logic.

[0045] Therefore, the embodiments of the present disclosure provide a load balancing method, apparatus, device or storage medium, which distributes the received requests to specific nodes (which can be master nodes or slave nodes) in a master-slave system to implement the routing function of the request, wherein the first request is sent directly to the master node, and for the sending of the second request, by configuring the corresponding dynamic weight for each slave node, the optimal slave node is determined using the dynamic weight, that is, the slave node corresponding to the maximum current weight, and then the second request is sent to the optimal slave node to achieve load balancing. The load can be understood as the number of second requests received by the slave node. In addition, since the dynamic weight can reflect the impact of network jitter on the weight configuration, the optimal slave node determined using the dynamic weight is the optimal slave node in the current network jitter scenario. "Optimal" can be understood as the slave node with the smallest data delay with the master node in the current network jitter scenario. Routing the second request to the optimal slave node for processing can reduce the impact caused by network jitter, and the data delay between the optimal slave node and the master node is minimized, so that the data obtained by the business is the latest data, thereby ensuring the correct execution of the business logic.

[0046] Figure 1A flow chart of a load balancing method provided for an embodiment of the present disclosure, wherein the executor of the load balancing method is an electronic device, and the electronic device includes but is not limited to a smart phone, a PDA, a tablet computer, a wearable device with a display screen, a desktop computer, a laptop computer, an all-in-one machine, a smart home device, a server, etc., wherein the server can be an independent server or a cluster of multiple servers, and can include a server built locally and a server built in the cloud.

[0047] In some embodiments, the load balancing method is applied to a master-slave system, which includes at least one master node and multiple slave nodes connected to the master node. The executor of the load balancing method is a proxy node, which belongs to a node in the master-slave system, and the proxy node is connected to the master node and each slave node respectively.

[0048] like Figure 1 As shown, the load balancing method may include but is not limited to step 101 and step 102:

[0049] In step 101, in response to receiving a first request, the first request is sent to a master node.

[0050] In this embodiment, the first request and the second request may be any two requests with different functions, for example, the first request is a read request and the second request is a write request; or the first request is a write request and the second request is a read request. It should be noted that this embodiment does not limit the specific contents of the first request and the second request.

[0051] In this embodiment, the first request and / or the second request is sent by the client to the proxy node in the master-slave system, and the proxy node distributes the received request to a specific node in the master-slave system (which can be a master node or a slave node) to realize the routing function of the request.

[0052] Taking read-write requests as an example, the proxy node can determine whether the master-slave system has enabled read-write separation. For example, the master node is responsible for processing the first request, and the slave node is responsible for processing the second request. If the first request is a read request, the second request is a write request; if the first request is a write request, the second request is a read request. The timing of the judgment can be when the proxy node first receives the request sent by the client (which can be the first request or the second request) after the master-slave system is started, or the proxy node directly makes the judgment after the master-slave system is started. After the proxy node determines that the master-slave system has enabled read-write separation, it directly sends the first request to the master node in response to receiving the first request.

[0053] It should be noted that if the proxy node determines that the master-slave system does not have read-write separation enabled, the proxy node stops executing steps 101 and 102. In addition, if the proxy node determines that there is only one slave node in the master-slave system, the proxy node stops executing steps 101 and 102.

[0054] In step 102, in response to receiving the second request, a corresponding dynamic weight is configured for each slave node; the historical weight of the corresponding slave node is updated based on the dynamic weight to obtain the current weight of each slave node; the second request is sent to the slave node corresponding to the maximum current weight, and the current weight of the slave node corresponding to the maximum current weight is reduced.

[0055] In this embodiment, after the proxy node determines that the master-slave system starts read-write separation, in response to receiving the second request, it selects a slave node from multiple slave nodes included in the master-slave system as a recipient of the second request.

[0056] In order to select a slave node from multiple slave nodes, in this embodiment, the proxy node configures a corresponding dynamic weight for each slave node. The "dynamic" means that the configured weight is not a fixed value, but the configured weight is adaptively adjusted according to different network jitter conditions. Therefore, the dynamic weight can reflect the impact of network jitter on the weight configuration; further, the historical weight of the slave node is updated based on the dynamic weight, and the current weight of the slave node obtained can also reflect the impact of network jitter. Therefore, the slave node corresponding to the maximum current weight is the optimal slave node in the current network jitter scenario. "Optimal" can be understood as the slave node with the smallest data delay with the master node in the current network jitter scenario; thereby, the second request is sent to the slave node corresponding to the maximum current weight, so that the second request is routed to the optimal slave node for processing. Since the optimal slave node is the optimal slave node in the current network jitter scenario, the impact caused by network jitter can be reduced, and the data delay between the optimal slave node and the master node is the smallest, thereby ensuring the correct execution of the business logic.

[0057] It should be noted that reducing the current weight of the slave node corresponding to the maximum current weight can be performed after determining the slave node corresponding to the maximum current weight, or can be performed after sending the second request to the slave node corresponding to the maximum current weight.

[0058] It should be noted that the slave node corresponding to the maximum current weight may also be determined first, so that the slave node can receive the next second request.

[0059] It can be seen that in the embodiment of the present disclosure, the received request is distributed to a specific node in the master-slave system (which can be a master node or a slave node) to realize the routing function of the request, wherein the first request is sent directly to the master node, and for the sending of the second request, by configuring the corresponding dynamic weight for each slave node, the optimal slave node is determined by using the dynamic weight, that is, the slave node corresponding to the maximum current weight, and then the second request is sent to the optimal slave node to realize load balancing. The load can be understood as the number of second requests received by the slave node. In addition, since the dynamic weight can reflect the impact of network jitter on the weight configuration, the optimal slave node determined by the dynamic weight is the optimal slave node in the current network jitter scenario. "Optimal" can be understood as the slave node with the smallest data delay with the master node in the current network jitter scenario. Routing the second request to the optimal slave node for processing can reduce the impact caused by network jitter, and the data delay between the optimal slave node and the master node is minimized, so that the data obtained by the business is the latest data, thereby ensuring the correct execution of the business logic.

[0060] In some embodiments, an implementation of "configuring a corresponding dynamic weight for each slave node in response to receiving the second request" in step 102 is as follows: Figure 2 As shown, the process includes the following steps 201 and 202:

[0061] In step 201, in response to receiving a second request, a first data offset maintained by the master node and a second data offset maintained by each slave node are obtained.

[0062] In this embodiment, in response to receiving the second request, the proxy node obtains the first data offset from the master node, and obtains the second data offset from each slave node in the master-slave system. The first data offset is the offset maintained by the master node, which can be understood as the offset (offset) of the data processed by the master node itself. The second data offset is the offset maintained by the slave node, specifically, the slave node synchronizes data from the master node through asynchronous synchronization, and maintains the offset (offset) of the data processed by itself.

[0063] It can be seen that the closer the second data offset is to the first data offset, the newer the data of the slave node is, and the data delay with the master node is the smallest.

[0064] In step 202, a corresponding dynamic weight is configured for each slave node based on the first data offset and each second data offset.

[0065] In this embodiment, the proxy node uses the data offset (including the first data offset and each second data offset) to configure the corresponding dynamic weight for each slave node. Because the change (i.e., the difference) between the second data offset and the first data offset will change under different network jitters, the change in the data offset reflects the impact of network jitter on the data of the slave node synchronizing the master node. The change in the data offset of different slave nodes relative to the master node is different, reflecting the different impacts of network jitter on different slave nodes. Therefore, the dynamic weight configured using the data offset can reflect the impact of network jitter on the weight configuration. The dynamic weight reflects the ability of the slave node to resist network jitter. The higher the dynamic weight, the smaller the change in the data offset of the slave node relative to the master node.

[0066] In some embodiments, an implementation of "configuring a corresponding dynamic weight for each slave node based on the first data offset and each second data offset" in step 202 is as follows:

[0067] First, determine the change in the data offset of each slave node relative to the master node; wherein the change in the data offset of the slave node relative to the master node is the difference between the second data offset maintained by the slave node and the first data offset; then, configure a corresponding dynamic weight for each slave node, and the dynamic weight is inversely correlated with the change in the data offset of the corresponding slave node relative to the master node.

[0068] It should be noted that this embodiment does not limit the specific anti-correlation relationship between the dynamic weight and the change in the data offset, and those skilled in the art can set the specific anti-correlation relationship according to actual needs.

[0069] In some embodiments, one implementation of "updating the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node" in step 102 is: adding the dynamic weight to the historical weight of the corresponding slave node to obtain the current weight of the corresponding slave node. Correspondingly, one implementation of "reducing the current weight of the slave node corresponding to the maximum current weight" in step 102 is: determining the sum of the dynamic weights of each slave node to obtain the total dynamic weight; subtracting the total dynamic weight from the current weight of the slave node corresponding to the maximum current weight, and the weight value obtained is used as the historical weight of the next second request route.

[0070] In some embodiments, since a slave node is selected from a plurality of slave nodes to receive the second request, the current weights of the other slave nodes that have not received the second request are maintained unchanged as the historical weights for the next second request routing. When the second request is received again, step 102 is repeated to implement the routing of the second request, that is, the corresponding dynamic weight is reconfigured for each slave node, the historical weight of the corresponding slave node is updated based on the dynamic weight, and the current weight of each slave node is obtained; the second request is sent to the slave node corresponding to the maximum current weight, and the current weight of the slave node corresponding to the maximum current weight is reduced.

[0071] Based on the load balancing method disclosed in the above embodiments, the technical effect of the present disclosure is explained by comparing it with the traditional smooth weighted polling strategy:

[0072] Taking the master-slave system including three slave nodes (denoted as node A, node B and node C) as an example, the execution results of the traditional smooth weighted polling strategy are shown in Table 1. The rounds in Table 1 represent the order of receiving the second request, that is, round 1 represents the first time the second request is received, round 2 represents the second time the second request is received, and so on. Round 7 represents the seventh time the second request is received.

[0073] Table 1 Execution results of traditional smooth weighted polling strategy

[0074] Round The current weight set of this round Selected Node Next round of historical weight collection 1 {4,2,1} A {-3,2,1} 2 {1,4,2} B {1,-3,2} 3 {5,-1,3} A {-2,-1,3} 4 {2,1,4} C {2,1,-3} 5 {6,3,-2} A {-1,3,-2} 6 {3,5,-1} B {3,-2,-1} 7 {7,0,0} A {0,0,0}

[0075] The initial weights of nodes A, B, and C are all set to zero. To update the weights, a fixed weight of 4 is configured for node A, a fixed weight of 2 is configured for node B, and a fixed weight of 1 is configured for node C.

[0076] In round 1 of Table 1, the initial weight of each node is added to the corresponding fixed weight to obtain the current weight of each node: the current weight of node A is 4, the current weight of node B is 2, and the current weight of node C is 1, which is recorded as the current weight set of this round {4, 2, 1}. Select node A with the largest current weight as the receiving node of the second request. After sending the second request to node A, subtract the sum of the fixed weights (4+2+1) from the current weight of node A, and the weight value (-3) obtained is used as the historical weight of node A participating in the next second request routing. Maintain the current weights of node B and node C unchanged as the historical weights participating in the next second request routing. Therefore, the historical weight set for the next round is {-3, 2, 1}.

[0077] In round 2 of Table 1, the historical weight of each node is added to the corresponding fixed weight to obtain the current weight of each node: the current weight of node A is 1 (i.e. -3+4), the current weight of node B is 4 (i.e. 2+2), and the current weight of node C is 2 (i.e. 1+1), which is recorded as the current weight set of this round {1, 4, 2}. Node B with the largest current weight is selected as the receiving node of the second request. After sending the second request to node B, the current weight of node B (4) is subtracted from the sum of fixed weights (i.e. 4+2+1), and the weight value (-3) obtained is used as the historical weight of node B participating in the next second request routing. The current weights of nodes A and C are maintained unchanged as the historical weights participating in the next second request routing. Therefore, the historical weight set for the next round is {1, -3, 2}.

[0078] In round 3 of Table 1, the historical weight of each node is added to the corresponding fixed weight to obtain the current weight of each node: the current weight of node A is 5 (1+4), the current weight of node B is -1 (-3+2), and the current weight of node C is 3 (2+1), which is recorded as the current weight set of this round {5, -1, 3}. Node A with the largest current weight is selected as the receiving node of the second request. After the second request is sent to node A, the current weight of node A (5) is subtracted from the sum of fixed weights (4+2+1), and the weight value (-2) obtained is used as the historical weight of node A participating in the next second request routing. The current weights of node B and node C are maintained unchanged as the historical weights participating in the next second request routing. Therefore, the historical weight set of the next round is {-2, -1, 3}. Rounds 4 to 7 are similar and will not be repeated.

[0079] However, when the network jitters, for example in round 3, the data delay between node A and the main node is large due to network jitter, but the impact on node C is small. The data of node C is closer to the data of the main node. If the traditional smooth weighted polling strategy is followed, node A will still be selected as the receiving node for the second request, and the better node C will not be selected as the receiving node, resulting in the data obtained by the business not being the latest data, affecting the correct execution of the business logic. It can be seen that network jitter has a greater impact on the traditional smooth weighted polling strategy.

[0080] In order to reduce the impact of network jitter, the execution results of the load balancing strategy provided by the present disclosure are shown in Table 2.

[0081] Table 2 Execution results of the load balancing strategy provided by the present disclosure

[0082] Round The current weight set of this round Selected Node Next round of historical weight collection 1 {4,2,1} A {-3,2,1} 2 {1,4,2} B {1,-3,2} 3 {2,1,4} C {2,1,-3} 4 {3,5,-1} C {3,-2,-1} 5 {7,0,0} A {0,0,0} 6 {4,2,1} A {-3,2,1} 7 {1,4,2} B {1,-3,2}

[0083] The initial weights of nodes A, B, and C are all set to zero. To update the weights, a dynamic weight of 4 is configured for node A, a dynamic weight of 2 is configured for node B, and a dynamic weight of 1 is configured for node C.

[0084] In rounds 1 and 2, the network does not jitter, so rounds 1 and 2 in Table 2 are the same as rounds 1 and 2 in Table 1. If the network jitters after round 2, in round 3, corresponding dynamic weights are configured for nodes A, B, and C. Specifically, if the change in the data offset of node A relative to the master node becomes the largest, the smallest dynamic weight 1 is configured for node A; if the change in the data offset of node B relative to the master node becomes the smallest, the largest dynamic weight 4 is configured for node B, and the dynamic weight 2 is configured for node C.

[0085] Therefore, in round 3, the historical weight of each node is added to the corresponding dynamic weight to obtain the current weight of each node: the current weight of node A is 2 (1 + 1), the current weight of node B is 1 (-3 + 4), and the current weight of node C is 4 (2 + 2), which is recorded as the current weight set of this round {2, 1, 4}. Node C with the largest current weight is selected as the receiving node of the second request. After sending the second request to node C, the current weight of node C (4) is subtracted from the sum of fixed weights (4 + 2 + 1), and the weight value (-3) obtained is used as the historical weight of node C participating in the next second request routing. The current weights of nodes A and B are maintained unchanged as the historical weights participating in the next second request routing. Therefore, the historical weight set for the next round is {2, 1, -3}.

[0086] In round 4, if the network jitter is still ongoing and the change in the data offset of node A relative to the master node becomes the largest, the smallest dynamic weight 1 is configured for node A; if the change in the data offset of node B relative to the master node becomes the smallest, the largest dynamic weight 4 is configured for node B, and the dynamic weight 2 is configured for node C. The historical weight of each node is added to the corresponding dynamic weight to obtain the current weight of each node: the current weight of node A is 3 (2+1), the current weight of node B is 5 (1+4), and the current weight of node C is -1 (-3+2), which is recorded as the current weight set of this round {3, 5, -1}. Node B with the largest current weight is selected as the receiving node of the second request. After sending the second request to node B, the current weight (5) of node B is subtracted from the sum of fixed weights (4+2+1), and the weight value (-2) obtained is used as the historical weight of node B participating in the next second request routing. The current weights of nodes A and C are maintained unchanged as the historical weights participating in the next second request routing. Therefore, the next round of historical weight set is {3, -2, -1}.

[0087] In round 5, if the network jitter stops and the change in the data offset of node A relative to the master node becomes the smallest, the largest dynamic weight of 4 is configured for node A; if the change in the data offset of node B relative to the master node becomes the second smallest, the second largest dynamic weight of 2 is configured for node B; if the change in the data offset of node C relative to the master node becomes the largest, the smallest dynamic weight of 1 is configured for node C. Add the historical weight of each node to the corresponding dynamic weight to obtain the current weight of each node: the current weight of node A is 7 (3+4), the current weight of node B is 0 (-2+2), and the current weight of node C is 0 (-1+1), which is recorded as the current weight set of this round {7, 0, 0}. Select node A with the largest current weight as the receiving node of the second request. After sending the second request to node A, subtract the fixed weight sum (4+2+1) from the current weight of node A (7), and the weight value (0) obtained is used as the historical weight of node A participating in the next second request routing. Maintain the current weights of node B and node C unchanged as the historical weights participating in the next second request routing. Therefore, the next round of historical weight set is {0, 0, 0}.

[0088] In rounds 6 and 7, if the network does not jitter and the change in the data offset of node A relative to the master node becomes the smallest, the largest dynamic weight 4 is configured for node A; if the change in the data offset of node B relative to the master node becomes the second smallest, the second largest dynamic weight 2 is configured for node B; if the change in the data offset of node C relative to the master node becomes the largest, the smallest dynamic weight 1 is configured for node C. The remaining operations are not repeated here.

[0089] It can be seen that compared with the execution results of the traditional smooth weighted polling strategy shown in Table 1, in the execution results of the load balancing strategy shown in Table 2, each round (that is, each time the second request is received) assigns a corresponding dynamic weight to each slave node, instead of configuring a fixed weight, to adapt to the network jitter of each round, so that the dynamic weight can reflect the impact of network jitter on the weight configuration. Therefore, the optimal slave node determined by the dynamic weight is the optimal slave node in the current network jitter scenario, and the data delay with the master node is the smallest. Routing the second request to the optimal slave node for processing can reduce the impact of network jitter, ensure that the data obtained by the business is the latest data, and ensure the correct execution of the business logic.

[0090] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all described as a series of action combinations, but those skilled in the art can understand that the embodiments of the present disclosure are not limited by the described action sequence, because according to the embodiments of the present disclosure, some steps can be performed in other sequences or simultaneously. In addition, those skilled in the art can understand that the embodiments described in the specification are all optional embodiments.

[0091] Figure 3 A schematic diagram of a proxy node provided in an embodiment of the present disclosure is applied to a master-slave system, wherein the master-slave system includes at least one master node and multiple slave nodes connected to the master node. The proxy node can be applied to electronic devices, including but not limited to smart phones, PDAs, tablet computers, wearable devices with display screens, desktop computers, laptop computers, all-in-one machines, smart home devices, servers, etc., wherein the server can be an independent server or a cluster of multiple servers, including servers built locally and servers built in the cloud. The proxy node provided in the embodiment of the present disclosure can execute the processing flow provided in each embodiment of the load balancing method, such as Figure 3 As shown, the proxy node includes but is not limited to: a first unit 31 and a second unit 32. The functions of each unit are described as follows:

[0092] The first unit 31, in response to receiving the first request, sends the first request to the master node in English;

[0093] The second unit 32 is used to configure a corresponding dynamic weight for each slave node in response to receiving a second request; update the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node; send the second request to the slave node corresponding to the maximum current weight, and reduce the current weight of the slave node corresponding to the maximum current weight.

[0094] In some embodiments, in response to receiving the second request, the second unit 32 configures a corresponding dynamic weight for each slave node, including:

[0095] In response to receiving the second request, obtaining a first data offset maintained by the master node and a second data offset maintained by each slave node;

[0096] Based on the first data offset and each second data offset, a corresponding dynamic weight is configured for each slave node.

[0097] In some embodiments, the second unit 32 configures a corresponding dynamic weight for each slave node based on the first data offset and each second data offset, including:

[0098] Determine a change in the data offset of each slave node relative to the master node; wherein the change in the data offset of the slave node relative to the master node is a difference between a second data offset maintained by the slave node and the first data offset;

[0099] A corresponding dynamic weight is configured for each slave node, and the dynamic weight is inversely correlated with the change in the data offset of the corresponding slave node relative to the master node.

[0100] In some embodiments, the second unit 32 updates the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node, including:

[0101] The dynamic weight is added to the historical weight of the corresponding slave node to obtain the current weight of the corresponding slave node.

[0102] In some embodiments, the second unit 32 reduces the current weight of the slave node corresponding to the maximum current weight, including:

[0103] Determine the sum of the dynamic weights of each slave node to obtain the total dynamic weight;

[0104] Subtract the total dynamic weight from the current weight of the slave node corresponding to the maximum current weight.

[0105] In some embodiments, the second unit 32 is further configured to:

[0106] The current weights of the slave nodes that have not received the second request are maintained unchanged.

[0107] It can be seen that in at least one proxy node embodiment of the present disclosure, the received request is assigned to a specific node in the master-slave system (which can be a master node or a slave node) to realize the routing function of the request, wherein the first request is sent directly to the master node, and for the sending of the second request, by configuring the corresponding dynamic weight for each slave node, the optimal slave node is determined by using the dynamic weight, that is, the slave node corresponding to the maximum current weight, and then the second request is sent to the optimal slave node to realize load balancing. The load can be understood as the number of second requests received by the slave node. In addition, since the dynamic weight can reflect the impact of network jitter on the weight configuration, the optimal slave node determined by the dynamic weight is the optimal slave node in the current network jitter scenario. "Optimal" can be understood as the slave node with the smallest data delay with the master node in the current network jitter scenario. Routing the second request to the optimal slave node for processing can reduce the impact caused by network jitter, and the data delay between the optimal slave node and the master node is minimized, so that the data obtained by the business is the latest data, thereby ensuring the correct execution of the business logic.

[0108] Figure 4 A master-slave system provided for an embodiment of the present disclosure includes at least one master node (Master), a plurality of slave nodes (Replica) connected to the master node, and a proxy node (Proxy), wherein the proxy node is connected to the master node and each slave node respectively.

[0109] exist Figure 4 There are four slave nodes in total: ReplicaA, ReplicaB, ReplicaC, and ReplicaD. The master-slave system enables read-write separation.

[0110] The user sends a request (write request or read request) to the Proxy through the client, and the Proxy distributes the request to a specific node to implement the routing function of the request.

[0111] The Master is responsible for processing write requests, and the Master maintains the first data offset (first offset) of the data it processes. The Master can also process read requests. When the master-slave system enables read-write separation, the read request is processed by the slave node, and the Master does not process the read request.

[0112] ReplicaA to ReplicaD synchronize data from the Master through asynchronous synchronization, and maintain the second data offset (second offset) of the data processed by themselves. The closer the second offset is to the first offset, the newer the data of the slave node is, and the data delay with the master node is the smallest.

[0113] exist Figure 4 In the example, when the proxy is started, it obtains the offset information of the Master and its slave nodes ReplicaA to ReplicaD, which are recorded as offset1 to offset4. The proxy configures the dynamic weight for processing read requests for the slave node, rather than the fixed weight. The size of the dynamic weight is configured according to the offset information of the current slave node. Compared with the traditional smooth weighted polling strategy, the advantage is that if a higher fixed weight is configured for a slave node according to the traditional smooth weighted polling strategy, if the data synchronization between the slave node and the master node slows down due to network jitter at a certain time, the offset difference (the difference between the second offset and the first offset) becomes larger. According to the traditional smooth weighted polling strategy, the slave node is likely to still be assigned to the next read request, but the data obtained by the user at this time may not be the latest. However, by using the method of configuring dynamic weights in this solution, since the offset difference of the slave node becomes larger, the dynamic weight configured in the next round becomes smaller, and the dynamic weights configured for other slave nodes with smaller offset differences become larger. The next read request will be assigned to the slave node with a smaller offset difference with a high probability, so that the data obtained by the user is more accurate.

[0114] Figure 5 is an exemplary block diagram of an electronic device provided by an embodiment of the present disclosure. Figure 5 As shown, the electronic device includes: a memory 51, a processor 52, and a computer program stored in the memory 51. It can be understood that the memory 51 in this embodiment can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories.

[0115] In some implementations, the memory 51 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof: an operating system and application programs.

[0116] The operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic tasks and process hardware-based tasks. The application includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application tasks. The program that implements the load balancing method provided in the embodiment of the present disclosure can be included in the application.

[0117] In the embodiment of the present disclosure, at least one processor 52 calls a program or instruction stored in at least one memory 51, specifically, a program or instruction stored in an application, and at least one processor 52 is used to execute the steps of each embodiment of the load balancing method provided in the embodiment of the present disclosure.

[0118] The load balancing method provided in the embodiment of the present disclosure can be applied to the processor 52, or implemented by the processor 52. The processor 52 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 52 or an instruction in the form of software. The above processor 52 can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0119] The steps of the load balancing method provided in the embodiment of the present disclosure can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 51, and the processor 52 reads the information in the memory 51 and completes the steps of the method in combination with its hardware.

[0120] The embodiment of the present disclosure also proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a program or instruction, wherein the program or instruction enables a computer to execute the steps of each embodiment of the load balancing method, which will not be described here to avoid repeated description. The computer-readable storage medium may be a non-transitory computer-readable storage medium.

[0121] The embodiment of the present disclosure also proposes a computer program product, which includes a computer program, which is stored in a computer-readable storage medium, and the computer-readable storage medium may be a non-transitory computer-readable storage medium. At least one processor of a computer reads and executes the computer program from the computer-readable storage medium, so that the computer executes the steps of each embodiment of the load balancing method, which will not be described here in detail to avoid repeated description.

[0122] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0123] Those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the present disclosure and to form different embodiments.

[0124] Those skilled in the art will appreciate that the description of each embodiment has its own emphasis, and for parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0125] Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A load balancing method, applied to a master-slave system, wherein the master-slave system includes at least one master node and a plurality of slave nodes connected to the master node, the method comprising: In response to receiving the first request, sending the first request to the master node; In response to receiving the second request, configuring a corresponding dynamic weight for each of the slave nodes; Update the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node; The second request is sent to the slave node corresponding to the maximum current weight, and the current weight of the slave node corresponding to the maximum current weight is reduced.

2. The method according to claim 1, wherein: In response to receiving the second request, configuring a corresponding dynamic weight for each slave node includes: In response to receiving the second request, obtaining a first data offset maintained by the master node and a second data offset maintained by each of the slave nodes; Based on the first data offset and each of the second data offsets, a corresponding dynamic weight is configured for each of the slave nodes.

3. The method according to claim 1, wherein: The configuring a corresponding dynamic weight for each slave node based on the first data offset and each of the second data offsets includes: Determine a change in the data offset of each slave node relative to the master node; wherein the change in the data offset of the slave node relative to the master node is a difference between a second data offset maintained by the slave node and the first data offset; A corresponding dynamic weight is configured for each slave node, and the dynamic weight is inversely correlated with a change in the data offset of the corresponding slave node relative to the master node.

4. The method according to any one of claims 1 to 3, wherein: The updating of the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node includes: The dynamic weight is added to the historical weight of the corresponding slave node to obtain the current weight of the corresponding slave node.

5. The method according to any one of claims 1 to 3, wherein: The reducing the current weight of the slave node corresponding to the maximum current weight includes: Determine the sum of the dynamic weights of each of the slave nodes to obtain a total dynamic weight; The total dynamic weight is subtracted from the current weight of the slave node corresponding to the maximum current weight.

6. The method according to claim 1, wherein: The method further comprises: The current weights of the slave nodes that have not received the second request are maintained unchanged.

7. A proxy node, applied to a master-slave system, wherein the master-slave system comprises at least one master node and a plurality of slave nodes connected to the master node, wherein the proxy node comprises: a first unit, in response to receiving a first request, sending the first request to the master node in English; A second unit, configured to configure a corresponding dynamic weight for each slave node in response to receiving a second request; Update the historical weight of the corresponding slave node based on the dynamic weight to obtain the current weight of each slave node; The second request is sent to the slave node corresponding to the maximum current weight, and the current weight of the slave node corresponding to the maximum current weight is reduced.

8. An electronic device, wherein: The method comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the load balancing method according to any one of claims 1 to 6.

9. A computer-readable storage medium, wherein: The computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute the steps of the load balancing method according to any one of claims 1 to 6.

10. A master-slave system, comprising at least one master node, and a plurality of slave nodes connected to the master node, and a proxy node as claimed in claim 7, wherein the proxy node is connected to the master node and each of the slave nodes respectively.