Dynamic load balancing task allocation method, allocation system and equipment under micro-service architecture, and storage medium
By dynamically allocating task requests to service instances that meet the warning value, the problem that existing load balancing methods fail to consider the status and load differences of service instances is solved, and more efficient load balancing and resource utilization are achieved.
Patent Information
- Application Number
- CN202411742072.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-11
AI Technical Summary
The existing load balancing method fails to effectively consider the load differences and status information between service instances, resulting in easy load imbalance in complex application scenarios, affecting the system response speed and resource utilization.
By receiving user task requests, the CPU occupancy, memory occupancy and network occupancy of all service instances are obtained, and the task requests are dynamically allocated to service instances whose metrics do not exceed the warning value.
It effectively avoids load imbalance problems, improves the adaptability and flexibility of the system, and ensures effective utilization of resources and maximizing task requests.
Smart Images

Figure CN119806801A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of load balancing task allocation, and specifically to a dynamic load balancing task allocation method, allocation system and device, and storage medium under a microservice architecture. Background Art
[0002] In modern microservice architecture, load balancing is a key technology to ensure high availability and high performance of the system. Its main goal is to evenly distribute user task requests to multiple service instances, improve usage efficiency, and avoid the imbalance problem of some service instances being overloaded while others are idle, thereby ensuring system stability and response speed.
[0003] Static load balancing methods or simple dynamic load balancing methods are often used in the prior art. Specifically, a fixed amount of task requests is preset for each service instance. When a user's task request is received, the task request is allocated using algorithms such as polling, least connection, and source address hashing.
[0004] Among them, the polling algorithm assigns task requests one by one to the sorted service instances in a simple and intuitive way. The polling algorithm is simple to operate and does not require obtaining the status information of the service instances; however, in actual applications, the load differences between service instances are not taken into account.
[0005] The least connection algorithm determines the allocation of task requests based on the number of connections of the current service instance, and preferentially allocates task requests to the service instance with the least number of connections. The least connection algorithm is suitable for processing long connection requests, and can prevent some service instances from being overloaded due to too many connections to a certain extent; however, in actual applications, it ignores the status information of each service instance, such as CPU occupancy, memory occupancy, and network occupancy, which may result in some service instances with a small number of connections but a high CPU occupancy, memory occupancy, or network occupancy still being allocated task requests.
[0006] The source address hashing algorithm hashes the IP address of the task request to ensure that the task request from the same IP address is always assigned to the same service instance. The source address hashing algorithm is suitable for scenarios that require session persistence, but in actual applications, it does not take into account the status information of the service instance, which may cause some service instances to be in a high-load state for a long time, thereby affecting the performance of the system.
[0007] In summary, the above load balancing method does not take into account the load differences between service instances and is only applicable to simple specific application scenarios. In complex application scenarios, it is difficult to meet the requirements of adaptability and flexibility. For example, in complex scenarios of radio and television production, service instances are prone to load imbalance. Some service instances may be overloaded while others are idle. When a service instance is overloaded, it will affect the response speed of the system, thereby affecting the user experience and even causing the system to crash or fail. For example, in application scenarios such as live broadcasts, financial trading systems or video conferencing, the system response speed needs to be high. Response delays not only affect user satisfaction, but may also lead to user churn and even economic losses. When a service instance is idle, the utilization rate of the service instance is low, resulting in a waste of resources. Summary of the invention
[0008] In order to solve one of the above-mentioned technical defects, the present application provides a dynamic load balancing task allocation method, allocation system and device, and storage medium under a microservice architecture.
[0009] According to a first aspect of the present application, a method for dynamic load balancing task allocation under a microservice architecture is provided, comprising:
[0010] receiving and responding to at least one task request from a user;
[0011] Get the CPU usage, memory usage, and network usage of all service instances in the system;
[0012] Dynamically allocate task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values.
[0013] According to a second aspect of the present application, a dynamic load balancing task allocation system under a microservice architecture is provided, comprising:
[0014] A receiving module, configured to receive and respond to at least one task request from a user;
[0015] The acquisition module is used to obtain the CPU usage, memory usage, and network usage of all service instances in the system;
[0016] The dynamic allocation module is used to dynamically allocate task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values.
[0017] According to a third aspect of the present application, an electronic device is provided, including:
[0018] Memory;
[0019] Processor; and
[0020] Computer programs;
[0021] Wherein, the computer program is stored in the memory and is configured to be executed by the processor to implement the dynamic load balancing task allocation method under the microservice architecture as described in any one of the above items.
[0022] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored; the computer program is executed by a processor to implement a dynamic load balancing task allocation method under a microservice architecture as described in any one of the above items.
[0023] This application takes into account the status information of each service instance, including CPU occupancy, memory occupancy, and network occupancy, and dynamically allocates task requests based on the status information of each service instance, which can effectively avoid the problem of unbalanced load of service instances caused by the failure to consider the load differences and status information between service instances in the prior art. It can meet the adaptability and flexibility requirements of complex application scenarios and provide effective technical support for the optimization of microservice architecture.
[0024] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the contents indicated in the written description and the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0026] Figure 1 A flow chart of a dynamic load balancing task allocation method under a microservice architecture provided in this application;
[0027] Figure 2 A flowchart of adding a new service instance provided for this application;
[0028] Figure 3 A flowchart of the deletion service instance provided for this application;
[0029] Figure 4 for Figure 1 A flowchart of dynamically allocating task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values;
[0030] Figure 5 for Figure 4A flow chart of allocating a task request to a service instance in a first service list by a first allocation strategy;
[0031] Figure 6 An example diagram of allocating a task request to a service instance in a first service list by using a first allocation strategy;
[0032] Figure 7 for Figure 4 A flow chart of allocating task requests one by one to service instances in a second service list by a second allocation strategy;
[0033] Figure 8 An example diagram of allocating task requests one by one to service instances in a second service list by a second allocation strategy;
[0034] Fig. 9 A functional structure diagram of a dynamic load balancing task allocation system under a microservice architecture provided in this application;
[0035] Fig.10 Another functional structure diagram of a dynamic load balancing task allocation system under a microservice architecture provided by this application;
[0036] Fig.11 A functional structure diagram of the deletion service instance provided for this application;
[0037] Fig.12 for Fig. 9 Schematic diagram of the functional structure of the dynamic allocation module;
[0038] Fig.13 for Fig.12 Schematic diagram of the functional structure of the first allocation unit;
[0039] Fig.14 for Fig.12 Schematic diagram of the functional structure of the second allocation unit.
[0040] In the figure:
[0041] 10 is a receiving module, 20 is an acquiring module, 30 is a dynamic allocation module, 40 is an additional condition determination module, 50 is a new module, 60 is a new acquisition module, 70 is a deletion condition determination module, 80 is a deletion module, and 90 is a service instance reallocation module;
[0042] 301 is a first allocation condition judgment unit, 302 is a first allocation unit, 303 is a first task completion judgment unit, 304 is a first iteration unit, 305 is a second allocation condition judgment unit, 306 is a second allocation unit, 307 is an update unit, and 308 is a first result output unit;
[0043] 3021 is a first acquisition unit, 3022 is a first sorting unit, 3023 is a second acquisition unit, 3024 is a second sorting unit, 3025 is a component selection unit, 3026 is a first component allocation unit, 3027 is a first pre-allocation unit, 3028 is a first calculation unit, 3029 is a first evaluation unit, 30291 is a first formal allocation unit, 30292 is a first reallocation unit, and 3030 is a second result output unit;
[0044] 3061 is the third acquisition unit, 3062 is the third sorting unit, 3063 is the task allocation unit, 30631 is the fourth sorting unit, 30632 is the second component allocation unit, 30633 is the second pre-allocation unit, 30634 is the occupancy calculation and pre-allocation judgment unit, 306341 is the second calculation unit, 306342 is the second evaluation unit, 306343 is the second formal allocation unit, 306344 is the service instance quantity judgment unit, 306345 is the second reallocation unit, 306346 is the second iteration unit, and 306347 is the third result output unit. DETAILED DESCRIPTION
[0045] In order to make the technical solutions and advantages in the embodiments of the present application more clearly understood, the exemplary embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0046] Figure 1 A flow chart of a dynamic load balancing task allocation method under a microservice architecture provided in this application is as follows: Figure 1 As shown, in order to solve the above problems, an embodiment of the present application provides a method for dynamic load balancing task allocation under a microservice architecture, including:
[0047] receiving and responding to at least one task request from a user;
[0048] Get the CPU usage, memory usage, and network usage of all service instances in the system;
[0049] Dynamically allocate task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values.
[0050] This application takes into account the status information of each service instance, including CPU occupancy, memory occupancy, and network occupancy, and dynamically allocates task requests based on the status information of each service instance, which can effectively avoid the problem of unbalanced load of service instances caused by the failure to consider the load differences and status information between service instances in the prior art. It can meet the adaptability and flexibility requirements of complex application scenarios and provide effective technical support for the optimization of microservice architecture.
[0051] Figure 2 The flowchart for adding a new service instance provided for this application is as follows: Figure 2 As shown, specifically, after obtaining the CPU occupancy, memory occupancy and network occupancy of all service instances in the system, determine whether the conditions for adding are met. If so, add a new service instance and obtain the CPU occupancy, memory occupancy and network occupancy of the new service instance; then dynamically allocate the task request to the service instance whose CPU occupancy, memory occupancy and network occupancy do not exceed the warning value; otherwise, directly dynamically allocate the task request to the service instance whose CPU occupancy, memory occupancy and network occupancy do not exceed the warning value.
[0052] More specifically, the additional condition may be: when all service instances do not meet the condition that the CPU occupancy rate, the memory occupancy rate and the network occupancy rate do not exceed the warning value, it means that the load of the existing service instances is heavy and a new service instance may be added.
[0053] The new service instances added in this application can quickly expand the system and then participate in the allocation of task requests, which can alleviate the load pressure of existing service instances. In the context of the increasing popularity of cloud computing and microservice architecture, good scalability enables the system to flexibly respond to future business growth.
[0054] Figure 3 The flowchart of the deletion service instance provided for this application is as follows: Figure 3 As shown, specifically, after obtaining the CPU occupancy, memory occupancy and network occupancy of all service instances in the system, determine whether the deletion conditions are met. If so, remove some idle service instances and allocate the removed service instances to other systems with heavier loads; otherwise, end the deletion.
[0055] More specifically, the deletion condition can be: the service instance has not been assigned a task request within a preset time, and the number of idle service instances in the system is greater than a preset threshold. This means that there are many idle service instances in the system for a long time. Some idle service instances can be removed and allocated to other systems with heavier loads to improve utilization and reduce resource waste.
[0056] Figure 4 for Figure 1A flowchart of dynamically allocating task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values is shown in FIG. Figure 4 As shown, further, the task request is dynamically allocated to the service instance whose CPU occupancy, memory occupancy and network occupancy do not exceed the warning value, specifically including:
[0057] Determine whether there is a service instance that meets a first allocation condition among all service instances, where the first allocation condition is: CPU occupancy rate is less than 50%, and both memory occupancy rate and network occupancy rate do not exceed warning values;
[0058] If so, store the service instance that meets the first allocation condition in the first service list, allocate the task request to the service instance in the first service list through the first allocation strategy, and timely update the CPU occupancy, memory occupancy and network occupancy of the service instance; determine whether the allocation of all task requests is completed, and if so, end the allocation; otherwise, iterate and determine whether there is a service instance that meets the first allocation condition among all service instances, and allocate the unallocated task requests;
[0059] If it does not exist, perform the following steps:
[0060] Determine whether there is a service instance that meets the second allocation condition among all service instances, where the second allocation condition is: 50%≤CPU occupancy rate<80%, and both memory occupancy rate and network occupancy rate do not exceed the warning value;
[0061] If so, the service instance that meets the second allocation condition is stored in the second service list, the task request is allocated to the service instance in the second service list one by one through the second allocation strategy, and the CPU occupancy, memory occupancy and network occupancy of the service instance are updated in time;
[0062] If it does not exist, an allocation failure prompt will be output.
[0063] In this application, the first allocation strategy and the second allocation strategy are adopted, which fully consider the load differences between different service instances, and flexibly allocate task requests to different service instance states, so as to ensure that the load of each service instance is close, improve the system response speed, avoid the imbalance of service instance load, and ensure the effective use of resources and the maximum processing of task requests. Among them, the first allocation strategy is applicable to the situation where the resources of the service instance are relatively sufficient, and the task request is preferentially allocated to the service instance with lighter load, so as to improve the utilization rate of the service instance and avoid the waste of resources. At the same time, it can ensure that the task request is processed in time and improve user satisfaction. The second allocation strategy is applicable to the situation where the resources of the service instance are not sufficient and the load is heavy. The resources of each service instance are maximized to improve the overall performance of the system and ensure that more task requests can be processed under heavy load.
[0064] Figure 5 for Figure 4 A flow chart of allocating task requests to service instances in a first service list by a first allocation strategy, such as Figure 5 As shown, further, the task request is allocated to the service instance in the first service list through the first allocation strategy, specifically including:
[0065] Get the number of service instances in the first service list and sort them in descending order according to CPU idleness;
[0066] Get the number of all task requests and the corresponding CPU usage, and sort them from high to low according to CPU usage;
[0067] Compare the number of service instances and the number of task requests, and select the number of components corresponding to the smaller value;
[0068] According to the order of task requests, the task requests corresponding to the number of components are placed into the corresponding components from front to back;
[0069] According to the order of service instances, each component and the corresponding task request are pre-allocated to the service instances from front to back;
[0070] Calculate the CPU usage, memory usage, and network usage of the pre-allocated service instance, and determine whether the CPU usage, memory usage, and network usage of the pre-allocated service instance do not exceed the warning value. If so, perform formal allocation; otherwise, perform pre-allocation again.
[0071] Figure 6 This is an example diagram of allocating task requests to service instances in a first service list using a first allocation strategy, such as Figure 6As shown, there are service instances with CPU occupancy less than 50% and memory occupancy and network occupancy not exceeding the warning value. The first allocation strategy is used to allocate task requests. The first allocation strategy is allocated in the order of (a) to (b). In the example, there are five task requests, and their CPU occupancy are 20%, 15%, 10%, 5%, and 5% respectively; there are three service instances in the first service list, and the CPU occupancy of service instance A, service instance B, and service instance C are 5%, 5%, and 5% respectively. Since the number of service instances is less than the number of task requests, the corresponding number of service instances is selected, that is, 3 components are selected, the first three task requests are placed in the three components respectively, and then they are allocated to the three service instances respectively, and the first round of allocation can be completed.
[0072] After the first round of allocation, the remaining two task requests are allocated. At this time, there are two task requests, and their CPU occupancy rates are 5% and 5% respectively; there are three service instances in the first service list, and the CPU occupancy rates of service instance C, service instance B, and service instance A are 15%, 20%, and 25% respectively. Since the number of task requests is less than the number of service instances, select the components corresponding to the number of task requests, that is, select two components, put the two task requests into the two components respectively, and then allocate them to service instance C and service instance B respectively, so as to complete the allocation of all task requests.
[0073] In this application, the first allocation strategy is applied to the situation where the resources of the service instance are relatively sufficient. Therefore, multiple task requests can be allocated in each round, and the specific processing quantity is determined according to the number of service instances and the number of task requests. After completing the allocation of task requests in each round, the CPU occupancy rate, memory occupancy rate and network occupancy rate of each service instance are updated, which is convenient for real-time monitoring of the status of each service instance and for processing subsequent unallocated task requests.
[0074] Figure 7 for Figure 4 The flowchart of allocating task requests one by one to the service instances in the second service list through the second allocation strategy is as follows, Figure 7 As shown, further, the task requests are allocated one by one to the service instances in the second service list through the second allocation strategy, specifically including:
[0075] Get the CPU usage corresponding to the task request and sort them from high to low according to the CPU usage;
[0076] According to the order of task requests, the task requests are allocated one by one, including:
[0077] Sort the service instances in the second service list according to CPU usage from large to small;
[0078] Place the current task request in the corresponding component;
[0079] Then pre-allocate the component and the corresponding current task request to the service instance with the highest ranking;
[0080] The occupancy rate and pre-allocation judgment are performed on the pre-allocated service instances, including:
[0081] Calculate the CPU usage, memory usage, and network usage of the pre-allocated service instance;
[0082] Determine whether the CPU usage, memory usage, and network usage of the pre-allocated service instance exceed the warning value. If so, formal allocation is performed.
[0083] Otherwise, determine whether the current service instance is the service instance with the lowest order. If so, output an allocation failure prompt; otherwise, pre-allocate the component and the corresponding current task request to the next service instance from front to back, and then iterate the occupancy calculation and pre-allocation judgment of the pre-allocated service instance.
[0084] Figure 8 This is an example diagram of allocating task requests one by one to service instances in the second service list through the second allocation strategy, such as Figure 8 As shown, there is no service instance with CPU occupancy rate less than 50%, but there is a service instance with 50%≤CPU occupancy rate less than 80% and both memory occupancy rate and network occupancy rate do not exceed the warning value. The second allocation strategy is used to allocate task requests. The second allocation strategy is allocated in the order of (d) to (i). In the example, there are five task requests, and their CPU occupancy rates are 15%, 10%, 5%, 5%, and 5% respectively; there are three service instances in the first service list, and the CPU occupancy rates of service instance A1, service instance B1, and service instance C1 are 55%, 53%, and 51% respectively. The task requests are allocated one by one. During the allocation process, if the CPU occupancy rate, memory occupancy rate, and network occupancy rate of the service instance do not exceed the warning value, the task request is preferentially allocated to the service instance with the highest ranking.
[0085] In this application, the second allocation strategy is applied to the case where the service instance is heavily loaded. In order to ensure that the resources of the service instance are effectively used, the task request is allocated to the service instance with a high CPU occupancy rate but has not yet reached the load limit. The task requests are allocated in order from the largest to the smallest CPU occupancy rate, that is, the task requests with high processing power requirements are allocated first, which can improve the performance of the system. Since the service instance is heavily loaded before allocation, it will not cause a significant increase in the system response time.
[0086] In this application, after pre-allocation, it is necessary to determine whether the CPU usage, memory usage and network usage of the pre-allocated service instance exceed the warning value. After formal allocation, the CPU usage, memory usage and network usage of the service instance need to be updated. The changes in the status information of the service instance can be updated and monitored in time, which facilitates the dynamic allocation of task requests to the most suitable service instance while ensuring that the service instance does not exceed the load warning value.
[0087] Fig. 9 A functional structure diagram of a dynamic load balancing task allocation system under a microservice architecture provided in this application, such as Fig. 9 As shown, the present application also provides a dynamic load balancing task allocation system under a microservice architecture, including:
[0088] A receiving module 10, configured to receive and respond to at least one task request from a user;
[0089] The acquisition module 20 is used to obtain the CPU occupancy rate, memory occupancy rate and network occupancy rate of all service instances in the system;
[0090] The dynamic allocation module 30 is used to dynamically allocate task requests to service instances whose CPU occupancy, memory occupancy and network occupancy do not exceed warning values.
[0091] Fig.10 Another functional structure diagram of a dynamic load balancing task allocation system under a microservice architecture provided by this application, Fig.11 The functional structure diagram of the deletion service instance provided for this application is as follows: Fig.10 , 11 As shown, specifically, the dynamic load balancing task allocation system under the microservice architecture also includes:
[0092] The additional condition judgment module 40 is used to judge whether the additional condition is met; the additional condition may be: when all service instances do not meet the condition that the CPU occupancy rate, the memory occupancy rate and the network occupancy rate do not exceed the warning value;
[0093] A new module 50 is used to add a new service instance when the addition condition is met;
[0094] A new acquisition module 60 is added to obtain the CPU occupancy rate, memory occupancy rate and network occupancy rate of the new service instance;
[0095] A deletion condition determination module 70, used to determine whether the deletion condition is met;
[0096] A deletion module 80, used to remove some idle service instances when a deletion condition is met;
[0097] The service instance reallocation module 90 is used to allocate the removed service instances to other systems with heavier loads.
[0098] Fig.12 for Fig. 9 The functional structure diagram of the dynamic allocation module is as follows: Fig.12 As shown, further, the dynamic allocation module 30 includes:
[0099] The first allocation condition determination unit 301 is used to determine whether there is a service instance that meets a first allocation condition among all service instances, where the first allocation condition is: CPU occupancy rate is less than 50%, and both memory occupancy rate and network occupancy rate do not exceed a warning value;
[0100] A first allocation unit 302 is configured to store the service instance satisfying the first allocation condition in a first service list when there is a service instance satisfying the first allocation condition, and allocate the task request to the service instance in the first service list according to a first allocation strategy;
[0101] The first task completion judgment unit 303 is used to judge whether the allocation of all task requests is completed;
[0102] The first iterative unit 304 is configured to iteratively determine whether there is a service instance that meets the first allocation condition among all service instances when the first allocation unit has not completed the allocation of all task requests, and allocate unallocated task requests;
[0103] The second allocation condition judgment unit 305 is used to judge whether there is a service instance that meets the second allocation condition among all service instances when there is no service instance that meets the first allocation condition, and the second allocation condition is: 50%≤CPU occupancy rate<80%, and both the memory occupancy rate and the network occupancy rate do not exceed the warning value;
[0104] The second allocation unit 306 is used for storing the service instances satisfying the second allocation condition in a second service list when there are service instances satisfying the second allocation condition, and allocating the task requests one by one to the service instances in the second service list according to the second allocation strategy;
[0105] An updating unit 307, used to timely update the CPU occupancy, memory occupancy and network occupancy of the service instance;
[0106] The first result output unit 308 is used to output allocation completion information when all task requests are allocated; and to output an allocation failure prompt when there is no service instance that meets the first allocation condition and the second allocation condition among all service instances.
[0107] Fig.13 for Fig.12The functional structure diagram of the first allocation unit is as follows: Fig.13 As shown, further, the first allocation unit 302 specifically includes:
[0108] The first acquisition unit 3021 is used to acquire the number of each service instance in the first service list;
[0109] The first sorting unit 3022 is used to sort the service instances in the first service list according to the CPU idleness from large to small;
[0110] The second acquisition unit 3023 is used to acquire the number of all task requests and the corresponding CPU occupancy rate;
[0111] The second sorting unit 3024 is used to sort all task requests from large to small according to CPU occupancy;
[0112] The component selection unit 3025 is used to compare the number of service instances and the number of task requests, and select the number of components corresponding to the smaller value;
[0113] The first component allocation unit 3026 is used to place the task requests corresponding to the number of components into the corresponding components from front to back according to the order of the task requests;
[0114] A first pre-allocation unit 3027 is used to pre-allocate each component and the corresponding task request to the service instance from front to back according to the order of the service instance;
[0115] A first calculation unit 3028, used to calculate the CPU occupancy, memory occupancy and network occupancy of the pre-allocated service instance;
[0116] The first evaluation unit 3029 is used to determine whether the CPU occupancy rate, memory occupancy rate and network occupancy rate of the pre-allocated service instance do not exceed the warning value;
[0117] The first formal allocation unit 30291 is used to make formal allocation when the first evaluation unit 3029 passes the evaluation;
[0118] A first reallocation unit 30292, configured to reallocate the pre-allocation when the first evaluation unit 3029 fails the evaluation;
[0119] The second result output unit 3030 is used to output formal allocation information when formal allocation is performed; and is used to output a prompt for re-pre-allocation when the first evaluation unit 3029 fails the evaluation.
[0120] Fig.14 for Fig.12 The functional structure diagram of the second allocation unit is as follows: Fig.14As shown, further, the second allocation unit 306 specifically includes:
[0121] The third acquisition unit 3061 is used to acquire the CPU occupancy rate corresponding to the task request;
[0122] The third sorting unit 3062 is used to sort the task requests from large to small according to the CPU occupancy rate;
[0123] The task allocation unit 3063 is used to allocate the task requests one by one according to the order of the task requests, specifically including:
[0124] The fourth sorting unit 30631 is used to sort the service instances in the second service list according to the CPU occupancy rate from large to small;
[0125] The second component allocation unit 30632 is used to place the current task request in the corresponding component;
[0126] The second pre-allocation unit 30633 is used to pre-allocate the component and the corresponding current task request to the service instance with the highest ranking;
[0127] The occupancy calculation and pre-allocation judgment unit 30634 is used to calculate the occupancy and pre-allocation judgment of the pre-allocated service instance, specifically including:
[0128] The second calculation unit 306341 is used to calculate the CPU occupancy, memory occupancy and network occupancy of the pre-allocated service instance;
[0129] The second evaluation unit 306342 is used to determine that the CPU occupancy rate, the memory occupancy rate and the network occupancy rate of the pre-allocated service instance do not exceed the warning value;
[0130] The second formal allocation unit 306343 is used to make formal allocation when the second evaluation unit 30635 passes the evaluation;
[0131] The service instance quantity determination unit 306344 is used to determine whether the current service instance is the service instance with the lowest ranking when the second evaluation unit 30635 fails the evaluation;
[0132] The second reallocation unit 306345 is used to pre-allocate the components and the corresponding current task requests from front to back to the next service instance when the current service instance is not the last service instance in the sorting;
[0133] The second iteration unit 306346 is used to pre-allocate the components and the corresponding current task requests to the next service instance from front to back, and then iteratively perform occupancy and pre-allocation judgment on the pre-allocated service instance;
[0134] The third result output unit 306347 is used to output formal allocation information when formal allocation is performed; and is used to output an allocation failure prompt when the current service instance is the last service instance in the sorting.
[0135] The present application also provides an electronic device, including:
[0136] Memory;
[0137] Processor; and
[0138] Computer programs;
[0139] Wherein, the computer program is stored in the memory and is configured to be executed by the processor to implement the dynamic load balancing task allocation method under the microservice architecture as described in any of the above contents.
[0140] The present application also provides a computer-readable storage medium having a computer program stored thereon; the computer program is executed by a processor to implement a dynamic load balancing task allocation method under a microservice architecture as described in any of the above items.
[0141] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code. The scheme in the embodiments of the present application can be implemented in various computer languages, for example, C language, VHDL language, Verilog language, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0142] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0143] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0144] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0145] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0146] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0147] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A dynamic load balancing task allocation method under a microservice architecture, characterized in that: include: receiving and responding to at least one task request from a user; Get the CPU usage, memory usage, and network usage of all service instances in the system; Dynamically allocate task requests to service instances whose CPU usage, memory usage, and network usage do not exceed warning values.
2. The method for dynamic load balancing task allocation under the microservice architecture according to claim 1 is characterized in that: The dynamically allocating task requests to service instances whose CPU occupancy, memory occupancy, and network occupancy do not exceed the warning values specifically includes: Determine whether there is a service instance that meets a first allocation condition among all service instances, where the first allocation condition is: CPU occupancy rate is less than 50%, and both memory occupancy rate and network occupancy rate do not exceed warning values; If so, store the service instance that meets the first allocation condition in the first service list, allocate the task request to the service instance in the first service list through the first allocation strategy, and timely update the CPU occupancy, memory occupancy and network occupancy of the service instance; determine whether the allocation of all task requests is completed, and if so, end the allocation; otherwise, iterate and determine whether there is a service instance that meets the first allocation condition among all service instances, and allocate the unallocated task requests; If it does not exist, perform the following steps: Determine whether there is a service instance that meets the second allocation condition among all service instances, where the second allocation condition is: 50%≤CPU occupancy rate<80%, and both memory occupancy rate and network occupancy rate do not exceed the warning value; If so, the service instance that meets the second allocation condition is stored in the second service list, the task request is allocated to the service instance in the second service list one by one through the second allocation strategy, and the CPU occupancy, memory occupancy and network occupancy of the service instance are updated in time; If it does not exist, an allocation failure prompt will be output.
3. The method for dynamic load balancing task allocation under the microservice architecture according to claim 2 is characterized in that: The allocating the task request to the service instance in the first service list by using the first allocation strategy specifically includes: Get the number of service instances in the first service list and sort them in descending order according to CPU idleness; Get the number of all task requests and the corresponding CPU usage, and sort them from high to low according to CPU usage; Compare the number of service instances and the number of task requests, and select the number of components corresponding to the smaller value; According to the order of task requests, the task requests corresponding to the number of components are placed into the corresponding components from front to back; According to the order of service instances, each component and the corresponding task request are pre-allocated to the service instances from front to back; Calculate the CPU usage, memory usage, and network usage of the pre-allocated service instance, and determine whether the CPU usage, memory usage, and network usage of the pre-allocated service instance do not exceed the warning value. If so, perform formal allocation; otherwise, perform pre-allocation again.
4. The method for dynamic load balancing task allocation under the microservice architecture according to claim 2 is characterized in that: The step of allocating the task requests one by one to the service instances in the second service list by using the second allocation strategy specifically includes: Get the CPU usage corresponding to the task request and sort them from high to low according to the CPU usage; According to the order of task requests, the task requests are allocated one by one, including: Sort the service instances in the second service list according to CPU usage from large to small; Place the current task request in the corresponding component; Then pre-allocate the component and the corresponding current task request to the service instance with the highest ranking; The occupancy rate and pre-allocation judgment are performed on the pre-allocated service instances, including: Calculate the CPU usage, memory usage, and network usage of the pre-allocated service instance; Determine whether the CPU usage, memory usage, and network usage of the pre-allocated service instance exceed the warning value. If so, formal allocation is performed. Otherwise, determine whether the current service instance is the service instance with the lowest order. If so, output an allocation failure prompt; otherwise, pre-allocate the component and the corresponding current task request to the next service instance from front to back, and then iterate the occupancy calculation and pre-allocation judgment of the pre-allocated service instance.
5. A dynamic load balancing task allocation system under a microservice architecture, characterized in that: include: A receiving module (10), configured to receive and respond to at least one task request from a user; An acquisition module (20) is used to acquire the CPU occupancy rate, memory occupancy rate and network occupancy rate of all service instances in the system; The dynamic allocation module (30) is used to dynamically allocate the task request to the service instance whose CPU occupancy rate, memory occupancy rate and network occupancy rate do not exceed the warning value.
6. The dynamic load balancing task allocation system under the microservice architecture according to claim 5 is characterized in that: The dynamic allocation module (30) comprises: A first allocation condition judgment unit (301) is used to judge whether there is a service instance that meets a first allocation condition among all service instances, the first allocation condition being: CPU occupancy rate < 50%, and memory occupancy rate and network occupancy rate both not exceeding a warning value; A first allocation unit (302) is used to store the service instance satisfying the first allocation condition in a first service list when there is a service instance satisfying the first allocation condition, and allocate the task request to the service instance in the first service list according to a first allocation strategy; A first task completion judgment unit (303) is used to judge whether the allocation of all task requests is completed; A first iteration unit (304) is used to iteratively determine whether there is a service instance that meets the first allocation condition among all service instances when the first allocation unit has not completed the allocation of all task requests, and allocate unallocated task requests; A second allocation condition judgment unit (305) is used to judge whether there is a service instance that meets the second allocation condition among all service instances when there is no service instance that meets the first allocation condition, wherein the second allocation condition is: 50%≤CPU occupancy rate<80%, and both the memory occupancy rate and the network occupancy rate do not exceed the warning value; A second allocation unit (306) is used to store the service instance satisfying the second allocation condition in a second service list when there is a service instance satisfying the second allocation condition, and to allocate the task requests one by one to the service instances in the second service list according to a second allocation strategy; An updating unit (307), used to timely update the CPU occupancy rate, memory occupancy rate and network occupancy rate of the service instance; The first result output unit (308) is used to output allocation completion information when all task requests are allocated; and to output allocation failure prompt when there is no service instance that meets the first allocation condition and the second allocation condition among all service instances.
7. The dynamic load balancing task allocation system under the microservice architecture according to claim 6 is characterized in that: The first allocation unit (302) specifically comprises: A first acquisition unit (3021), configured to acquire the number of each service instance in the first service list; A first sorting unit (3022) is used to sort the service instances in the first service list according to CPU idleness from large to small; The second acquisition unit (3023) is used to acquire the number of all task requests and the corresponding CPU occupancy rate; The second sorting unit (3024) is used to sort all task requests according to CPU occupancy rate from large to small; A component selection unit (3025) is used to compare the number of service instances and the number of task requests, and select the number of components corresponding to the smaller value; A first component allocation unit (3026) is used to place the task requests corresponding to the number of components into the corresponding components from front to back according to the order of the task requests; A first pre-allocation unit (3027), configured to pre-allocate each component and the corresponding task request to the service instance from front to back according to the order of the service instance; A first calculation unit (3028), used to calculate the CPU occupancy, memory occupancy and network occupancy of the pre-allocated service instance; A first evaluation unit (3029) is used to determine whether the CPU occupancy rate, memory occupancy rate and network occupancy rate of the pre-allocated service instance do not exceed the warning value; A first formal allocation unit (30291), used for making a formal allocation when the first evaluation unit (3029) passes the evaluation; A first reallocation unit (30292), configured to reallocate the pre-allocation when the first evaluation unit evaluation (3029) fails; The second result output unit (3030) is used to output formal allocation information when formal allocation is made; and is used to output a prompt for re-pre-allocation when the first evaluation unit evaluation (3029) fails.
8. The dynamic load balancing task allocation system under the microservice architecture according to claim 6 is characterized in that: The second allocation unit (306) specifically comprises: The third acquisition unit (3061) is used to acquire the CPU occupancy rate corresponding to the task request; A third sorting unit (3062) is used to sort the task requests according to the CPU occupancy rate from large to small; The task allocation unit (3063) is used to allocate the task requests one by one according to the order of the task requests, specifically including: A fourth sorting unit (30631) is used to sort the service instances in the second service list according to CPU occupancy rate from large to small; The second component allocation unit (30632) is used to place the current task request in the corresponding component; A second pre-allocation unit (30633) is used to pre-allocate the component and the corresponding current task request to the service instance with the highest ranking; The occupancy calculation and pre-allocation judgment unit (30634) is used to calculate the occupancy and pre-allocation judgment of the pre-allocated service instance, specifically including: The second calculation unit (306341) is used to calculate the CPU occupancy, memory occupancy and network occupancy of the pre-allocated service instance; The second evaluation unit (306342) is used to determine whether the CPU occupancy rate, memory occupancy rate and network occupancy rate of the pre-allocated service instance do not exceed the warning value; The second formal allocation unit (306343) is used to make formal allocation when the second evaluation unit (30635) passes the evaluation; A service instance quantity determination unit (306344), configured to determine whether the current service instance is the service instance with the lowest ranking when the second evaluation unit (30635) fails the evaluation; The second reallocation unit (306345) is used to pre-allocate the components and the corresponding current task requests to the next service instance from front to back when the current service instance is not the last service instance in the sorting; The second iteration unit (306346) is used to pre-allocate the components and the corresponding current task requests to the next service instance from front to back, and then iteratively perform occupancy and pre-allocation judgment on the pre-allocated service instance; The third result output unit (306347) is used to output formal allocation information when formal allocation is performed; and is used to output an allocation failure prompt when the current service instance is the last service instance in the sorting.
9. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the dynamic load balancing task allocation method under the microservice architecture as described in any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon; the computer program is executed by a processor to implement the dynamic load balancing task allocation method under the microservice architecture as described in any one of claims 1 to 4.