Resource scheduling method and device for container cluster
By first adapting the FirstFit algorithm and the improved genetic algorithm combined with the greedy algorithm to optimize the resource scheduling of container clusters, the problems of load imbalance and resource fragmentation in large-scale container clusters are solved, and fast and effective resource scheduling is achieved.
Patent Information
- Application Number
- CN202110574037.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-25
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2041-05-25
AI Technical Summary
Existing technologies are not applicable to resource scheduling of large-scale container clusters, resulting in unbalanced load on cluster nodes and excessive resource fragmentation. In addition, traditional genetic algorithms have blind convergence directions and slow convergence speeds.
The FirstFit algorithm and the improved genetic algorithm are used for container scheduling. First, the containers are divided into first target containers and second target containers based on the resource demand sorting. The first target container is scheduled using the FirstFit algorithm, and the second target container is scheduled using the improved genetic algorithm. The scheduling process is optimized by combining the greedy algorithm and the roulette algorithm.
It achieves rapid iterative convergence, reduces resource fragmentation, optimizes cluster resource allocation, saves scheduling time, improves resource scheduling efficiency, and reduces cluster resource scheduling costs.
Smart Images

Figure CN115391024B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a resource scheduling method and device for a container cluster. Background Art
[0002] Kubernetes is an open source project developed by Google to solve container orchestration problems. It has now become the implementation standard in the container orchestration field.
[0003] In related technologies, the Kubernetes scheduler is scheduled based on a scheduling algorithm that filters hosts and scores hosts. This scheduling method is easy to implement, but ignores the dynamic changes in the applicability of cluster resources, resulting in problems such as unbalanced load on cluster nodes and excessive resource fragmentation.
[0004] In addition, related technologies also use traditional genetic algorithms to search for the optimal solution globally. However, since parameters such as the crossover rate and mutation rate cannot be predicted, the algorithm has problems such as blind convergence direction and slow convergence speed.
[0005] In summary, the relevant technologies are not applicable to the resource scheduling process of large-scale container clusters, which is prone to unbalanced load on cluster nodes and excessive resource fragmentation. In addition, the use of traditional genetic algorithms has the problems of blind convergence direction and slow convergence speed. Summary of the Invention
[0006] The present invention provides a resource scheduling method and device for a container cluster, which is used to solve the problems that related technologies are not applicable to the resource scheduling process of large-scale container clusters, are prone to unbalanced cluster node loads and excessive resource fragmentation, and the use of traditional genetic algorithms has the problems of blind convergence direction and slow convergence speed.
[0007] In a first aspect, the present invention provides a resource scheduling method for a container cluster, comprising:
[0008] Obtaining resource requirements of target containers, sorting the target containers according to a first preset order based on the resource requirements of the target containers, using a first preset proportion of the sorted target containers as first target containers, and using the remaining target containers as second target containers;
[0009] Scheduling the first target container to the first node based on a FirstFit algorithm;
[0010] scheduling the second target container to the first node based on an improved genetic algorithm;
[0011] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0012] In one embodiment, scheduling the second target container to the first node based on the improved genetic algorithm specifically includes:
[0013] Initialize a population, where each individual in the population is a first node on which a first target container has been deployed;
[0014] Calculating the fitness of the first node, where the fitness of the first node is related to the remaining resources of the first node, and the smaller the remaining resources of the first node, the higher the fitness of the first node;
[0015] All individuals in the population are sorted from largest to smallest according to fitness, and the first target node and the second target node are selected from the second preset proportion of individuals in the lower sort order according to the roulette wheel algorithm;
[0016] Perform cross processing on the first target node and the second target node based on a greedy algorithm, and schedule the second target container based on the cross processing result;
[0017] When all scheduling of the second target container is completed, or the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
[0018] In one embodiment, performing cross processing on the first target node and the second target node based on a greedy algorithm, and scheduling the second target container based on the cross processing result, specifically includes:
[0019] Acquire third target containers on the first target node and the second target node, and sort the third target containers according to a second preset order based on resource requirements, where the third target container is at least one container in the first target containers;
[0020] Scheduling the sorted third target container to the first target node and the second target node respectively based on a greedy algorithm to obtain at least one scheduling mode, and determining the fitness of the first target node and the second target node in each scheduling mode;
[0021] Based on the fitness of the first target node and the second target node in each scheduling mode, using the objective function to calculate the objective function value of the at least one scheduling mode, if the objective function value of the at least one scheduling mode is lower than the objective function value before the crossover, reselecting the first target node and the second target node, otherwise retaining the scheduling mode with the higher objective function value;
[0022] Determine a target node with a lower fitness in a scheduling mode with a higher objective function value, and schedule the second target container to the target node.
[0023] In one embodiment, the objective function is specifically:
[0024] ψ(n1, n2) = (g(n1) - g(n2)) 2 (1)
[0025] Wherein, ψ(n1, n2) represents the variance of the fitness of the first target node and the fitness of the second target node, n1 represents the first target node, n2 represents the second target node, g(n1) represents the fitness of the first target node, and g(n2) represents the fitness of the second target node.
[0026] In one embodiment, the method of scheduling the sorted third target container to the first target node and the second target node based on the greedy algorithm to obtain at least one scheduling method specifically includes:
[0027] Scheduling the sorted third target container to the first target node, and when resources of the first target node are fully occupied, scheduling the remaining containers in the sorted third target container to the second target node;
[0028] Alternatively, the sorted third target container is scheduled to the second target node, and when resources of the second target node are fully occupied, the remaining containers in the sorted third target container are scheduled to the first target node.
[0029] In one embodiment, scheduling the first target container to the first node based on a FirstFit algorithm specifically includes:
[0030] Obtaining resource ratios of the first target container and the first node respectively;
[0031] If the resource ratio of the first target container and the resource ratio of the first node meet a preset condition, scheduling the first target container to the first node;
[0032] Among them, the preset condition is: 0≤I c1 / I r1 -I c2 / I r2 ≤Δk,I c1 / I r1 Indicates the resource ratio of the first target container, I c2 / I r2 Indicates the resource ratio of the first node, I c1 Indicates the CPU resource requirement of the first target container, I r1 Indicates the memory resource requirement of the first target container, I c2represents the CPU resource requirement of the first node, I r2 represents the memory resource requirement of the first node, and Δk is a second preset threshold.
[0033] In one embodiment, the resource scheduling method for a container cluster further includes:
[0034] If the second target container is not fully scheduled, obtain a second node in the cluster, where the second node is at least one node in the cluster on which no container is deployed;
[0035] sorting the second nodes in a third preset order based on the total amount of resources of the second nodes to obtain a first list;
[0036] Based on the sorting result, a node with a first sequence number is taken from the first list, and an unscheduled second target container is scheduled to the node with the first sequence number;
[0037] When the resources of the first sequence number node are fully occupied, the second sequence number node is taken out from the first list, and the remaining containers in the unscheduled second target containers are scheduled to the second sequence number node until all the second target containers are scheduled.
[0038] In a second aspect, the present invention provides a resource scheduling device for a container cluster, comprising:
[0039] a sorting unit, configured to obtain resource requirements of target containers, sort the target containers in a first preset order based on the resource requirements of the target containers, use a first preset proportion of the sorted target containers as first target containers, and use the remaining target containers as second target containers;
[0040] A first scheduling unit is configured to schedule the first target container to the first node based on a FirstFit algorithm;
[0041] a second scheduling unit, configured to schedule the second target container to the first node based on an improved genetic algorithm;
[0042] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0043] In a third aspect, the present invention provides an electronic device comprising a memory and a memory storing a computer program, wherein when the processor executes the program, the steps of the resource scheduling method for the container cluster described in the first aspect are implemented.
[0044] In a fourth aspect, the present invention provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, and the computer program is used to enable the processor to execute the steps of the resource scheduling method for the container cluster described in the first aspect.
[0045] The resource scheduling method and device for a container cluster provided by the present invention obtain the resource requirements of the target containers, sort the target containers in a first preset order based on the resource requirements of the target containers, use a first preset proportion of the sorted target containers as the first target containers, and use the remaining target containers as the second target containers. The first target container is scheduled to the first node based on the first adaptation FirstFit algorithm, and the second target container is scheduled to the first node based on the improved genetic algorithm. Rapid iterative convergence can be achieved, and blind convergence direction can be avoided. Batch scheduling of containers is realized, the cluster resource allocation method is optimized, the resource fragmentation generated in the resource scheduling process is reduced, scheduling time is saved, resource scheduling efficiency is improved, and cluster resource scheduling costs are reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0047] Figure 1 This is a flow chart of the resource scheduling method for a container cluster provided by the present invention;
[0048] Figure 2 This is a schematic diagram of a process for resource scheduling based on an improved genetic algorithm provided by the present invention;
[0049] Figure 3 This is a schematic diagram of the structure of the resource scheduling device for the container cluster provided by the present invention;
[0050] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0051] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0052] The existing technical solution uses the traditional Kubernetes scheduling strategy to schedule containers. The Kubernetes scheduler is a two-stage online scheduler that selects a host for each unscheduled container through a set of rules. The scheduling algorithm includes host filtering and host scoring.
[0053] Specifically, the execution logic of the Kubernetes scheduler is to allocate a host for the container to run the container based on the cluster's resource availability and the container's scheduling constraints each time a new container is created and scheduled.
[0054] Traditional Kubernetes scheduling strategies use a static scheduling approach, which only considers the actual usage of cluster resources during the scheduling process and ignores the dynamic changes in cluster resource usage. This makes it impossible to allocate computing resources to containers from a global perspective, lacks overall planning, and is prone to problems such as unbalanced cluster node loads and excessive resource fragmentation.
[0055] The existing technical solutions also use traditional genetic algorithms to schedule containers. Traditional genetic algorithms include three basic operations: selection, crossover, and mutation.
[0056] Specifically, the selection operation is used to retain the genes of the current better solution, the crossover operation is used to generate a new solution based on the current better solution, and the mutation operation is used to find the best solution in the global scope in order to jump out of the local optimal solution.
[0057] Traditional genetic algorithms have the ability to globally search for optimal solutions, but parameters such as crossover rate and mutation rate cannot be predicted, resulting in the algorithm having problems of blind convergence direction and slow convergence speed.
[0058] In order to solve the above technical problems, an embodiment of the present invention provides a resource scheduling method for a container cluster. Figure 1 This is a flow chart of the resource scheduling method for a container cluster provided by an embodiment of the present invention. Figure 1 As shown, the resource scheduling method for a container cluster provided by the present invention includes:
[0059] Step 100: Obtain resource requirements of target containers, sort the target containers according to a first preset order based on the resource requirements of the target containers, use a first preset proportion of the sorted target containers as first target containers, and use the remaining target containers as second target containers.
[0060] The target container includes at least two containers.
[0061] Resource demand refers to the container's demand for central processing unit (CPU) resources and memory resources, where CPU resources and memory resources have the same weight.
[0062] Optionally, the first preset order is an order from largest to smallest.
[0063] Optionally, the first preset proportion is the top 80% when sorting in descending order.
[0064] The first target container is at least one container of a first preset ratio after sorting.
[0065] The second target container is at least one container among the target containers except the first target container.
[0066] In one embodiment, resource requirements of target containers are obtained, and the target containers are sorted in descending order according to the resource requirements of the target containers. The target containers in the first 80% of the sorting are used as the first target container, and the target containers in the last 20% of the sorting are used as the second target container.
[0067] Step 101: Schedule the first target container to the first node based on the FirstFit algorithm.
[0068] Optionally, scheduling the first target container to the first node based on a FirstFit algorithm specifically includes:
[0069] Obtaining resource ratios of the first target container and the first node respectively;
[0070] If the resource ratio of the first target container and the resource ratio of the first node meet a preset condition, scheduling the first target container to the first node;
[0071] Among them, the preset condition is: 0≤I c1 / I r1 -I c2 / I r2 ≤Δk,I c1 / I r1 Indicates the resource ratio of the first target container, I c2 / I r2 Indicates the resource ratio of the first node, I c1 Indicates the CPU resource requirement of the first target container, I r1 Indicates the memory resource requirement of the first target container, I c2 represents the CPU resource requirement of the first node, I r2represents the memory resource requirement of the first node, and Δk is a second preset threshold.
[0072] It should be noted that in order to optimize cluster resource allocation, reduce cluster resource fragmentation as a whole, and lower resource costs, the embodiment of the present invention adopts the FirstFit algorithm to prioritize scheduling the first target container, and introduces a resource ratio factor for regulation in the resource scheduling process.
[0073] The principle of the FirstFit algorithm is to schedule containers with a resource ratio in the first target container close to the resource ratio of the first node to the first node when the first node can store at least one container.
[0074] The first node is at least one node in the cluster.
[0075] The resource ratio is the ratio of CPU resources to memory resources.
[0076] In one implementation, the first target container is scheduled to a first node having a resource ratio close to that of the container based on a FirstFit algorithm.
[0077] Step 102: Schedule the second target container to the first node based on an improved genetic algorithm; wherein the target container includes at least two containers, and the first node includes at least one node in a cluster.
[0078] In order to solve the problem that parameters such as crossover rate and mutation rate in traditional genetic algorithms cannot be predicted, resulting in the algorithm having blind convergence direction and slow convergence speed, the embodiment of the present invention adopts an improved genetic algorithm that can quickly iterate and converge. The subclass of the improved genetic algorithm is dozens of times that of the traditional genetic algorithm. The quality of the solution obtained based on the improved genetic algorithm is significantly improved compared with the traditional genetic algorithm.
[0079] It should be noted that the second target container is used to fill resource fragments on the first node.
[0080] Among them, the improved genetic algorithm only uses selection and crossover operations, removes mutation operations, reduces the blindness of the algorithm search, achieves rapid convergence, and improves computational efficiency.
[0081] The resource scheduling method for a container cluster provided by an embodiment of the present invention obtains the resource demand of the target container, sorts the target containers according to a first preset order based on the resource demand of the target container, uses a first preset proportion of the sorted target containers as the first target container, and uses the remaining target containers as the second target container, schedules the first target container to the first node based on the first adaptation FirstFit algorithm, and schedules the second target container to the first node based on the improved genetic algorithm. It can quickly iterate and converge, avoid blind convergence direction, realize batch scheduling of containers, optimize the cluster resource allocation method, reduce resource fragmentation generated in the resource scheduling process, save scheduling time, improve resource scheduling efficiency, and reduce cluster resource scheduling costs.
[0082] Figure 2 FIG. 1 is a flow chart of resource scheduling based on an improved genetic algorithm provided by an embodiment of the present invention. Figure 2 As shown, based on any of the above embodiments, scheduling the second target container to the first node based on the improved genetic algorithm specifically includes:
[0083] Step 200: Initialize a population, where each individual in the population is a first node on which a first target container has been deployed.
[0084] It should be noted that by taking the first node where the first target container has been deployed as a population individual, selecting the target node from the population based on the improved genetic algorithm, and scheduling the second target container to the target node, the amount of resources wasted on the target node can be minimized.
[0085] Step 201: Calculate the fitness of the first node. The fitness of the first node is related to the remaining resources of the first node. The smaller the remaining resources of the first node, the higher the fitness of the first node.
[0086] The remaining resource amount is obtained based on the resource remaining rate and the total resource amount.
[0087] The resource surplus ratio is the ratio of the remaining CPU resources and remaining memory resources on a node to the total resources. CPU resources and memory resources have equal weight.
[0088] Step 202: sort all individuals in the population from largest to smallest according to fitness, and select the first target node and the second target node from the individuals in the second preset proportion at the bottom of the sort according to the roulette wheel algorithm.
[0089] It should be noted that in order to improve the overall fitness of the population during the selection operation, two individuals with smaller fitness are preferentially selected to further reduce the blindness of the algorithm search.
[0090] Optionally, the second preset ratio is 50%.
[0091] The principle of the roulette algorithm is that the probability of each individual in the population being selected is proportional to the individual's fitness, and the purpose is to avoid individuals with lower fitness being directly eliminated.
[0092] The first target node is a node with a smaller fitness among the first nodes.
[0093] The second target node is a node with a smaller fitness among the first nodes, and the fitness of the first target node and the second target node are different.
[0094] In one embodiment, all nodes in the population are sorted from largest to smallest according to fitness, and the first target node and the second target node are selected from the bottom 50% of the sorted nodes according to a roulette wheel algorithm.
[0095] Step 203: Perform cross processing on the first target node and the second target node based on a greedy algorithm, and schedule the second target container based on the cross processing result.
[0096] All containers deployed on the first target node and the second target node are reallocated to the first target node and the second target node based on a greedy algorithm to obtain at least one scheduling method.
[0097] The cross-processing result is a scheduling method that satisfies the local optimum among the at least one scheduling method.
[0098] It's important to note that the crossover operation modifies the traditional probability-based crossover operation, further determining the algorithm's search direction. The crossover operation aims to maximize the fitness of one of the two selected individuals while decreasing the fitness of the other. The individual with the lower fitness has more remaining resources and, therefore, a greater probability of storing the second target container.
[0099] Step 204: When all scheduling of the second target container is completed, or the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
[0100] In one embodiment, when all scheduling of the second target container is completed, the scheduling of the second target container is ended.
[0101] In one embodiment, when the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
[0102] The resource scheduling method for a container cluster provided by an embodiment of the present invention initializes a population, calculates the fitness of individuals in the population, selects and crosses individuals, and schedules a second target container based on the crossover result, thereby effectively reducing the blindness of the improved genetic algorithm, enabling rapid iterative convergence, realizing batch scheduling of containers, optimizing the cluster resource allocation method, reducing resource fragmentation generated during the resource scheduling process, saving scheduling time, improving resource scheduling efficiency, and reducing cluster resource scheduling costs.
[0103] Based on any of the foregoing embodiments, performing cross processing on the first target node and the second target node based on a greedy algorithm, and scheduling the second target container based on the cross processing result, specifically includes:
[0104] Acquire third target containers on the first target node and the second target node, and sort the third target containers according to a second preset order based on resource requirements, where the third target container is at least one container in the first target containers;
[0105] Scheduling the sorted third target container to the first target node and the second target node respectively based on a greedy algorithm to obtain at least one scheduling mode, and determining the fitness of the first target node and the second target node in each scheduling mode;
[0106] Based on the fitness of the first target node and the second target node in each scheduling mode, using the objective function to calculate the objective function value of the at least one scheduling mode, if the objective function value of the at least one scheduling mode is lower than the objective function value before the crossover, reselecting the first target node and the second target node, otherwise retaining the scheduling mode with the higher objective function value;
[0107] Determine a target node with a lower fitness in a scheduling mode with a higher objective function value, and schedule the second target container to the target node.
[0108] Optionally, the second preset order is an order from largest to smallest, and the second preset order may be the same as or different from the first preset order.
[0109] Optionally, the method of scheduling the sorted third target container to the first target node and the second target node based on a greedy algorithm to obtain at least one scheduling mode specifically includes:
[0110] Scheduling the sorted third target container to the first target node, and when resources of the first target node are fully occupied, scheduling the remaining containers in the sorted third target container to the second target node;
[0111] Alternatively, the sorted third target container is scheduled to the second target node, and when resources of the second target node are fully occupied, the remaining containers in the sorted third target container are scheduled to the first target node.
[0112] Optionally, the objective function is specifically:
[0113] ψ(n1, n2) = (g(n1) - g(n2)) 2 (1)
[0114] Wherein, ψ(n1, n2) represents the variance of the fitness of the first target node and the fitness of the second target node, n1 represents the first target node, n2 represents the second target node, g(n1) represents the fitness of the first target node, and g(n2) represents the fitness of the second target node.
[0115] The target node is a node with a smaller fitness selected from the first target node and the second target node in a scheduling mode with a higher objective function value.
[0116] It should be noted that the objective function value before the crossover is the objective function value calculated by using formula (1) for the first target node and the second target node before the crossover process is performed.
[0117] It should be noted that, based on the above two scheduling methods, the objective function values of the two scheduling methods are calculated using formula (1) respectively. The objective function values before the first target node and the second target node are obtained using formula (1) before the crossover process. If the objective function values of the two scheduling methods are smaller than the objective function values before the crossover, the first target node and the second target node are reselected based on the selection operation in the improved genetic algorithm. If the objective function value of at least one scheduling method is greater than or equal to the objective function value before the crossover, the scheduling method with the higher objective function value is selected. In the scheduling method with the higher objective function value, the fitness of the first target node and the second target node is compared, and the target node with the smaller fitness is selected as the result of the crossover operation.
[0118] The resource scheduling method for a container cluster provided by an embodiment of the present invention performs cross-processing on a first target node and a second target node based on a greedy algorithm to obtain a target node with smaller fitness, schedules the second target container to the target node with smaller fitness, obtains a global optimal solution from a local optimal solution, can quickly iterate and converge, realizes batch scheduling of containers, optimizes the cluster resource allocation method, reduces resource fragmentation generated in the resource scheduling process, saves scheduling time, improves resource scheduling efficiency, and reduces cluster resource scheduling costs.
[0119] Based on any of the above embodiments, the resource scheduling method for the container cluster further includes:
[0120] If the second target container is not fully scheduled, obtain a second node in the cluster, where the second node is at least one node in the cluster on which no container is deployed;
[0121] sorting the second nodes in a third preset order based on the total amount of resources of the second nodes to obtain a first list;
[0122] Based on the sorting result, a node with a first sequence number is taken from the first list, and an unscheduled second target container is scheduled to the node with the first sequence number;
[0123] When the resources of the first sequence number node are fully occupied, the second sequence number node is taken out from the first list, and the remaining containers in the unscheduled second target containers are scheduled to the second sequence number node until all the second target containers are scheduled.
[0124] Optionally, the third preset order is an order from largest to smallest, and the third preset order may be the same as or different from the first preset order and the second preset order.
[0125] The first list is a sorting result obtained by sorting the second nodes according to a third preset order based on the total amount of resources of the second nodes.
[0126] The first sequence number node is the node that ranks first in the first list.
[0127] The second sequence number node is the second node in the first list.
[0128] The first node includes a first sequence number node and a second sequence number node.
[0129] In one implementation, the second nodes are sorted in descending order based on the total amount of resources of the second nodes to obtain a first list, a node with a first sequence number is selected from the first list, and the unscheduled second target container is scheduled to the node with the first sequence number.
[0130] Furthermore, if all unscheduled second target containers are scheduled to the node with the first sequence number, then all the second target containers are scheduled, and the scheduling of the second target containers ends.
[0131] Alternatively, if the resources of the first sequence number node are fully occupied, the second sequence number node is taken from the first list, and the remaining containers in the unscheduled second target container are scheduled to the second sequence number node. If the second target container is still not scheduled, the third sequence number node is taken from the first list, and the steps of scheduling the second target container to the second sequence number node are repeated until all the second target containers are scheduled.
[0132] The resource scheduling method for a container cluster provided in an embodiment of the present invention schedules an unscheduled second target container to a second node with a larger total resource amount until all second target containers are scheduled. This can further reduce resource fragmentation generated during the resource scheduling process, save scheduling time, improve resource scheduling efficiency, and reduce cluster resource scheduling costs.
[0133] The resource scheduling device for a container cluster provided by the present invention is described below. The resource scheduling device for a container cluster described below and the resource scheduling method for a container cluster described above can be referenced to each other.
[0134] Figure 3 Schematic diagram of the structure of the resource scheduling device of the container cluster provided by the embodiment of the present invention. Figure 3 As shown, the resource scheduling device of the container cluster includes: a sorting unit 300, a first scheduling unit 301 and a second scheduling unit 302, wherein:
[0135] A sorting unit 300 is configured to obtain resource requirements of target containers, sort the target containers in a first preset order based on the resource requirements of the target containers, use a first preset proportion of the sorted target containers as first target containers, and use the remaining target containers as second target containers;
[0136] A first scheduling unit 301 is configured to schedule the first target container to a first node based on a first fit FirstFit algorithm;
[0137] A second scheduling unit 302 is configured to schedule the second target container to the first node based on an improved genetic algorithm;
[0138] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0139] The resource scheduling device for a container cluster provided by an embodiment of the present invention obtains the resource demand of the target container, sorts the target containers according to a first preset order based on the resource demand of the target container, uses a first preset proportion of the sorted target containers as the first target container, and uses the remaining target containers as the second target container, schedules the first target container to the first node based on the first adaptation FirstFit algorithm, and schedules the second target container to the first node based on the improved genetic algorithm. It can quickly iterate and converge, avoid blind convergence direction, realize batch scheduling of containers, optimize the cluster resource allocation method, reduce resource fragmentation generated in the resource scheduling process, save scheduling time, improve resource scheduling efficiency, and reduce cluster resource scheduling costs.
[0140] Optionally, the second scheduling unit 302 is configured to:
[0141] Initialize a population, where each individual in the population is a first node on which a first target container has been deployed;
[0142] Calculating the fitness of the first node, where the fitness of the first node is related to the remaining resources of the first node, and the smaller the remaining resources of the first node, the higher the fitness of the first node;
[0143] All individuals in the population are sorted from largest to smallest according to fitness, and the first target node and the second target node are selected from the second preset proportion of individuals in the lower sort order according to the roulette wheel algorithm;
[0144] Performing cross processing on the first target node and the second target node based on a greedy algorithm, and scheduling the second target container based on the cross processing result;
[0145] When all scheduling of the second target container is completed, or the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
[0146] Optionally, performing cross processing on the first target node and the second target node based on a greedy algorithm, and scheduling the second target container based on a cross processing result, specifically includes:
[0147] Acquire third target containers on the first target node and the second target node, and sort the third target containers according to a second preset order based on resource requirements, where the third target container is at least one container in the first target containers;
[0148] Scheduling the sorted third target container to the first target node and the second target node respectively based on a greedy algorithm to obtain at least one scheduling mode, and determining the fitness of the first target node and the second target node in each scheduling mode;
[0149] Based on the fitness of the first target node and the second target node in each scheduling mode, using the objective function to calculate the objective function value of the at least one scheduling mode, if the objective function value of the at least one scheduling mode is lower than the objective function value before the crossover, reselecting the first target node and the second target node, otherwise retaining the scheduling mode with the higher objective function value;
[0150] Determine a target node with a lower fitness in a scheduling mode with a higher objective function value, and schedule the second target container to the target node.
[0151] Optionally, the objective function is specifically:
[0152] ψ(n1, n2) = (g(n1) - g(n2))2 (1)
[0153] Wherein, ψ(n1, n2) represents the variance of the fitness of the first target node and the fitness of the second target node, n1 represents the first target node, n2 represents the second target node, g(n1) represents the fitness of the first target node, and g(n2) represents the fitness of the second target node.
[0154] Optionally, the method of scheduling the sorted third target container to the first target node and the second target node based on a greedy algorithm to obtain at least one scheduling mode specifically includes:
[0155] Scheduling the sorted third target container to the first target node, and when resources of the first target node are fully occupied, scheduling the remaining containers in the sorted third target container to the second target node;
[0156] Alternatively, the sorted third target container is scheduled to the second target node, and when resources of the second target node are fully occupied, the remaining containers in the sorted third target container are scheduled to the first target node.
[0157] Optionally, the first scheduling unit 301 is further configured to:
[0158] Obtaining resource ratios of the first target container and the first node respectively;
[0159] If the resource ratio of the first target container and the resource ratio of the first node meet a preset condition, scheduling the first target container to the first node;
[0160] Among them, the preset condition is: 0≤I c1 / I r1 -I c2 / I r2 ≤Δk,I c1 / I r1 Indicates the resource ratio of the first target container, I c2 / I r2 Indicates the resource ratio of the first node, I c1 Indicates the CPU resource requirement of the first target container, I r1 Indicates the memory resource requirement of the first target container, I c2 represents the CPU resource requirement of the first node, I r2 represents the memory resource requirement of the first node, and Δk is a second preset threshold.
[0161] Optionally, the resource scheduling device of the container cluster further includes:
[0162] The third scheduling unit is configured to, when the second target container is not fully scheduled, obtain a second node in the cluster, where the second node is at least one node in the cluster on which no container is deployed; sort the second nodes in a third preset order based on the total amount of resources of the second nodes to obtain a first list; take out a first sequence number node from the first list based on the sorting result, and schedule the unscheduled second target container to the first sequence number node; when the resources of the first sequence number node are full, take out a second sequence number node from the first list, and schedule the remaining containers in the unscheduled second target container to the second sequence number node, until the second target container is fully scheduled.
[0163] The resource scheduling device for container clusters provided by the present invention can achieve Figures 1 to 2 The various processes implemented by the method embodiment achieve the same technical effect and are not described here again to avoid repetition.
[0164] Figure 4 An example of a physical structure diagram of an electronic device is shown below. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 may call a computer program in the memory 430 to execute the steps of the resource scheduling method for the container cluster, for example, including:
[0165] Obtaining resource requirements of target containers, sorting the target containers according to a first preset order based on the resource requirements of the target containers, using a first preset proportion of the sorted target containers as first target containers, and using the remaining target containers as second target containers;
[0166] Scheduling the first target container to the first node based on a FirstFit algorithm;
[0167] scheduling the second target container to the first node based on an improved genetic algorithm;
[0168] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0169] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0170] On the other hand, the present invention further provides a computer program product, comprising a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions. When the program instructions are executed by a computer, the computer can execute the resource scheduling method for a container cluster provided by each of the above methods, the method comprising:
[0171] Obtaining resource requirements of target containers, sorting the target containers according to a first preset order based on the resource requirements of the target containers, using a first preset proportion of the sorted target containers as first target containers, and using the remaining target containers as second target containers;
[0172] Scheduling the first target container to the first node based on a FirstFit algorithm;
[0173] scheduling the second target container to the first node based on an improved genetic algorithm;
[0174] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0175] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, wherein the computer program is configured to cause the processor to execute the methods provided in the above embodiments, for example, including:
[0176] Obtaining resource requirements of target containers, sorting the target containers according to a first preset order based on the resource requirements of the target containers, using a first preset proportion of the sorted target containers as first target containers, and using the remaining target containers as second target containers;
[0177] Scheduling the first target container to the first node based on a FirstFit algorithm;
[0178] scheduling the second target container to the first node based on an improved genetic algorithm;
[0179] The target container includes at least two containers, and the first node includes at least one node in a cluster.
[0180] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO)), optical storage (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (such as ROMs, EPROMs, EEPROMs, non-volatile memories (NANDFLASH), solid-state drives (SSDs)), etc.
[0181] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0182] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0183] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A resource scheduling method for a container cluster, characterized in that: include: Obtaining resource requirements of target containers, sorting the target containers according to a first preset order based on the resource requirements of the target containers, using a first preset proportion of the sorted target containers as first target containers, and using the remaining target containers as second target containers; Scheduling the first target container to the first node based on a FirstFit algorithm; scheduling the second target container to the first node based on an improved genetic algorithm; The target container includes at least two containers, and the first node includes at least one node in a cluster; Scheduling the second target container to the first node based on the improved genetic algorithm specifically includes: Initialize a population, where each individual in the population is a first node on which a first target container has been deployed; Calculating the fitness of the first node, where the fitness of the first node is related to the remaining resources of the first node, and the smaller the remaining resources of the first node, the higher the fitness of the first node; All individuals in the population are sorted from largest to smallest according to fitness, and the first target node and the second target node are selected from the second preset proportion of individuals in the lower sort order according to the roulette wheel algorithm; Perform cross processing on the first target node and the second target node based on a greedy algorithm, and schedule the second target container based on the cross processing result; When all scheduling of the second target container is completed, or the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
2. The resource scheduling method for a container cluster according to claim 1, characterized in that: The cross-processing of the first target node and the second target node based on the greedy algorithm, and scheduling the second target container based on the cross-processing result, specifically includes: Acquire third target containers on the first target node and the second target node, and sort the third target containers according to a second preset order based on resource requirements, where the third target container is at least one container in the first target containers; Scheduling the sorted third target container to the first target node and the second target node respectively based on a greedy algorithm to obtain at least one scheduling mode, and determining the fitness of the first target node and the second target node in each scheduling mode; Based on the fitness of the first target node and the second target node in each scheduling mode, using the objective function to calculate the objective function value of the at least one scheduling mode, if the objective function value of the at least one scheduling mode is lower than the objective function value before the crossover, reselecting the first target node and the second target node, otherwise retaining the scheduling mode with the higher objective function value; Determine a target node with a lower fitness in a scheduling mode with a higher objective function value, and schedule the second target container to the target node.
3. The resource scheduling method for a container cluster according to claim 2, characterized in that: The objective function is specifically: ψ(n1,n2)=(g(n1)-g(n2)) 2 (1) Wherein, ψ(n1,n2) represents the variance of the fitness of the first target node and the fitness of the second target node, n1 represents the first target node, n2 represents the second target node, g(n1) represents the fitness of the first target node, and g(n2) represents the fitness of the second target node.
4. The resource scheduling method for a container cluster according to claim 2, characterized in that: The method of scheduling the sorted third target container to the first target node and the second target node based on the greedy algorithm to obtain at least one scheduling method specifically includes: Scheduling the sorted third target container to the first target node, and when resources of the first target node are fully occupied, scheduling the remaining containers in the sorted third target container to the second target node; Alternatively, the sorted third target container is scheduled to the second target node, and when resources of the second target node are fully occupied, the remaining containers in the sorted third target container are scheduled to the first target node.
5. The resource scheduling method for a container cluster according to claim 1, characterized in that: Scheduling the first target container to the first node based on the FirstFit algorithm specifically includes: Obtaining resource ratios of the first target container and the first node respectively; If the resource ratio of the first target container and the resource ratio of the first node meet a preset condition, scheduling the first target container to the first node; Among them, the preset condition is: 0≤I c1 / I r1 -I c2 / I r2 ≤Δk,I c1 / I r1 Indicates the resource ratio of the first target container, I c2 / I r2 Indicates the resource ratio of the first node, I c1 Indicates the CPU resource requirement of the first target container, I r1 Indicates the memory resource requirement of the first target container, I c2 represents the CPU resource requirement of the first node, I r2 represents the memory resource requirement of the first node, and Δk is a second preset threshold.
6. The resource scheduling method for a container cluster according to claim 1, characterized in that: Also includes: If the second target container is not fully scheduled, obtain a second node in the cluster, where the second node is at least one node in the cluster on which no container is deployed; sorting the second nodes in a third preset order based on the total amount of resources of the second nodes to obtain a first list; Based on the sorting result, a node with a first sequence number is taken from the first list, and an unscheduled second target container is scheduled to the node with the first sequence number; When the resources of the first sequence number node are fully occupied, the second sequence number node is taken out from the first list, and the remaining containers in the unscheduled second target containers are scheduled to the second sequence number node until all the second target containers are scheduled.
7. A resource scheduling device for a container cluster, characterized in that: include: a sorting unit, configured to obtain resource requirements of target containers, sort the target containers in a first preset order based on the resource requirements of the target containers, use a first preset proportion of the sorted target containers as first target containers, and use the remaining target containers as second target containers; A first scheduling unit is configured to schedule the first target container to the first node based on a FirstFit algorithm; a second scheduling unit, configured to schedule the second target container to the first node based on an improved genetic algorithm; The target container includes at least two containers, and the first node includes at least one node in a cluster; The second scheduling unit is specifically configured to: Initialize a population, where each individual in the population is a first node on which a first target container has been deployed; Calculating the fitness of the first node, where the fitness of the first node is related to the remaining resources of the first node, and the smaller the remaining resources of the first node, the higher the fitness of the first node; All individuals in the population are sorted from largest to smallest according to fitness, and the first target node and the second target node are selected from the second preset proportion of individuals in the lower sort order according to the roulette wheel algorithm; Perform cross processing on the first target node and the second target node based on a greedy algorithm, and schedule the second target container based on the cross processing result; When all scheduling of the second target container is completed, or the number of iterations reaches a first preset threshold, the scheduling of the second target container is terminated.
8. An electronic device comprising a processor and a memory storing a computer program, characterized in that: When the processor executes the computer program, the steps of the resource scheduling method for the container cluster according to any one of claims 1 to 6 are implemented.
9. A processor-readable storage medium, characterized in that: The processor-readable storage medium stores a computer program, and the computer program is used to enable the processor to execute the steps of the resource scheduling method for a container cluster according to any one of claims 1 to 6.
Citation Information
Patent Citations
Genetic-tabu hybrid algorithm based resource scheduling policy method in private cloud environment
CN105550033A
Cloud computing resource allocation method based on improved genetic algorithm
CN110308993A