Polling load balancing method and device based on zset data structure
By using the zset data structure and Redis cluster in the load balancing system, the score values of the server nodes are dynamically adjusted to reflect the load situation, solving the problems of insufficient scalability and high maintenance costs of traditional load balancing strategies in high concurrency scenarios, and achieving flexible load balancing adjustment and resource optimization.
Patent Information
- Application Number
- CN202411495050.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-10-24
AI Technical Summary
Traditional load balancing strategies lack scalability and high maintenance costs in high concurrency and large traffic scenarios, resulting in poor flexibility in load balancing adjustment.
The polling load balancing method based on the zset data structure is adopted, and the client request is received through the load balancer, the zset data structure is queried from the Redis cluster, the server node is allocated according to the score value, and the score value is dynamically updated to reflect the server load situation. When the server load exceeds the threshold, increase the score value to lower the priority.
Improve the flexibility of load balancing adjustment, optimize resource utilization, and reduce operation and maintenance costs.
Smart Images

Figure CN119011590B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Internet load balancing, and in particular to a polling load balancing method and device based on a zset data structure. Background Art
[0002] With the rapid development of Internet technology, the scale and complexity of network applications are increasing. In order to ensure the stable operation of the system in high concurrency and large traffic scenarios, load balancing has become one of the key technologies.
[0003] At present, traditional load balancing strategies, such as hardware-based load balancers or simple polling algorithms, can perform load balancing distribution to a certain extent to improve system performance. However, this method often has the problems of insufficient scalability and high maintenance costs, which makes it difficult to dynamically adjust the load. Therefore, the flexibility of load balancing adjustment is poor. Summary of the invention
[0004] Based on this, it is necessary to provide a polling load balancing method and device based on the zset data structure with good load balancing adjustment flexibility and low operation and maintenance cost to address the above technical problems.
[0005] The present invention provides a polling load balancing method based on a zset data structure, the method comprising:
[0006] Receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating a server node according to a score value in the zset data structure;
[0007] Determine the plurality of server nodes in order of the score values in the zset data structure, and update the score value of each server node to characterize the load condition of the server node;
[0008] When the load of the server node exceeds a first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure;
[0009] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0010] In one embodiment, the process of receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating a server node according to a score value in the zset data structure, comprises:
[0011] The plurality of server nodes are stored in a zset data structure in the Redis cluster, and a value is assigned to each server node to obtain an initial score value of each server node;
[0012] Different identification information is set for each server node according to a set rule, so that different server nodes have unique node identifiers respectively;
[0013] Each server node has a unique node identifier, and multiple server nodes with different node identifiers have the same initial score value. The node identifier includes the IP address, port and ID name of the server node.
[0014] In one embodiment, receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating server nodes according to a score value in the zset data structure, includes:
[0015] Receiving a service allocation request from a client through the load balancer, and the load balancer querying a server node from a zset data structure in the Redis cluster in response to the service allocation request;
[0016] When multiple server nodes in the zset data structure all have the same initial score value, one server node is selected from the multiple server nodes, and a first value is added to the initial score value of the selected server node;
[0017] The first value is a preset fixed value used to represent the load increase of the selected server node.
[0018] In one embodiment, the receiving of a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating server nodes according to a score value in the zset data structure, further includes:
[0019] Sort the multiple server nodes in the zset data structure according to the final score value of each server node to obtain the zset data structure of the ordered set of multiple server nodes;
[0020] The load balancer responds to the service allocation request and selects a server node with the smallest score value from the zset data structure.
[0021] In one embodiment, when the load of the server node exceeds a first threshold, increasing the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure includes:
[0022] When the server node is in an unavailable state, a value is assigned to the server node to obtain a penalty score value of the server node, where the penalty score value is used to reduce the priority of the server node in the zset data structure;
[0023] When the load of the server node exceeds the first threshold, a second value is added to the score value of the server node to reduce the priority of the server node in the zset data structure;
[0024] The penalty score value is greater than the sum of the second value and the score value of the service node whose load exceeds the first threshold, and the second value is greater than the first value.
[0025] In one embodiment, the method further comprises:
[0026] When the final score value of the server node exceeds the second threshold, the score value of the server node is reset to obtain a reset score value of the server node, so as to increase the priority of the server node in the zset data structure.
[0027] In one embodiment, the method further comprises:
[0028] Performing real-time monitoring on the load condition of each server node in the zset data structure to obtain a monitoring result for characterizing the load condition of each server node;
[0029] The score value corresponding to each server node is dynamically adjusted according to the monitoring result, so as to perform adaptive server node allocation according to the dynamically adjusted server node score value.
[0030] The present invention also provides a polling load balancing device based on a zset data structure, the device comprising:
[0031] A service allocation request module, used to receive a service allocation request from a client through a load balancer, query a zset data structure from a Redis cluster through the load balancer, and allocate a server node according to a score value in the zset data structure;
[0032] A node score updating module, used to determine the plurality of server nodes in order of the score values in the zset data structure, and update the score value of each server node to characterize the load condition of the server node;
[0033] a priority updating module, configured to increase the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure when the load of the server node exceeds a first threshold;
[0034] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0035] The present invention also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the polling load balancing method based on the zset data structure as described above is implemented.
[0036] The present invention also provides a computer storage medium storing a computer program, wherein when the computer program is executed by a processor, the polling load balancing method based on the zset data structure as described above is implemented.
[0037] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the polling load balancing method based on the zset data structure as described above is implemented.
[0038] The above-mentioned polling load balancing method and device based on the zset data structure receives the service allocation request from the client through the load balancer, queries the zset data structure from the Redis cluster through the load balancer, and allocates the server node to the client according to the score value in the zset data structure, and then determines multiple server nodes in the order of the score value in the zset data structure, and updates the score value of each server node to characterize the load situation of the server node. When the load of the server node exceeds the set threshold, the score value of the corresponding server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure. Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load situation includes load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases. This method uses the characteristics of the zset data structure to dynamically allocate requests according to the real-time changes of the server load, thereby optimizing resource utilization and improving the flexibility of load balancing adjustment, thereby reducing operation and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 One of the flow charts of the polling load balancing method based on the zset data structure provided by the present invention;
[0041] Figure 2 A schematic diagram of the overall process of round-robin load balancing in a round-robin load balancing method based on a zset data structure in a specific embodiment provided by the present invention;
[0042] Figure 3 The second flowchart of the polling load balancing method based on the zset data structure provided by the present invention;
[0043] Figure 4 The third flowchart of the polling load balancing method based on the zset data structure provided by the present invention;
[0044] Figure 5 The fourth flowchart of the polling load balancing method based on the zset data structure provided by the present invention;
[0045] Figure 6 The fifth flowchart of the polling load balancing method based on the zset data structure provided by the present invention;
[0046] Figure 7 The sixth flowchart of the polling load balancing method based on the zset data structure provided by the present invention;
[0047] Figure 8 A schematic diagram of the structure of a polling load balancing device based on a zset data structure provided by the present invention;
[0048] Fig. 9 This is a diagram of the internal structure of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] Combine the following Figures 1 to 9 The present invention describes a polling load balancing method and device based on a zset data structure.
[0051] like Figure 1 As shown, in one embodiment, a polling load balancing method based on a zset data structure includes the following steps:
[0052] Step S110, receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating server nodes according to the score value in the zset data structure.
[0053] Specifically, the load balancing system receives a service allocation request from a client through a load balancer. After receiving the service allocation request from the client, the load balancer queries the server node in the zset data structure from the Redis cluster in response to the service allocation request, and allocates the corresponding server node to the client according to the score value in the zset data structure.
[0054] It should be noted that the server nodes with lower score values in the zset data structure are allocated to the clients with higher priority.
[0055] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0056] Step S120, determining multiple server nodes in order of the score values in the zset data structure, and updating the score value of each server node to represent the load condition of the server node.
[0057] Specifically, the load balancer determines multiple server nodes allocated in response to the service allocation request according to the order of the score values in the zset data structure, and updates the score value of each server node to represent the load conditions of the allocated server nodes and unallocated server nodes.
[0058] Step S130: when the load of the server node exceeds the first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure.
[0059] Specifically, when the load of a server node exceeds a set threshold, the load balancing system will increase the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure.
[0060] Combination Figure 2 As shown, in a specific embodiment, the polling load balancing method based on the zset data structure provided by the present invention stores the server node information in the zset data structure of the Redis cluster and performs load balancing distribution through an improved polling algorithm, thereby achieving efficient, flexible and scalable load balancing.
[0061] In this embodiment, the Redis cluster is used to store server node information and the zset data structure. The load balancer is responsible for receiving client requests and allocating requests according to the information in the zset data structure. The server node carries the server for actual business processing. In the zset data structure, the information of each server node includes: a node identifier (such as an IP address + port or a unique ID) and a score, where the score represents the weight or load status of the current node. The server nodes are sorted from low to high according to the score, and the lower the score, the higher the priority.
[0062] In this embodiment, information registration is performed after the service is started. The service unique ID can be set according to a unified rule, or it can be directly identified by its ip+port and other information, and a default score is assigned. The client initiates a service allocation request to the load balancer to obtain the corresponding server information allocated. After the load balancer receives the service allocation request from the client, it queries the zset data structure from the Redis cluster, obtains the server nodes according to the scores from low to high (zset sorting method), selects and allocates the server nodes in order, and updates the score of the server node (usually increases a fixed value, such as 1) to reflect its load increase. In the process of selecting a server, if it is found that the server is temporarily unavailable, the penalty score value is set to increase (such as half of the total number of server nodes), and the use priority of the unavailable server is shifted back to improve the efficiency of the subsequent selection of available servers. In addition, if the score of the server node exceeds the preset threshold, its score is reset to ensure that other nodes can be evenly allocated to subsequent service allocation requests.
[0063] In this embodiment, it is also necessary to continuously monitor the real-time load of each server node (such as CPU, memory, network, etc.), and then dynamically adjust the score of the corresponding node in the zset data structure according to the monitoring results, increase the score of the node with higher load, and reduce the score of the node with lower load, and finally, perform adaptive request allocation according to the dynamically adjusted score. After the client obtains the analyzed service node information from the load balancer, it sends the actual business request to the load balancer.
[0064] In this embodiment, the zset data structure, as an ordered set data structure, has efficient insertion, deletion and sorting functions, and is more suitable for processing scenarios that require dynamic adjustment of weights and priorities. The Redis cluster adopts a master-slave replication architecture, so that data can be synchronized between multiple nodes, ensuring high data availability. When a server node failure is detected in the load balancer or Redis cluster, the system can automatically switch to the backup server node to ensure that the service is not interrupted due to the failure. In addition, snapshots of memory data can be generated regularly and persisted to disk. In the event of a system failure, the snapshot can be used to restore to the most recent persistence state.
[0065] The above-mentioned polling load balancing method based on the zset data structure receives the service allocation request from the client through the load balancer, queries the zset data structure from the Redis cluster through the load balancer, obtains the server node according to the score value in the zset data structure, and then determines multiple server nodes in the order of the score value in the zset data structure, and updates the score value of each server node to characterize the load situation of the server node. When the load of the server node exceeds the set threshold, the score value of the corresponding server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure. Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load situation includes load increase and load reduction. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases. This method dynamically allocates requests according to the real-time changes of the server load by utilizing the characteristics of the zset data structure, thereby optimizing resource utilization and improving the flexibility of load balancing adjustment, thereby reducing operation and maintenance costs.
[0066] like Figure 3 As shown, in one embodiment, the polling load balancing method based on the zset data structure provided by the present invention receives a service allocation request from a client through a load balancer, queries the zset data structure from a Redis cluster through the load balancer, and allocates server nodes according to the score value in the zset data structure, which includes the following steps:
[0067] Step S310, storing multiple server nodes in the zset data structure in the Redis cluster, and assigning a value to each server node to obtain an initial score value of each server node.
[0068] Step S320: different identification information is set for each server node according to a set rule, so that different server nodes have unique node identifiers respectively.
[0069] Each server node has a unique node identifier, and multiple server nodes with different node identifiers have the same initial score value. The node identifier includes the IP address, port and ID name of the server node.
[0070] like Figure 4As shown, in one embodiment, the polling load balancing method based on the zset data structure provided by the present invention receives a service allocation request from a client through a load balancer, queries the zset data structure from a Redis cluster through the load balancer, and allocates server nodes according to the score value in the zset data structure, specifically including the following steps:
[0071] Step S112: receiving a service allocation request from the client through the load balancer, and the load balancer queries the server node from the zset data structure in the Redis cluster in response to the service allocation request.
[0072] Step S114: when multiple server nodes in the zset data structure have the same initial score value, one server node is selected from the multiple server nodes, and the first value is added to the initial score value of the selected server node.
[0073] The first value is a preset fixed value used to represent the load increase of the selected server node.
[0074] like Figure 5 As shown, in one embodiment, the polling load balancing method based on the zset data structure provided by the present invention receives a service allocation request from a client through a load balancer, queries the zset data structure from a Redis cluster through the load balancer, and allocates server nodes according to the score value in the zset data structure, and specifically includes the following steps:
[0075] Step S116, sorting the multiple server nodes in the zset data structure according to the final score value of each server node, to obtain a zset data structure of an ordered set of the multiple server nodes.
[0076] Step S118, in response to the service allocation request, the load balancer selects a server node with the smallest score value from the zset data structure.
[0077] like Figure 6 As shown, in one embodiment, the polling load balancing method based on the zset data structure provided by the present invention, when the load of the server node exceeds the first threshold, increases the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure, specifically comprising the following steps:
[0078] Step S132: when the server node is in an unavailable state, a value is assigned to the server node to obtain a penalty score value of the server node, and the penalty score value is used to reduce the priority of the server node in the zset data structure.
[0079] Step S134: when the load of the server node exceeds the first threshold, a second value is added to the score value of the server node to reduce the priority of the server node in the zset data structure.
[0080] The penalty score value is greater than the sum of the second value and the score value of the service node whose load exceeds the first threshold, and the second value is greater than the first value.
[0081] It should be noted that when the final score value of the server node exceeds the second threshold, the score value of the server node is reset to obtain the reset score value of the server node to increase the priority of the server node in the zset data structure and ensure that other server nodes can be evenly distributed to subsequent service allocation requests.
[0082] like Figure 7 As shown, in one embodiment, the polling load balancing method based on the zset data structure provided by the present invention further includes the following steps:
[0083] Step S710, monitor the load condition of each server node in the zset data structure in real time to obtain a monitoring result for characterizing the load condition of each server node.
[0084] Step S720: dynamically adjust the score value corresponding to each server node according to the monitoring result, so as to perform adaptive server node allocation according to the dynamically adjusted server node score value.
[0085] The polling load balancing device based on the zset data structure provided by the present invention is described below. The polling load balancing device based on the zset data structure described below and the polling load balancing method based on the zset data structure described above can correspond to each other.
[0086] like Figure 8 As shown, in one embodiment, a polling load balancing device based on a zset data structure includes a service allocation request module 810, a node score update module 820 and a priority update module 830.
[0087] The service allocation request module 810 is used to receive a service allocation request from a client through a load balancer, query a zset data structure from a Redis cluster through the load balancer, and allocate server nodes according to the score value in the zset data structure.
[0088] The node score updating module 820 is used to determine multiple server nodes according to the order of the score values in the zset data structure, and update the score value of each server node to represent the load condition of the server node.
[0089] The priority updating module 830 is used to increase the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure when the load of the server node exceeds a first threshold.
[0090] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0091] In this embodiment, the polling load balancing device based on the zset data structure provided by the present invention further includes a server node registration module, which is used to:
[0092] Multiple server nodes are stored in the zset data structure in the Redis cluster, and each server node is assigned a value to obtain an initial score value of each server node.
[0093] Different identification information is set for each server node according to the set rules, so that different server nodes have unique node identifiers respectively.
[0094] Each server node has a unique node identifier, and multiple server nodes with different node identifiers have the same initial score value. The node identifier includes the IP address, port and ID name of the server node.
[0095] In this embodiment, the polling load balancing device based on the zset data structure provided by the present invention, the service allocation request module 810 is specifically used for:
[0096] The load balancer receives a service allocation request from the client, and the load balancer queries the server node from the zset data structure in the Redis cluster in response to the service allocation request.
[0097] When multiple server nodes in the zset data structure have the same initial score value, one server node is selected from the multiple server nodes, and the first value is added to the initial score value of the selected server node.
[0098] The first value is a preset fixed value used to represent the load increase of the selected server node.
[0099] In this embodiment, in the polling load balancing device based on the zset data structure provided by the present invention, the service allocation request module 810 is further specifically used for:
[0100] The multiple server nodes in the zset data structure are sorted according to the final score value of each server node to obtain a zset data structure of an ordered set of the multiple server nodes.
[0101] In response to the service allocation request, the load balancer selects the server node with the smallest score value from the zset data structure.
[0102] In this embodiment, in the polling load balancing device based on the zset data structure provided by the present invention, the priority updating module 830 is specifically used for:
[0103] When a server node is in an unavailable state, a value is assigned to the server node to obtain a penalty score value of the server node. The penalty score value is used to reduce the priority of the server node in the zset data structure.
[0104] When the load of the server node exceeds the first threshold, a second value is added to the score value of the server node to reduce the priority of the server node in the zset data structure.
[0105] The penalty score value is greater than the sum of the second value and the score value of the service node whose load exceeds the first threshold, and the second value is greater than the first value.
[0106] In this embodiment, the polling load balancing device based on the zset data structure provided by the present invention further includes a score resetting module, which is used to:
[0107] When the final score value of the server node exceeds the second threshold, the score value of the server node is reset to obtain a reset score value of the server node, so as to increase the priority of the server node in the zset data structure.
[0108] In this embodiment, the polling load balancing device based on the zset data structure provided by the present invention further includes a load monitoring and dynamic adjustment module, which is used to:
[0109] The load condition of each server node in the zset data structure is monitored in real time to obtain a monitoring result for characterizing the load condition of each server node.
[0110] The score value corresponding to each server node is dynamically adjusted according to the monitoring result, so as to perform adaptive server node allocation according to the dynamically adjusted server node score value.
[0111] Fig. 9 An example of a physical structure diagram of an electronic device is shown. The electronic device may be a smart terminal, and its internal structure diagram may be as follows: Fig. 9As shown. The electronic device includes a processor, an internal memory and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a polling load balancing method based on a zset data structure is implemented, and the method includes:
[0112] Receive service allocation requests from clients through the load balancer, query the zset data structure from the Redis cluster through the load balancer, and allocate server nodes according to the score values in the zset data structure;
[0113] Determine multiple server nodes according to the order of the score values in the zset data structure, and update the score value of each server node to represent the load condition of the server node;
[0114] When the load of the server node exceeds the first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure;
[0115] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0116] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present invention, and does not constitute a limitation on the electronic device to which the scheme of the present invention is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0117] On the other hand, the present invention further provides a computer storage medium storing a computer program, which implements a polling load balancing method based on a zset data structure when executed by a processor, the method comprising:
[0118] Receive service allocation requests from clients through the load balancer, query the zset data structure from the Redis cluster through the load balancer, and allocate server nodes according to the score values in the zset data structure;
[0119] Determine multiple server nodes according to the order of the score values in the zset data structure, and update the score value of each server node to represent the load condition of the server node;
[0120] When the load of the server node exceeds the first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure;
[0121] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0122] In another aspect, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, a polling load balancing method based on a zset data structure is implemented, the method comprising:
[0123] Receive service allocation requests from clients through the load balancer, query the zset data structure from the Redis cluster through the load balancer, and allocate server nodes according to the score values in the zset data structure;
[0124] Determine multiple server nodes according to the order of the score values in the zset data structure, and update the score value of each server node to represent the load condition of the server node;
[0125] When the load of the server node exceeds the first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure;
[0126] Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
[0127] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory.
[0128] By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0129] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0130] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A polling load balancing method based on zset data structure, characterized in that: The method comprises: Receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating a server node according to a score value in the zset data structure; Determine the plurality of server nodes in order of the score values in the zset data structure, and update the score value of each server node to characterize the load condition of the server node; When the load of the server node exceeds a first threshold, the score value of the server node in the zset data structure is increased to reduce the priority of the server node in the zset data structure; Wherein, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node, and the load condition includes load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases; The process of receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating a server node according to a score value in the zset data structure, includes: The plurality of server nodes are stored in a zset data structure in the Redis cluster, and a value is assigned to each server node to obtain an initial score value of each server node; Different identification information is set for each server node according to a set rule, so that different server nodes have unique node identifiers respectively; Each server node has a unique node identifier, and multiple server nodes with different node identifiers have the same initial score value, and the node identifier includes the IP address, port and ID name of the server node; The receiving of the service allocation request from the client through the load balancer, querying the zset data structure from the Redis cluster through the load balancer, and allocating the server node according to the score value in the zset data structure, includes: Receiving a service allocation request from a client through the load balancer, and the load balancer querying a server node from a zset data structure in the Redis cluster in response to the service allocation request; When multiple server nodes in the zset data structure all have the same initial score value, one server node is selected from the multiple server nodes, and a first value is added to the initial score value of the selected server node; The first value is a preset fixed value, which is used to represent the load increase of the selected server node; The method further comprises: receiving a service allocation request from a client through a load balancer, querying a zset data structure from a Redis cluster through the load balancer, and allocating a server node according to a score value in the zset data structure; and Sort the multiple server nodes in the zset data structure according to the final score value of each server node to obtain the zset data structure of the ordered set of multiple server nodes; In response to the service allocation request, the load balancer selects a server node with a minimum score value from the zset data structure; When the load of the server node exceeds a first threshold, increasing the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure includes: When the server node is in an unavailable state, a value is assigned to the server node to obtain a penalty score value of the server node, where the penalty score value is used to reduce the priority of the server node in the zset data structure; When the load of the server node exceeds the first threshold, a second value is added to the score value of the server node to reduce the priority of the server node in the zset data structure; The penalty score value is greater than the sum of the second value and the score value of the service node whose load exceeds the first threshold, and the second value is greater than the first value.
2. The polling load balancing method based on the zset data structure according to claim 1 is characterized in that: The method further comprises: When the final score value of the server node exceeds the second threshold, the score value of the server node is reset to obtain a reset score value of the server node, so as to increase the priority of the server node in the zset data structure.
3. The polling load balancing method based on the zset data structure according to claim 2 is characterized in that: The method further comprises: Performing real-time monitoring on the load condition of each server node in the zset data structure to obtain a monitoring result for characterizing the load condition of each server node; The score value corresponding to each server node is dynamically adjusted according to the monitoring result, so as to perform adaptive server node allocation according to the dynamically adjusted server node score value.
4. A polling load balancing device based on zset data structure, characterized in that: The device is used to implement the polling load balancing method based on the zset data structure according to any one of claims 1 to 3, comprising: A service allocation request module, used to receive a service allocation request from a client through a load balancer, query a zset data structure from a Redis cluster through the load balancer, and allocate a server node according to a score value in the zset data structure; A node score updating module, used to determine the plurality of server nodes in order of the score values in the zset data structure, and update the score value of each server node to characterize the load condition of the server node; a priority updating module, configured to increase the score value of the server node in the zset data structure to reduce the priority of the server node in the zset data structure when the load of the server node exceeds a first threshold; Among them, each server node has a unique score value in the zset data structure, and the higher the score value, the lower the priority of the corresponding server node. The load conditions include load increase and load decrease. When the score value of the server node increases, the load of the server node increases, and when the score value of the server node decreases, the load of the server node decreases.
5. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.
6. A computer storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
A server load balancing method and a device which are dynamically adjusted
CN109104500A
Real-time database query method based on dynamic load balancing
CN112698941A