Micro-service load balancing method and device, computer equipment and storage medium

The dynamic programming algorithm is used to align microservice instances and subtask loads, solving the problem of microservice load imbalance, achieving load balancing and resource optimization, and improving task processing efficiency.

CN118656209AActive Publication Date: 2024-09-17SHENZHEN INST OF ADVANCED TECH CHINESE ACAD OF SCI
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410773161.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-17
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

The load imbalance of microservice instances in the existing technology leads to resource waste and reduced task execution efficiency, and random scheduling methods cannot effectively achieve load balancing.

Method used

Using a sequence alignment algorithm based on dynamic programming, the cumulative load and subtask load of microservice instances are regarded as a circular sequence, and the alignment is performed to minimize the maximum load value and maintain the successor relationship of subtasks to realize the load between microservice instances. balanced.

Benefits of technology

It effectively maintains load balancing in the microservice scheduling process, optimizes resource utilization, improves task throughput and processing efficiency, and saves time overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656209A
    Figure CN118656209A
Patent Text Reader

Abstract

The invention relates to a micro-service load balancing method and device, computer equipment and a storage medium. The method comprises the steps of obtaining a micro-service task, performing sub-task division on the micro-service task according to the number of micro-service instances in a current system, and putting all the sub-tasks into the same batch in an annular organization manner; the method comprises the following steps: respectively acquiring an accumulated load of each micro-service instance in a current system and a load of each sub-task in a batch, taking the accumulated load and the load of each sub-task in the batch as two annular sequences, and aligning the two annular sequences by adopting a sequence alignment algorithm based on dynamic programming, the maximum load value in all the micro-service instances is minimum; and based on an alignment result of the two annular sequences, allocating each sub-task in the batch to the micro-service instance, so that the relaying relation of the sub-tasks allocated to the micro-service instance is kept unchanged. According to the embodiment of the invention, a better load balancing effect can be maintained, the resource utilization rate is optimized, and the task processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the technical field of resource scheduling, and in particular, relates to a microservice load balancing method, apparatus, computer equipment, and storage medium. Background Art

[0002] To optimize system performance and resource utilization, load balancing is a key technology across many fields. With the popularity of microservice architecture, the functional modules of applications are gradually split into independent microservice units, providing a more flexible, maintainable and scalable software development and deployment model. However, microservices also bring new challenges, one of which is how to effectively manage and balance the load of microservice instances.

[0003] In this context, a pattern has emerged to distribute a single microservice to multiple microservice instances through batch scheduling to achieve distributed execution, as shown in the following example. Figure 1 As shown, it is a schematic diagram of the microservice allocation mode of the prior art. In this mode, the unit of a scheduling is a batch, and a batch contains multiple microservice subtasks. Deploying multiple microservice instances can provide fault tolerance, improve service availability, and improve the concurrency and overall processing capacity of tasks. When multiple microservice instances are deployed in a ring manner, and there is also a ring communication relationship between the subtasks scheduled in a batch, the succession relationship of each subtask in the batch should be kept unchanged during the allocation process. This way of keeping the order between subtasks is very important for reducing communication overhead and improving overall execution efficiency. With the widespread application of this batch scheduling method, load balancing of multiple microservice instances has become an urgent problem to be solved. For this problem, the current random scheduling method randomly selects microservice instances with the same number of batch subtasks, randomly selects the starting point of the batch subtask, and then allocates the batch subtasks to the selected microservice instances accordingly, so as to realize the scheduling function. However, the random scheduling method cannot achieve load balancing between microservice instances, and has the following shortcomings:

[0004] First, some microservice instances may be idle due to insufficient load, while other microservice instances are overloaded, resulting in a waste of server resources.

[0005] Second, since the final completion time of a task is determined by the last completed subtask, and uneven load will cause the completion time of some subtasks to be delayed, it will affect the execution efficiency of the task. Summary of the invention

[0006] The present application provides a microservice load balancing method, apparatus, computer device, and storage medium, which aim to solve at least one of the above-mentioned technical problems in the prior art to a certain extent.

[0007] In order to solve the above problems, this application provides the following technical solutions:

[0008] A microservice load balancing method, comprising:

[0009] Obtain a microservice task, divide the microservice task into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape;

[0010] The cumulative load of each microservice instance in the current system and the load of each subtask in the batch are obtained respectively, and the cumulative load and the load of each subtask in the batch are used as two circular sequences, and the two circular sequences are aligned by a sequence alignment algorithm based on dynamic programming so that the maximum "load value" of all microservice instances is minimized;

[0011] Based on the alignment result of the two ring sequences, each subtask in the batch is allocated to a microservice instance, so that the succession relationship of the subtasks allocated to the microservice instance remains unchanged.

[0012] The technical solution adopted by the embodiment of the present application also includes: before obtaining the microservice task, it also includes:

[0013] The number of microservice instances in the current system is obtained; wherein the number of the microservice instances is m, and the m microservice instances are deployed in a ring manner.

[0014] The technical solution adopted by the embodiment of the present application also includes: dividing the microservice task into subtasks according to the number of microservice instances in the current system, specifically:

[0015] The number of subtask divisions of the microservice task is less than or equal to the number m of microservice instances in the current system.

[0016] The technical solution adopted by the embodiment of the present application also includes: respectively obtaining the cumulative load of each microservice instance in the current system and the load of each subtask in the batch, and taking the cumulative load and the load of each subtask in the batch as two ring sequences, and further including:

[0017] The elements in the two ring sequences S1 and S2 are put into a ring in order, and the number of positions on the ring is the same as the number of microservice instances in the current system.

[0018] The technical solution adopted in the embodiment of the present application also includes: the two circular sequences are aligned using a sequence alignment algorithm based on dynamic programming, specifically:

[0019] Without changing the successor relationship of sequence elements and under the condition that the length of the merged sequence is not greater than the number of microservice instances, a sequence alignment algorithm based on dynamic programming is used to align the two ring sequences S1 and S2 at m positions, and then the corresponding elements in the aligned two ring sequences S1 and S2 are merged to obtain a new load sequence S3, so that the maximum "load value" among all microservice instances is minimized.

[0020] The technical solution adopted in the embodiment of the present application also includes: the two circular sequences are aligned using a sequence alignment algorithm based on dynamic programming, specifically:

[0021] Initialize the dynamic programming array S as a four-dimensional array, S i,j (p, q) records the maximum sum of the corresponding elements in the current two ring sequences, and implies that the algorithm proceeds to the i-th element of S1 and the j-th element of S2, which are represented by a respectively. i and b i , and S1 has used p gaps, and S2 has used q gaps, then the dynamic transfer equation is:

[0022]

[0023] The parameters i, j, p, q in the above formula satisfy the following constraints:

[0024]

[0025] Where |S1| and |S2| represent the number of elements of the two ring sequences S1 and S2, respectively; the inequalities represent the index ranges of the elements or available gaps of the two ring sequences, respectively; and the equality represents that the elements or gaps of S1 and S2 correspond to each other;

[0026] When we start running the sequence alignment algorithm, we first calculate the starting point of the dynamic programming process:

[0027]

[0028] Among them, the first equation means that both S1 and S2 are aligned using gaps, the second and third equations mean that one sequence of S1 and S2 is aligned using gaps and the other sequence is aligned using elements, the fourth equation means that both S1 and S2 are aligned using elements, and the parameter χ is all possible values ​​that satisfy the conditional constraints.

[0029] The technical solution adopted by the embodiment of the present application also includes: allocating each subtask in the batch to a microservice instance based on the alignment result of the two ring sequences, specifically:

[0030] The subtasks in the batch are passed to the task adjustment area. In the initial stage of the system, if the number of microservice instances involved in the allocation plan is less than the number of microservice instances in the current system, the subtasks in the batch are cached in the task adjustment area, and then the subtasks organized in a ring are allocated to the microservice instances deployed in a ring through the scheduler, and the preceding and succeeding subtasks of each subtask in the batch remain unchanged after being allocated to the microservice instance.

[0031] Another technical solution adopted by the embodiment of the present application is: a microservice load balancing device, comprising:

[0032] Microservice partitioning module: used to obtain microservice tasks, divide the microservice tasks into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape;

[0033] Sequence alignment module: used to obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the batch, respectively, take the cumulative load and the load of each subtask in the batch as two circular sequences, and align the two circular sequences using a sequence alignment algorithm based on dynamic programming, so that the maximum "load value" in all microservice instances is minimized;

[0034] Task allocation module: used for allocating each subtask in the batch to a microservice instance based on the alignment result of the two ring sequences, so that the succession relationship of the subtasks allocated to the microservice instance remains unchanged.

[0035] Another technical solution adopted by the embodiment of the present application is: a computer device, the computer device includes a processor and a memory coupled to the processor, wherein:

[0036] The memory stores program instructions for implementing the microservice load balancing method;

[0037] The processor is used to execute the program instructions stored in the memory to control the microservice load balancing method.

[0038] Another technical solution adopted by the embodiment of the present application is: a storage medium storing program instructions executable by a processor, wherein the program instructions are used to execute the microservice load balancing method.

[0039] Compared with the prior art, the beneficial effects of the embodiments of the present application are as follows: the microservice load balancing method, device, computer equipment and storage medium of the embodiments of the present application propose a sequence alignment algorithm based on dynamic programming, which regards the cumulative load of each microservice instance in the current system and the subtask load of the same batch as two ring sequences, and puts the elements in the two ring sequences into a ring in an orderly manner. Under the condition that the successor relationship of the ring sequence elements is not changed and the length of the merged sequence is not greater than the number of microservice instances, the alignment of the two ring sequences is achieved, so that the maximum "load value" in all microservice instances is minimized, and finally, based on the alignment result, the batch subtasks organized in a ring are scheduled to the microservice instances deployed in a ring, so as to achieve load balancing of microservices. The embodiments of the present application can maintain a good load balancing effect in the microservice scheduling process. For the server, it optimizes resource utilization and improves task throughput. For the served end, it improves task processing efficiency and saves time overhead. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 A schematic diagram of a microservice allocation model in the prior art;

[0041] Figure 2 is a flow chart of a microservice load balancing method according to an embodiment of the present application;

[0042] Figure 3 A schematic diagram of circular sequence alignment and merging according to an embodiment of the present application;

[0043] Figure 4 A pseudo code diagram of a sequence alignment algorithm according to an embodiment of the present application;

[0044] Figure 5 A schematic diagram of the microservice scheduling simulation experiment results of an embodiment of the present application;

[0045] Figure 6 This is a schematic diagram of the structure of a microservice load balancing device according to an embodiment of the present application;

[0046] Figure 7 A schematic diagram of the computer device structure of an embodiment of the present application;

[0047] Figure 8 A schematic diagram of the structure of a storage medium according to an embodiment of the present application. DETAILED DESCRIPTION

[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0049] The terms "first", "second", "third" in this application are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first", "second", "third" can expressly or implicitly include at least one of the features. In the description of this application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. In the embodiments of this application, all directional indications (such as up, down, left, right, front, back...) are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication also changes accordingly. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or computer device that includes a series of steps or units is not limited to the steps or units listed, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or computer devices.

[0050] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0051] Specifically, see Figure 2 , is a flow chart of the microservice load balancing method of the embodiment of the present application. The microservice load balancing method of the embodiment of the present application comprises the following steps:

[0052] S100: Get the number of microservice instances in the current system;

[0053] In this step, the number of microservice instances is m, and the m microservice instances are deployed in a ring manner.

[0054] S110: Obtain microservice tasks, divide a single microservice task into subtasks according to the number of microservice instances, and organize all subtasks of a single microservice task into the same batch in a ring-like manner. Inside;

[0055] In this step, the number of subtasks divided into a single microservice task is less than or equal to the number m of microservice instances in the current system.

[0056] S120: respectively obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the current batch, use the cumulative load and the load of each subtask in the current batch as two ring sequences S1 and S2, and put the elements in the two ring sequences S1 and S2 into a ring in order;

[0057] In this step, the number of positions on the ring is the same as the number of microservice instances in the current system, that is, it includes m positions.

[0058] S130: Use a sequence alignment algorithm based on dynamic programming to align the two ring sequences S1 and S2, and merge the corresponding elements in the aligned two ring sequences S1 and S2 to generate a new load sequence S3, and the new load sequence S3 can minimize the maximum "load value" of all microservice instances;

[0059] In this step, when scheduling all batches of subtasks, the idea of ​​iterative merging is adopted, and the local optimal merge is greedily achieved at each step, that is, to ensure that the scheduling of each batch of subtasks is the current optimal solution. By considering the cumulative load of each microservice instance in the current system and the load of each subtask in the current batch as two circular sequences S1 and S2, the elements in the two circular sequences S1 and S2 are orderly placed in a ring with m positions, and the two circular sequences are aligned at m positions without changing the successor relationship of the elements and under the condition that the length of the merged sequence is not greater than the number of microservice instances. Finally, the corresponding elements in the two aligned circular sequences are merged to obtain a new load sequence S3, which minimizes the maximum "load value" among all microservice instances. Specifically, Figure 3 , which is a schematic diagram of circular sequence alignment and merging according to an embodiment of the present application, wherein there may be gaps between any adjacent elements of the same circular sequence.

[0060] Specifically, for the alignment of two circular sequences, S1 is used as a normal fixed sequence during the execution process, and the starting element of S2 is looped, thereby converting it into the alignment of two non-circular sequences. It should be noted that the alignment scheme that obtains the optimal solution may not be unique. In order to better balance the load, it is necessary to find a solution with the smallest maximum "load difference" of each microservice instance among multiple optimal alignment schemes. The embodiment of the present application proposes a sequence alignment algorithm based on dynamic programming. The specific algorithm is: initialize the dynamic programming array S as a four-dimensional array, S i,j (p, q) records the maximum sum of the corresponding elements in the current two ring sequences, and implies that the algorithm proceeds to the i-th element of S1 (using a i denoted by b), the jth element of S2 (denoted by b i ), and S1 has used p gaps, and S2 has used q gaps, then the dynamic transfer equation is:

[0061]

[0062] The parameters i, j, p, q in the above formula are not independent and should satisfy the following constraints:

[0063]

[0064] Among them, |S1| and |S2| represent the number of elements of the two ring sequences S1 and S2 respectively, the inequalities represent the index ranges of the elements or available gaps of the two ring sequences respectively, and the equality indicates that the elements or gaps of S1 and S2 correspond to each other.

[0065] When we start running the sequence alignment algorithm, we first calculate the boundary conditions, which are the starting point (basecase) of the dynamic programming process:

[0066]

[0067] The first equation indicates that both S1 and S2 are aligned using gaps, the second and third equations indicate that one of the sequences in S1 and S2 is aligned using gaps and the other sequence is aligned using elements, and the fourth equation indicates that both S1 and S2 are aligned using elements. The parameter χ is all possible values ​​that satisfy the conditional constraints. The pseudo code of the sequence alignment algorithm based on dynamic programming is as follows: Figure 4 shown.

[0068] S140: Based on the sequence alignment results, the same batch is sent through the scheduler The batch subtasks organized in a ring are assigned to the microservice instances deployed in a ring, so that the succession relationship of the batch subtasks assigned to the microservice instances remains unchanged;

[0069] In this step, at the initial stage of the system, if the number of microservice instances involved in the allocation plan is less than the number of microservice instances in the current system, the system does not perform actual scheduling operations, but caches the subtasks in the batch in the task adjustment area, and then allocates the batch subtasks organized in a ring to the microservice instances deployed in a ring through the scheduler. The preceding and succeeding subtasks of the subtasks in the same batch remain unchanged after being allocated to the microservice instances, thereby achieving load balancing of microservices and giving full play to the advantages of the sequence alignment algorithm, which is conducive to improving the flexibility of subtask adjustment.

[0070] In order to verify the feasibility and effectiveness of the embodiments of the present application, a simulation experiment is used for comparative verification. In the simulation experiment, it is assumed that there are 10 microservice instances, the number of subtasks and the load in each batch are integers, the number of subtasks in each batch is randomly generated from a discrete uniform distribution of 1 to 10, and the subtask load is randomly generated from a discrete uniform distribution of 1 to 10000. For the convenience of analysis, the average load value of the current total load evenly distributed to all microservice instances is taken as an ideal value. By analyzing the ratio of the experimental results to the ideal value, the effectiveness of the embodiments of the present application can be more intuitively felt. The results of the microservice scheduling simulation experiment are shown in the figure. Figure 5 As shown, the ordinate in the figure is the ratio of the simulation experiment result to the ideal value, the abscissa is the number of scheduled batches, the upper line is the operation result of the random scheduling algorithm, and the lower line is the operation result of the algorithm proposed in the embodiment of the present application. The experimental results show that the embodiment of the present application can maintain a better load balancing effect during the scheduling process.

[0071] Based on the above, the microservice load balancing method of the embodiment of the present application proposes a sequence alignment algorithm based on dynamic programming, which regards the cumulative load of each microservice instance in the current system and the subtask load of the same batch as two circular sequences, and puts the elements in the two circular sequences into a ring in order. Under the condition that the successor relationship of the circular sequence elements is not changed and the length of the merged sequence is not greater than the number of microservice instances, the two circular sequences are aligned to minimize the maximum "load value" in all microservice instances. Finally, based on the alignment result, the batch subtasks organized in a ring are scheduled to the microservice instances deployed in a ring to achieve load balancing of microservices. The embodiment of the present application can maintain a good load balancing effect during the microservice scheduling process. For the server, it optimizes resource utilization and improves task throughput. For the serviced end, it improves task processing efficiency and saves time overhead.

[0072] See also Figure 6 , is a schematic diagram of the structure of a microservice load balancing device in an embodiment of the present application. The microservice load balancing device 40 in an embodiment of the present application includes:

[0073] Microservice partitioning module 41: used to obtain microservice tasks, divide the microservice tasks into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape;

[0074] The sequence alignment module 42 is used to obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the batch, respectively, take the cumulative load and the load of each subtask in the batch as two circular sequences, and align the two circular sequences using a sequence alignment algorithm based on dynamic programming, so that the maximum "load value" in all microservice instances is minimized;

[0075] The task allocation module 43 is used to allocate each subtask in the batch to the microservice instance based on the alignment result of the two ring sequences, so that the succession relationship of the subtasks allocated to the microservice instance remains unchanged.

[0076] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0077] The device provided in the embodiment of the present application can be applied in the aforementioned method embodiment. For details, please refer to the description of the aforementioned method embodiment, which will not be repeated here.

[0078] See also Figure 7 , is a schematic diagram of the computer device structure of an embodiment of the present application. The computer device 50 includes:

[0079] A memory 51 storing executable program instructions;

[0080] A processor 52 connected to the memory 51;

[0081] The processor 52 is used to call the executable program instructions stored in the memory 51 and perform the following steps: obtain the microservice task, divide the microservice task into subtasks according to the number of microservice instances in the current system, and organize all the subtasks into the same batch in a circular manner; obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the batch respectively, use the cumulative load and the load of each subtask in the batch as two circular sequences, and use the sequence alignment algorithm based on dynamic programming to align the two circular sequences so that the maximum "load value" in all microservice instances is minimized; based on the alignment results of the two circular sequences, assign each subtask in the batch to the microservice instance so that the succession relationship of the subtasks assigned to the microservice instance remains unchanged.

[0082] The processor 52 may also be referred to as a CPU (Central Processing Unit). The processor 52 may be an integrated circuit chip having signal processing capabilities. The processor 52 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0083] See also Figure 8, is a schematic diagram of the structure of the storage medium of the embodiment of the present application. The storage medium of the embodiment of the present application stores a program instruction 61 that can implement the following steps: obtain a microservice task, divide the microservice task into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape; respectively obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the batch, use the cumulative load and the load of each subtask in the batch as two ring sequences, and use the sequence alignment algorithm based on dynamic programming to align the two ring sequences so that the maximum "load value" in all microservice instances is minimized; based on the alignment results of the two ring sequences, assign each subtask in the batch to the microservice instance so that the succession relationship of the subtasks assigned to the microservice instance remains unchanged. Among them, the program instruction 61 can be stored in the above-mentioned storage medium in the form of a software product, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network computer device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program instructions, or terminal computer devices such as computers, servers, mobile phones, tablets, etc. Among them, the server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0084] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0085] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. The above is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the description and drawings of this application, or directly or indirectly used in other related technical fields, is also included in the patent protection scope of the present application.

Claims

1. A microservice load balancing method, It is characterized in that include: Obtain a microservice task, divide the microservice task into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape; The cumulative load of each microservice instance in the current system and the load of each subtask in the batch are obtained respectively, and the cumulative load and the load of each subtask in the batch are used as two circular sequences, and the two circular sequences are aligned by a sequence alignment algorithm based on dynamic programming so that the maximum "load value" in all microservice instances is minimized; Based on the alignment result of the two ring sequences, each subtask in the batch is allocated to a microservice instance, so that the succession relationship of the subtasks allocated to the microservice instance remains unchanged.

2. The microservice load balancing method according to claim 1, It is characterized in that Before obtaining the microservice task, the following is also included: The number of microservice instances in the current system is obtained; wherein the number of the microservice instances is m, and the m microservice instances are deployed in a ring manner.

3. The microservice load balancing method according to claim 2, It is characterized in that The subtask division of the microservice task according to the number of microservice instances in the current system is specifically as follows: The number of subtask divisions of the microservice task is less than or equal to the number m of microservice instances in the current system.

4. The microservice load balancing method according to any one of claims 1 to 3, It is characterized in that The method further includes: obtaining the accumulated load of each microservice instance in the current system and the load of each subtask in the batch respectively, and taking the accumulated load and the load of each subtask in the batch as two ring sequences; The two circular sequences S 1 and S 2 The elements in are put into a ring in order, and the number of positions on the ring is the same as the number of microservice instances in the current system.

5. The microservice load balancing method according to claim 4, It is characterized in that The two circular sequences are aligned using a sequence alignment algorithm based on dynamic programming, specifically: Under the constraints that the successor relationship of sequence elements is not changed and the length of the merged sequence is not greater than the number of microservice instances, a sequence alignment algorithm based on dynamic programming is used to align two circular sequences S at m positions. 1 and S 2 Align and align the two circular sequences S 1 and S 2 The corresponding elements in are merged to obtain a new load sequence S 3 , so that the maximum "load value" of all microservice instances is minimized.

6. The microservice load balancing method according to claim 5, It is characterized in that The two circular sequences are aligned using a sequence alignment algorithm based on dynamic programming, specifically: Initialize the dynamic programming array S as a four-dimensional array, S i, (p, q) records the maximum sum of the corresponding elements in the current two ring sequences, and implies that the algorithm proceeds to S 1 The i-th element of S 2 The jth element of i and b i , and S 1 p gaps have been used, S 2 If q gaps have been used, the dynamic transfer equation is: The parameters i, j, p in the above formula satisfy the following constraints: Among them, | 1 | and | 2 | respectively represent two circular sequences S 1 and S 2 The number of elements of the two circular sequences, the inequalities represent the index ranges of the elements or available gaps of the two circular sequences, and the equality represents S 1 and S 2 The elements or gaps correspond to each other; When we start running the sequence alignment algorithm, we first calculate the starting point of the dynamic programming process: The first equation represents S 1 and S 2 Both use gaps for alignment. The second and third equations represent S 1 and S 2 One of the sequences in is aligned using gaps, and the other is aligned using elements. The fourth equation expresses S 1 and S 2 All elements are used for alignment, and the parameter χ is all possible values ​​that satisfy the conditional constraints.

7. The microservice load balancing method according to claim 1, It is characterized in that Based on the alignment result of the two ring sequences, each subtask in the batch is assigned to a microservice instance, specifically: The subtasks in the batch are passed to the task adjustment area. In the initial stage of the system, if the number of microservice instances involved in the allocation plan is less than the number of microservice instances in the current system, the subtasks in the batch are cached in the task adjustment area, and then the subtasks organized in a ring are allocated to the microservice instances deployed in a ring through the scheduler, and the preceding and succeeding subtasks of each subtask in the batch remain unchanged after being allocated to the microservice instance.

8. A microservice load balancing device, It is characterized in that include: Microservice partitioning module: used to obtain microservice tasks, divide the microservice tasks into subtasks according to the number of microservice instances in the current system, and organize all subtasks into the same batch in a ring shape; Sequence alignment module: used to obtain the cumulative load of each microservice instance in the current system and the load of each subtask in the batch, respectively, take the cumulative load and the load of each subtask in the batch as two circular sequences, and align the two circular sequences using a sequence alignment algorithm based on dynamic programming, so that the maximum "load value" in all microservice instances is minimized; Task allocation module: used for allocating each subtask in the batch to a microservice instance based on the alignment result of the two ring sequences, so that the succession relationship of the subtasks allocated to the microservice instance remains unchanged.

9. A computer device, It is characterized in that The computer device includes a processor and a memory coupled to the processor, wherein: The memory stores program instructions for implementing the microservice load balancing method according to any one of claims 1 to 7; The processor is used to execute the program instructions stored in the memory to control the microservice load balancing method.

10. A storage medium, It is characterized in that Program instructions executable by a processor are stored, and the program instructions are used to execute the microservice load balancing method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Cluster task distribution method, device and equipment and storage medium

    CN111338793A

  • Load balancing method, system and device and storage medium

    CN112948120A

  • Single-task load balancing method and device under micro-service architecture and medium

    CN115858174A

  • Adjusting dynamically scalable instance hosting based on compute resource usage

    US10884778B1

  • Workload Partitioning in a Parallel System with Hetergeneous Alignment Constraints

    US20080077930A1