Distributed load balancing method

By dynamically binding service instances and messages and partitioning according to service node types, the problem of uneven load in distributed queues is solved, processing efficiency and fault tolerance are improved, load balancing and high system availability are achieved.

CN119311405APending Publication Date: 2025-01-14WUHAN FIBERHOME DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411331944.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

In a high concurrency environment, consumers in distributed queues have low load balancing efficiency and insufficient fault tolerance, making it difficult to effectively implement the existing technology.

Method used

By dynamically binding the service instance with messages in the queue, partitioning is divided according to the type of the service node, and partitioning of the service node is determined according to the type of the message to achieve load balancing. Specific methods include caching old partition information, monitoring service changes, publishing service partition changes according to the partition change table, and confirming the partition size based on the new partition information, ensuring that the same type of service node is allocated to the same partition.

Benefits of technology

It improves processing efficiency and fault tolerance of the system, realizes load balancing of message consumption, adapts to dynamic environment changes, and improves the usability and practical value of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311405A_ABST
    Figure CN119311405A_ABST
Patent Text Reader

Abstract

The invention provides a distributed load balancing method, which comprises the following steps of: dividing partitions of service nodes according to the types of the service nodes; the type represents a function type in the system; for a target message in the message queue, according to the type of the target message, determining a partition of a service node so as to determine a current service node; and after processing the message, the current service node returns the message to the message node. According to the method and the device, the partitions in charge of the service instances are redistributed, so that load balance of message consumption is realized, and the message consumption performance of the server is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of distributed cluster load balancing, and more specifically to a distributed load balancing method. Background Art

[0002] With the widespread application of distributed systems, distributed queues have been widely adopted as an important message delivery method. However, in a high-concurrency environment, how to effectively achieve load balancing of consumers in distributed queues has become a challenge. The current load balancing methods have problems such as low efficiency and insufficient fault tolerance. Summary of the invention

[0003] In view of the above problems, the present disclosure provides a distributed load balancing method for dynamically binding a service instance with a message in a queue.

[0004] The present disclosure provides a distributed load balancing method, including: dividing the service node into partitions according to the type of the service node; the type represents the function type in the system; for a target message in a message queue, according to the type of the target message, determining the partition of the service node for determining the current service node; after the current service node processes the message, returning the message to the message node.

[0005] According to an embodiment of the present disclosure, partitions of service nodes are divided according to the types of service nodes, including: in response to successful registration of a preset number of service nodes, old partition information is cached, and all service nodes are added to a service node queue; the partition information includes a key-value pair of the service; the key-value pair is used to characterize the service type and the service data structure; for each service node in the service node queue, partitions of the service nodes are allocated according to the type of the service node so that service nodes of the same type are allocated to the same partition.

[0006] According to an embodiment of the present disclosure, for each service node in the service node queue, a partition of the service node is allocated according to the type of the service node so that service nodes of the same type are allocated to the same partition, including: for each service node in the service node queue, according to the type of the service node, a key-value pair of a new partition is confirmed; the key-value pair of the old partition information is compared with the key-value pair of the new partition, and in response to a change in the key-value pair, the service and the key-value pair are recorded in a partition change table; and the service partition change is published according to the partition change table.

[0007] According to an embodiment of the present disclosure, caching old partition information also includes: monitoring service changes based on a distributed cluster.

[0008] According to an embodiment of the present disclosure, the service partition change is published according to the partition change table, and before that, the process also includes: confirming the size of the new partition according to the new partition information.

[0009] According to an embodiment of the present disclosure, for a target message in a message queue, a partition of a service node is determined according to the type of the target message in order to determine a current service node, including: taking the first message in the message queue as the current message; taking the first service node of each partition as the partition service node; determining the current partition according to the type of the current message; taking the partition service node as the current service node; selecting another service node of the current partition as the partition service node; and in response to the existence of a next message, repeating the step of determining the current partition according to the type of the current message.

[0010] According to an embodiment of the present disclosure, selecting another service node of the current partition as the partition service node includes: determining whether there is a next service node in the current partition; if so, selecting the next service node as the partition service node; if not, selecting the first service node as the partition service node.

[0011] The second aspect of the present disclosure provides a distributed load balancing device that can be used to implement the above method, including: a service partitioning module, used to divide the service node into partitions according to the type of the service node; the type represents the function type in the system; a message processing module, used to determine the partition of the service node for determining the current service node according to the type of the target message in the message queue; after the current service node processes the message, it returns the message to the message node.

[0012] The third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the above-mentioned distributed load balancing method.

[0013] The fourth aspect of the present disclosure further provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the above-mentioned distributed load balancing method.

[0014] According to the distributed load balancing method provided by the present disclosure, after the service nodes are partitioned according to type, the message selects the service node according to the load in the same type partition. Since the service node is dynamically bound to the message in the queue, the technical problem of uneven load in the distributed cluster is at least partially solved, and the technical effect of improving processing efficiency and balancing the consumer load is achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A flowchart of a distributed load balancing method according to an embodiment of the present disclosure is schematically shown;

[0016] Figure 2A flowchart schematically illustrates a service partition according to an embodiment of the present disclosure;

[0017] Figure 3 The structure block diagram of the distributed load balancing device according to the embodiment of the present disclosure is schematically shown;

[0018] Figure 4 A block diagram of an electronic device suitable for implementing a distributed load balancing method according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0019] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.

[0020] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0021] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.

[0022] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0023] First, the technical terms involved in this disclosure are explained as follows:

[0024] Message Queues: Use message queue systems (such as RabbitMQ and Kafka) to store and distribute messages. Service instances pull messages from the queue, process them, and then return or store the results.

[0025] Service Node: A service node usually provides a specific service type. The service type can represent the division of different functions or responsibilities in the system, such as business logic processing, message queue processing, API gateway, etc. The data structure is used to maintain the service node responsible for processing certain tasks or partitions in each service type.

[0026] Key-Value Pair: Key-Value Pair is a concept often used in computer science, especially when dealing with data storage, databases, programming, and configuration files. A key-value pair consists of two main parts: key and value. Key: It is a unique identifier used to quickly find and access the data associated with it. The key must be unique in a collection or database table so that the corresponding value can be accurately located and retrieved. The key can be of any data type, but strings, integers, or composite keys (such as a combination of multiple fields) are usually used as keys to simplify processing and queries. Value: It is the data item associated with the key. A key can correspond to one or more values ​​(depending on the specific application scenario and data structure). The value can be of any data type, including numbers, strings, lists, objects, etc. The value stores the specific information or data associated with the key. A key-value pair refers to a key = service type, and a value = service node. There are multiple service nodes under one type.

[0027] Figure 1 The following schematically shows a flow chart of a distributed load balancing method according to an embodiment of the present disclosure. Figure 1 As shown, an embodiment of the present disclosure provides a distributed load balancing method, including: dividing the service node into partitions according to the type of the service node; the type represents the function type in the system; for the target message in the message queue, according to the type of the target message, determining the partition of the service node to determine the current service node; after the current service node processes the message, the message is returned to the message node.

[0028] Through the embodiments of the present invention, a method for queue consumer load balancing based on a distributed cluster is provided, which realizes the redistribution of partitions that each service instance is responsible for, and utilizes distributed cluster technology to dynamically bind service instances to messages in the queue, so that processing tasks can be more effectively allocated according to message types, and at the same time, load balancing of message consumption can be achieved, the server message consumption performance can be improved, and the dynamic environmental changes in the system can be better adapted, the fault tolerance and availability of the system can be improved, and it has a high practical value in distributed systems.

[0029] On the basis of the above embodiment, partitions of service nodes are divided according to the types of service nodes, including: in response to successful registration of a preset number of service nodes, old partition information is cached, and all service nodes are added to a service node queue; the partition information includes a key-value pair of the service; the key-value pair is used to characterize the service type and the service data structure; for each service node in the service node queue, partitions of the service node are allocated according to the type of the service node so that service nodes of the same type are allocated to the same partition.

[0030] Figure 2 A flowchart of service partitioning according to an embodiment of the present disclosure is schematically shown. Figure 2 As shown, the following steps are included: based on the distributed cluster, service registration, monitoring service changes, service deregistration and other functions are implemented to discover distributed service nodes, manage and update service node partitions in the distributed system; when a new service is successfully registered, the data structure of the existing service type and responsible service is cleared, and the current service and other services are all added to the queue, a unique identifier is assigned to the service instance, the existing data structure is cleaned up and the service is initialized to ensure that the service information is the latest and new partitions are assigned; new partitions are assigned, and according to the circular queue sharding, the appropriate service instance is selected in the service list, and the service instance of each service type is added to the corresponding queue, and the service instances are sorted according to the service ID; according to the partition size in the queue, the new partition of each queue is calculated, and the partition is assigned to the service instance through looping and indexing, so as to achieve message load balancing; compare the new and old partition allocation information, find out the queue keys that have changed in the new partition allocation, and record the new partition information corresponding to these keys; sort the changed partitions by service type, and finally publish the service list change event.

[0031] In this embodiment, after the original partition set is cleared, the current service and other services will be added to the partition set, and each service type will be stored in the corresponding key-value pair. After the allocation, they will be sorted according to the service ID. In this way, the traversal is orderly.

[0032] Through the embodiments of the present disclosure, after a preset number of service nodes are successfully registered, the old partition information is cached and the new nodes are added to the service node queue. Then, partitions are allocated according to the node type to ensure that service nodes of the same type are allocated to the same partition, which facilitates subsequent message distribution and processing. By responding to service and partition changes, the system can dynamically adjust the load to ensure that each service instance can handle relatively balanced message traffic.

[0033] Based on the above embodiment, for each service node in the service node queue, according to the type of the service node, the partition of the service node is allocated to allocate service nodes of the same type to the same partition, including: for each service node in the service node queue, according to the type of the service node, confirming the key-value pair of the new partition; comparing the key-value pair of the old partition information with the key-value pair of the new partition, and in response to changes in the key-value pair, recording the service and the key-value pair to the partition change table; publishing the service partition change according to the partition change table.

[0034] Through the embodiments of the present disclosure, the partition change table is generated to centrally process the changes of the same type of services. This enables the partition changes of each service type to be processed and published separately, avoids the mixing of changes of different service types, and simplifies the publishing and processing of change events.

[0035] On the basis of the above embodiment, the old partition information is cached, and the process also includes: monitoring service changes based on a distributed cluster.

[0036] In this embodiment, based on the service node discovery of the distributed cluster, the service node partitions in the distributed system are managed and updated, new partition allocations are calculated based on the partition size and queue key, the changed partitions are sorted by service type and partition change events are published to achieve load balancing of the service consumption queue.

[0037] Through the embodiments of the present disclosure, service changes in the distributed cluster are monitored before caching old partition information, ensuring that the system can perceive the increase, decrease or type change of service nodes in real time, so as to adjust the partition strategy in time.

[0038] Based on the above embodiment, the service partition change is published according to the partition change table, which also includes: confirming the size of the new partition according to the new partition information.

[0039] The embodiments of the present disclosure help the system optimize resource allocation and ensure that each partition has sufficient resources to process the allocated messages.

[0040] On the basis of the above embodiment, for the target message in the message queue, according to the type of the target message, the partition of the service node is determined for determining the current service node, including: taking the first message in the message queue as the current message; taking the first service node of each partition as the partition service node; determining the current partition according to the type of the current message; taking the partition service node as the current service node; selecting another service node in the current partition as the partition service node; and in response to the existence of the next message, repeating the step of determining the current partition according to the type of the current message.

[0041] In this embodiment, when a message is received, the service partition is found according to the message type, and then the next idle node in the partition is selected to process the message.

[0042] Through the embodiments of the present disclosure, by traversing the message queue and assigning the message to the corresponding partition and service node according to the message type, the messages in the queue are assigned to different service instances according to certain rules, ensuring that each service instance can handle relatively balanced message traffic. According to the load of the service instance and the system resource status, the message distribution strategy is dynamically adjusted to achieve load balancing of the service node.

[0043] Based on the above embodiment, selecting another service node of the current partition as the partition service node includes: determining whether there is a next service node in the current partition; if so, selecting the next service node as the partition service node; if not, selecting the first service node as the partition service node.

[0044] Through the embodiments of the present disclosure, service nodes of the same type are allocated cyclically to achieve load balancing within a partition, thereby avoiding overloading of a single service node.

[0045] Based on the above-mentioned distributed load balancing method, the present disclosure also provides a distributed load balancing device, which can be used to implement the above-mentioned method. Figure 3 The device is described in detail.

[0046] like Figure 3 As shown, the distributed load balancing device of this embodiment includes a service partitioning module and a message processing module.

[0047] The service partitioning module is used to partition the service node according to the type of the service node; the type indicates the function type in the system. In one embodiment, the message processing module can be used to perform the operation S1 described above, which will not be repeated here.

[0048] The message processing module is used to determine the partition of the service node for determining the current service node according to the type of the target message in the message queue; after the current service node processes the message, it returns the message to the message node. In one embodiment, the message processing module can be used to perform the operations S2 to S3 described above, which will not be repeated here.

[0049] Figure 4 A block diagram of an electronic device suitable for implementing a distributed load balancing method according to an embodiment of the present disclosure is schematically shown.

[0050] like Figure 4As shown, the electronic device 400 according to an embodiment of the present disclosure includes a processor 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 to a random access memory (RAM) 403. The processor 401 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 401 may also include an onboard memory for caching purposes. The processor 401 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.

[0051] In RAM403, various programs and data required for the operation of electronic device 400 are stored. Processor 401, ROM402 and RAM 403 are connected to each other through bus 404. Processor 401 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 402 and / or RAM 403. It should be noted that the program can also be stored in one or more memories other than ROM402 and RAM 403. Processor 401 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.

[0052] According to an embodiment of the present disclosure, the electronic device 400 may further include an input / output (I / O) interface 405, which is also connected to the bus 404. The electronic device 400 may further include one or more of the following components connected to the I / O interface 405: an input portion 406 including a keyboard, a mouse, etc.; an output portion 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 408 including a hard disk, etc.; and a communication portion 409 including a network interface card such as a LAN card, a modem, etc. The communication portion 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage portion 408 as needed.

[0053] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.

[0054] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the method provided by the embodiment of the present disclosure.

[0055] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).

[0056] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0057] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.

[0058] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.

Claims

1. A distributed load balancing method, characterized in that: include: Divide the service nodes into partitions according to the types of service nodes; The type represents the type of function in the system; For the target message in the message queue, the partition of the service node is determined according to the type of the target message to determine the current service node, so that the current service node can process the message and then return the message to the message node.

2. The method according to claim 1, wherein: The service nodes are divided into partitions according to the type of service nodes, including: In response to a preset number of service nodes successfully registering, old partition information is cached, and all service nodes are added to a service node queue; the partition information includes a key-value pair of a service; the key-value pair is used to characterize a service type and a service data structure; For each service node in the service node queue, a partition of the service node is allocated according to the type of the service node so that service nodes of the same type are allocated to the same partition.

3. The method according to claim 2, wherein: For each service node in the service node queue, according to the type of the service node, a partition of the service node is allocated so that service nodes of the same type are allocated to the same partition, including: For each service node in the service node queue, confirm the key-value pair of the new partition according to the type of the service node; compare the key-value pair of the old partition information with the key-value pair of the new partition, and in response to a change in the key-value pair, record the service and the key-value pair in the partition change table; The service partition change is published according to the partition change table.

4. The method according to claim 2, wherein: Cache old partition information, previously also included: Based on distributed clusters, monitor service changes.

5. The method according to claim 3, wherein: The step of publishing the service partition change according to the partition change table further includes: According to the new partition information, confirm the size of the new partition.

6. The method according to claim 1, wherein: For a target message in a message queue, determining a partition of a service node according to a type of the target message to determine a current service node includes: The first message in the message queue is used as the current message; the first service node in each partition is used as the partition service node; Determine the current partition according to the type of the current message; use the partition service node as the current service node; select another service node of the current partition as the partition service node; In response to the existence of the next message, the step of determining the current partition according to the type of the current message is repeated.

7. The method according to claim 1, wherein: Select another service node in the current partition as the partition service node, including: Determine whether there is a next service node in the current partition; If yes, select the next service node as the partition service node; If not, the first service node is selected as the partition service node.

8. A distributed load balancing device, characterized in that: The device can be used to implement the method according to any one of claims 1 to 7, and the device comprises: A service partitioning module, used to divide the service nodes into partitions according to the type of the service nodes; the type indicates the function type in the system; The message processing module is used to determine the partition of the service node according to the type of the target message in the message queue to determine the current service node, so that the current service node can process the message and then return the message to the message node.

9. An electronic device, comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to execute the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the method according to any one of claims 1 to 7.