Pod scheduling method and system based on genetic algorithm

By applying the Pod scheduling method based on genetic algorithm in Kubernetes, the resource waste caused by imbalance in CPU and memory ratio in nodes is solved, and more efficient resource utilization and scheduling accuracy is achieved.

CN115145704BActive Publication Date: 2025-02-07SUZHOU SICUI IND INTERNET TECH RES INST CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210619775.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-02
Publication Date
2025-02-07
Estimated Expiration
2042-06-02

AI Technical Summary

Technical Problem

When considering node resources, the existing Kubernetes Pod scheduling algorithm mainly focuses on the sum of CPU and memory, and fails to effectively utilize the imbalance of CPU and memory ratio in the node, resulting in waste of resources.

Method used

Using the Pod scheduling method based on the genetic algorithm, the CPU and memory requirements of the target Pod are calculated as the ideal value by calculating the proportion of the node's current CPU and memory, and using the genetic algorithm to solve the optimal solution, select the proportion closest to the ideal value. The value is used as the optimal proportional value, and its corresponding node is used as the optimal scheduling node.

Benefits of technology

Effectively utilize the CPU and memory resources of each node in the cluster, avoid excessive CPU or memory surplus and insufficient other resources, improve resource utilization, and improve scheduling efficiency and accuracy through the parallelism and global search of genetic algorithms. sex.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115145704B_ABST
    Figure CN115145704B_ABST
Patent Text Reader

Abstract

The present invention discloses a Pod scheduling method and system based on a genetic algorithm, which belongs to the technical field of kubernetes cluster scheduling. The technical problem to be solved is how to overcome the waste of resources caused by the imbalance of the CPU and memory ratio in the node when scheduling the pod. The following steps are as follows: determine the CPU demand and memory demand of the target pod; filter all nodes based on the filtering method of kubernetes itself, and build a schedulable node set based on all nodes that meet the requirements; calculate the ratio of the current CPU and memory of the node; take the ratio between the CPU demand and the memory demand of the target pod as the ideal value, and based on the ratio value corresponding to each node in the schedulable node set, use the genetic algorithm to solve the optimal solution, and select the ratio value closest to the ideal value as the optimal ratio value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of kubernetes cluster scheduling, and in particular to a Pod scheduling method and system based on a genetic algorithm. Background Art

[0002] Kubernetes is of great significance as a management platform for cloud computing. With the continuous development of cloud computing, Kubernetes has become the cornerstone of cloud native. Kubernetes has become a powerful tool for most Internet companies to simplify operation and maintenance, and is an important supporting technology for cloud computing services. At present, the scheduling of pods in Kubernetes is completed in two steps. The first step is filtering, and the second step is scoring. For filtering: select nodes that meet the preset conditions, such as whether the CPU and memory resources are met, whether the labels are met, etc., and remove nodes that do not meet the conditions. For scoring: score the nodes that pass the filter, and finally select the node with the highest score. If the highest scores are the same, randomly select one from the nodes with the highest score. The scoring algorithm of Kubernetes itself is as follows:

[0003] score=(cpu((capacity-sum(requested))10 / capacity)+

[0004] memory((capacity-sum(requested))10 / capacity)) / 2

[0005] score indicates the result of the scoring, cpu indicates the remaining total CPU capacity, capacity indicates the initial maximum value of the corresponding resource, and sum(requested) indicates the total amount of resources currently allocated to the corresponding resource.

[0006] When the default scheduling algorithm is used for pod scheduling, the main consideration is the sum of the CPU and memory values. It does not take into account that in a node, there may be a small amount of CPU remaining but a large amount of memory remaining, or a large amount of CPU remaining but a small amount of memory remaining, resulting in a waste of resources.

[0007] How to overcome the resource waste caused by the imbalance of CPU and memory ratio in nodes when scheduling pods is a technical problem that needs to be solved. Summary of the invention

[0008] The technical task of the present invention is to address the above shortcomings and provide a Pod scheduling method and system based on a genetic algorithm to solve the technical problem of how to overcome the resource waste caused by the imbalance of the CPU and memory ratio in the node when scheduling the pod.

[0009] In a first aspect, a Pod scheduling algorithm based on a genetic algorithm of the present invention is based on the idea of ​​solving the optimal solution with a genetic algorithm. In the pod scheduling of Kubernetes, a node whose ratio between CPU and memory meets an ideal value is selected as the optimal node. The method comprises the following steps:

[0010] Determine the CPU and memory requirements of the target pod;

[0011] Filter all nodes based on kubernetes' own filtering method, and build a schedulable node set based on all nodes that meet the requirements;

[0012] For each node in the schedulable node set, based on the difference between the current remaining CPU amount of the node and the CPU requirement of the target pod, and the difference between the current remaining memory amount of the node and the memory requirement of the target pod, calculate the ratio of the current CPU and memory of the node, and record it as the ratio value of the node;

[0013] The ratio between the CPU demand and memory demand of the target pod is taken as the ideal value. Based on the ratio value corresponding to each node in the schedulable node set, the genetic algorithm is used to solve the optimal solution. The ratio value closest to the ideal value is selected as the optimal ratio value, and the node corresponding to the optimal ratio value is selected as the optimal node.

[0014] As a preferred method, the genetic algorithm is used to find the optimal solution, and the ratio value closest to the ideal value is selected as the optimal ratio value, including the following steps:

[0015] S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array;

[0016] S200, for each node in the schedulable node set, a chromosome is encoded using a binary encoding method;

[0017] S300, for each node in the schedulable node set, calculating the fitness value of the node, where the fitness value indicates the probability of the node being selected;

[0018] S400, for each node in the schedulable node set, create a corresponding individual based on its chromosome code and fitness value;

[0019] S500, creating P individuals based on step S400, and creating a population based on the P individuals;

[0020] S600, for each individual in the population, calculating the fitness value of the individual, and selecting the individual with the largest fitness value as the best individual in the population;

[0021] The fitness value of the individual is the ratio of the CPU remaining amount to the memory remaining amount in the node. The remaining amount is the interpolation between the current resource remaining amount of the node and the resource requirement of the target pod. The resources correspond to CPU and memory.

[0022] S700, calculating the selection operator of each individual by roulette, wherein the selection operator represents the probability of the individual being selected as the individual with the maximum fitness value, and the individual N i The selection operator F i The calculation formula is:

[0023]

[0024] The F i The value range is [0,1], and the sum of the selection probabilities of all individuals in the population is 1;

[0025] Where P represents the number of individuals in the population, f i Represents the fitness value of an individual;

[0026] S800, based on the selection operator of each individual, calculate the cumulative probability q of each individual i ;

[0027]

[0028] S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If

[0029] q i-1 <X≤q i

[0030] The number of individuals N used by sequence number i i Selected as parent;

[0031] SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation;

[0032] SB00, cross the first parent generation and the second parent generation to obtain offspring;

[0033] SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring;

[0034] SD00, for the P newly generated individuals, randomly select V individuals for mutation;

[0035] V=v×P

[0036] Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population;

[0037] SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f i Greater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ;

[0038] SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod.

[0039] Preferably, the calculation formula of chromosome length is:

[0040] 2 x <N≤2 y

[0041] y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i Indicates that the chromosome is decoded as follows:

[0042]

[0043] Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlice i .

[0044] As a preference, the fitness value f of the node numbered i i The calculation formula is:

[0045]

[0046] r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when f i Indicates the fitness value of the node numbered i;

[0047]

[0048] C i=capacityCPU i -sum(requestedCPU) i -requestCPU

[0049] M i =capacityMemory i -sum(requestedMemory) i -requestMemory

[0050] Among them, C i Indicates the current remaining CPU of the node with sequence number i, M i Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, and requestMemory indicates the memory requirement of the target pod.

[0051] Preferably, the first parent generation and the second parent generation are crossed by a matching crossover algorithm, comprising the following steps:

[0052] Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation;

[0053] The second gene string is copied to the corresponding position in the first parent generation to generate the chromosome of the first child generation, and the second gene string is copied to the corresponding position in the second parent generation to generate the chromosome of the second child generation.

[0054] In a second aspect, a Pod scheduling system based on a genetic algorithm of the present invention is used to execute a Pod scheduling method based on a genetic algorithm as described in any one of the first aspects to select a scheduling node for a pod, the system comprising:

[0055] A target pod confirmation module, which is used to determine the CPU requirement and memory requirement of the target pod;

[0056] A schedulable node set construction module, which is used to filter all nodes based on the filtering method of kubernetes itself, and build a schedulable node set based on all nodes that meet the requirements;

[0057] A ratio value calculation module, for each node in the schedulable node set, the ratio value calculation module is used to calculate the ratio value of the current CPU and memory of the node based on the difference between the current CPU remaining amount of the node and the CPU requirement of the target pod and the difference between the current memory remaining amount of the node and the memory requirement of the target pod, and record it as the ratio value of the node;

[0058] The optimization module is used to take the ratio between the CPU demand and the memory demand of the target pod as the ideal value, and based on the ratio value corresponding to each node in the schedulable node set, use the genetic algorithm to solve the optimal solution, select the ratio value closest to the ideal value as the optimal ratio value, and use the node corresponding to the optimal ratio value as the optimal node.

[0059] Preferably, the optimization module is used to select the ratio value closest to the ideal value as the optimal ratio value based on the idea of ​​solving the optimal solution with a genetic algorithm through the following steps:

[0060] S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array;

[0061] S200, for each node in the schedulable node set, a chromosome is encoded using a binary encoding method;

[0062] S300, for each node in the schedulable node set, calculating the fitness value of the node, where the fitness value indicates the probability of the node being selected;

[0063] S400, for each node in the schedulable node set, create a corresponding individual based on its chromosome code and fitness value;

[0064] S500, creating P individuals based on step S400, and creating a population based on the P individuals;

[0065] S600, for each individual in the population, calculating the fitness value of the individual, and selecting the individual with the largest fitness value as the best individual in the population;

[0066] The fitness value of the individual is the ratio of the CPU remaining amount to the memory remaining amount in the node. The remaining amount is the interpolation between the current resource remaining amount of the node and the resource requirement of the target pod. The resources correspond to CPU and memory.

[0067] S700, calculating the selection operator of each individual by roulette, wherein the selection operator represents the probability of the individual being selected as the individual with the maximum fitness value, and the individual N i The selection operator F i The calculation formula is:

[0068]

[0069] The F i The value range is [0,1], and the sum of the selection probabilities of all individuals in the population is 1;

[0070] Where P represents the number of individuals in the population, f i Represents the fitness value of an individual;

[0071] S800, based on the selection operator of each individual, calculate the cumulative probability q of each individual i ;

[0072]

[0073] S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If

[0074] q i-1 <X≤q i

[0075] The number of individuals N used by sequence number i i Selected as parent;

[0076] SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation;

[0077] SB00, cross the first parent generation and the second parent generation to obtain offspring;

[0078] SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring;

[0079] SD00, for the P newly generated individuals, randomly select V individuals for mutation;

[0080] V=v×P

[0081] Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population;

[0082] SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f i Greater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ;

[0083] SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod.

[0084] Preferably, the calculation formula of chromosome length is:

[0085] 2 x <N≤2 y

[0086] y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i Indicates that the chromosome is decoded as follows:

[0087]

[0088] Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlice i .

[0089] As a preference, the fitness value f of the node numbered i i The calculation formula is:

[0090]

[0091] r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when f i Indicates the fitness value of the node numbered i;

[0092]

[0093] C i =capacityCPU i -sum(requestedCPU) i -requestCPU

[0094] Mi =capacityMemory i -sum(requestedMemory) i -requestMemory

[0095] Among them, C i Indicates the current remaining CPU of the node with sequence number i, M i Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, and requestMemory indicates the memory requirement of the target pod.

[0096] Preferably, the optimization module is used to crossover the first parent generation and the second parent generation through a matching crossover algorithm based on the following steps:

[0097] Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation;

[0098] The second gene string is copied to the corresponding position in the first parent generation to generate the chromosome of the first child generation, and the second gene string is copied to the corresponding position in the second parent generation to generate the chromosome of the second child generation.

[0099] The Pod scheduling method and system based on genetic algorithm of the present invention have the following advantages:

[0100] 1. By controlling the CPU and memory ratio of each node in the cluster, the CPU and memory of the node can be fully utilized. There will be no situation where the CPU has a lot of surplus but the memory is basically used up, or the CPU has been basically used up but the memory has a lot of surplus. CPU and memory resources are fully utilized.

[0101] 2. Find the optimal node based on the idea of ​​genetic algorithm. Genetic algorithm has parallelism and good global search performance, which improves efficiency and accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0102] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0103] The present invention is further described below in conjunction with the accompanying drawings.

[0104] Figure 1 This is a flowchart of a Pod scheduling method based on a genetic algorithm in Example 1;

[0105] Figure 2 This is a flowchart of the idea of ​​solving the optimal solution through the genetic algorithm in the Pod scheduling method based on the genetic algorithm in Example 1, and selecting the ratio value closest to the ideal value as the optimal ratio value;

[0106] Figure 3 This is a block diagram of the matching crossover principle in the Pod scheduling method based on the genetic algorithm in Example 1;

[0107] Figure 4 , Figure 5 and Figure 6 The results are combined into a schematic diagram showing the comparison between the Pod scheduling method based on the genetic algorithm and the Kubernetes scheduling method itself in Example 1. DETAILED DESCRIPTION

[0108] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.

[0109] It should be understood that in the description of the embodiments of the present invention, the words "first", "second", etc. are only used for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order. The "plurality" in the embodiments of the present invention refers to two or more.

[0110] The embodiment of the present invention provides a Pod scheduling method and system based on a genetic algorithm, which is used to solve the technical problem of how to overcome the resource waste caused by the imbalance of the CPU and memory ratio in the node when scheduling the pod.

[0111] Embodiment 1:

[0112] The present invention provides a Pod scheduling algorithm based on a genetic algorithm, which is characterized in that based on the idea of ​​solving the optimal solution with the genetic algorithm, a node whose ratio between CPU and memory meets an ideal value is selected as the optimal node in the pod scheduling of Kubernetes. The method comprises the following steps:

[0113] L100, determine the CPU and memory requirements of the target pod;

[0114] L200, filter all nodes based on kubernetes' own filtering method, and build a schedulable node set based on all nodes that meet the requirements;

[0115] L300. For each node in the schedulable node set, based on the difference between the current remaining CPU amount of the node and the CPU requirement of the target pod and the difference between the current remaining memory amount of the node and the memory requirement of the target pod, calculate the ratio of the current CPU and memory of the node, and record it as the ratio value of the node;

[0116] L400. Take the ratio between the CPU demand and the memory demand of the target pod as the ideal value. Based on the ratio value corresponding to each node in the schedulable node set, use the genetic algorithm to solve the optimal solution. Select the ratio value closest to the ideal value as the optimal ratio value, and select the node corresponding to the optimal ratio value as the optimal node.

[0117] In step L300, the current remaining CPU of the node in the schedulable node set minus the CPU requirement of the target pod is calculated, divided by the remaining memory minus the memory requirement of the target pod, to obtain the ratio of the remaining CPU and memory of the node after the target pod is scheduled to the node.

[0118] C i =capacityCPU i -sum(requestedCPU) i -requestCPU;

[0119] M i =capacityMemory i -sum(requestedMemory) i -requestMemory;

[0120]

[0121] Among them, C i Indicates the current remaining CPU of the node with sequence number i, Mi Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, requestMemory indicates the memory requirement of the target pod, i Indicates the ratio of CPU to memory.

[0122] Step L400 uses the idea of ​​genetic algorithm to find the optimal solution, and selects the node in the schedulable set whose ratio value is closest to the ideal ratio value given in this paper. The node corresponding to the selected ratio value is the optimal node.

[0123] As a specific implementation, the specific steps for finding the optimal solution using the idea of ​​genetic algorithm are as follows.

[0124] S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array;

[0125] S200, chromosome encoding, for each node in the schedulable node set, chromosome encoding is performed using binary encoding;

[0126] The genetic algorithm in this embodiment uses binary coding, and the number of nodes is obtained as N through the filtering algorithm of Kubernetes itself, and the length of the chromosome is calculated by the following formula:

[0127] 2 x <N≤2 y

[0128] y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i express;

[0129] The decoding of the chromosome is as follows:

[0130]

[0131] Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlicei . There is a one-to-one correspondence between individuals and nodes in the population;

[0132] S300, calculate the fitness value. The fitness value indicates the probability of each node being selected. The larger the fitness value, the greater the probability of being selected. The fitness value of the node with serial number i is expressed as f i It is expressed as:

[0133]

[0134] r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when f i Indicates the fitness value of the node numbered i;

[0135] S400, creating individuals, creating corresponding individuals based on their chromosome codes and fitness values, and the individuals in the population correspond to the nodes one by one;

[0136] For nodeN with sequence number i i , chromosome DNA is obtained through step S200 i And the fitness f obtained in step S300 i , create individual N i ;

[0137] S500, creating an initial population, repeating step S500 P times to create a population;

[0138] For the population P k , where P represents the number of individuals in the population, k represents the generation of population evolution, the generation k value of the initial population is 1, and there are P randomly generated individuals in the population P1;

[0139] S600, select the best individual, for each individual in the population, calculate the fitness value of the individual, and select the individual with the largest fitness value as the best individual N in the population best ;

[0140] The fitness value of an individual is the ratio of the remaining CPU and the remaining memory in the node. The remaining amount is the interpolation between the current remaining resource of the node and the resource requirement of the target pod. The resources correspond to CPU and memory.

[0141] S700, calculating a selection operator, the purpose of the selection operator is to select individual genes with large fitness, select individuals with large fitness from the parent population for reproduction (crossover) to obtain the next generation of individuals, and improve the convergence speed of the genetic algorithm;

[0142] This paper adopts the roulette method to select individuals. The meaning of roulette is that the individual N in the population i The fitness value of the population is divided by the sum of the fitness values ​​of all individuals in the population to obtain a probability F between 0 and 1. i , the sum of the probabilities of all individuals being selected is 1.

[0143]

[0144] F i represents the selection operator of individuals, and P represents the number of individuals in the population;

[0145] Step S08: Calculate the cumulative probability of each individual as q i :

[0146]

[0147] The total probability of each individual being selected is 1;

[0148] S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If

[0149] q i-1 <X≤q i

[0150] The number of individuals N used by sequence number i i Selected as parent;

[0151] For example: the probability F1 of N1 is 0.1, and the probability F2 of N2 is 0.2, then the cumulative probability q1 of N1 is 0.1, and the cumulative probability q2 of N1 is 0.3.

[0152] q1=F1

[0153] q2=F1+F2

[0154] If the random number X is 0.15, individual N2 is selected as the parent;

[0155] SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation;

[0156] SB00, : The parent chromosomes cross over to generate offspring;

[0157] The crossover operator is one of the most important processes in the genetic algorithm. The chromosomes of individuals reproduce the next generation through crossover. The excellent genes of the parents can be guaranteed through selection operations and fitness functions. Then, the offspring are generated through crossover to enrich the diversity of the population. There are many ways to crossover. This embodiment adopts a partial matching crossover operator, such as Figure 3 As shown;

[0158] SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring;

[0159] SD00, for the P newly generated individuals, randomly select V individuals for mutation;

[0160] V=v×P

[0161] Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population;

[0162] SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f i Greater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ;

[0163] SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod.

[0164] The best individual is selected and decoded to find the corresponding node, which is the optimal scheduling node for the target pod.

[0165] As a specific implementation, SB00 crosses the first parent generation and the second parent generation through a matching crossover algorithm, including the following steps:

[0166] (1) Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation;

[0167] (2) Copying the second gene string to the corresponding position in the first parent generation to generate the chromosome of the first offspring, and copying the second gene string to the corresponding position in the second parent generation to generate the chromosome of the second offspring.

[0168] The method of this embodiment controls the CPU and memory ratio of each node in the cluster so that the CPU and memory of the node are fully utilized. There will be no situation where the CPU still has a lot of surplus but the memory is basically used up, or the CPU is basically used up but the memory still has a lot of surplus. The CPU and memory resources are fully utilized, and the optimal node is found based on the idea of ​​genetic algorithm. The genetic algorithm has parallelism and good global search performance.

[0169] As shown in the comparison chart Figure 4-Figure 6 As shown, assume that the optimal ratio of CPU to node in node is 0.2. The unit of CPU is C, and the unit of memory is G. Assume that there are three nodes that pass the filtering algorithm of kubernetes itself, the initial value of CPU of each node is 12C, the initial value of memory is 60G, the current remaining amount of resources of each node and the ratio of the current remaining CPU to memory are r, f represents the fitness value of each node in the genetic algorithm, and score represents the score of each node in the algorithm of kubernetes itself, such as Figure 1 As shown. It can be seen from the figure that the maximum fitness value of node1 is 100, so the node closest to the ideal ratio calculated by the genetic algorithm is node1. The target pod is scheduled to node1. After the target pod is scheduled to node1, the remaining CPU in node1 is 2C, the remaining memory is 10.5G, and the remaining ratio of CPU to memory is 0.19. Through the scoring function of kubernetes itself, the highest score of node3 is 3.75. The target pod is scheduled to node3. After the target pod is scheduled to node3, the remaining CPU in node3 is 1C, the remaining memory is 24G, and the remaining CPU to memory ratio is 0.042. Through the above analysis, when the default scoring function of kubernetes is used for scoring, after the target pod is scheduled to node3, the remaining CPU in node3 is only 1C, but the remaining memory is still 24G. There is a lack of CPU resources, but there is still a lot of remaining memory, resulting in a waste of resources. By giving an ideal ratio and using a genetic algorithm to select the node whose remaining CPU and memory ratio is closest to the ideal ratio after the target pod is scheduled to the node, the ratio between the CPU and memory in the node is as close to the ideal ratio as possible, avoiding the situation where one of the CPU and memory resources has little remaining but the other has a lot remaining.

[0170] Embodiment 2:

[0171] The present invention discloses a Pod scheduling system based on a genetic algorithm, comprising a target pod confirmation module, a schedulable node set construction module, a ratio value calculation module and an optimization module. The system can execute a Pod scheduling method based on a genetic algorithm disclosed in Example 1 to select a scheduling node for a pod.

[0172] The target pod confirmation module is used to determine the CPU and memory requirements of the target pod.

[0173] The schedulable node set construction module is used to filter all nodes based on kubernetes' own filtering method and build a schedulable node set based on all nodes that meet the requirements.

[0174] For each node in the schedulable node set, the ratio value calculation module is used to calculate the ratio of the current CPU and memory of the node based on the difference between the current CPU remaining amount of the node and the CPU requirement of the target pod and the difference between the current memory remaining amount of the node and the memory requirement of the target pod, which is recorded as the ratio value of the node.

[0175] The ratio value calculation module calculates the current CPU remaining amount of the node in the schedulable node set minus the CPU requirement of the target pod and divides it by the memory remaining amount minus the memory requirement of the target pod to obtain the ratio value of the remaining CPU and memory of the node after the target pod is scheduled to the node.

[0176] C i =capacityCPU i -sum(requestedCPU) i -requestCPU;

[0177] M i =capacityMemory i -sum(requestedMemory) i -requestMemory;

[0178]

[0179] Among them, C i Indicates the current remaining CPU of the node with sequence number i, M i Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, requestMemory indicates the memory requirement of the target pod, i Indicates the ratio of CPU to memory.

[0180] The optimization module is used to take the ratio between the CPU demand and memory demand of the target pod as the ideal value. Based on the ratio value corresponding to each node in the schedulable node set, the genetic algorithm is used to solve the optimal solution, and the ratio value closest to the ideal value is selected as the optimal ratio value. The node corresponding to the optimal ratio value is selected as the optimal node.

[0181] As a specific implementation, the optimization module uses the idea of ​​genetic algorithm to find the optimal solution through the following steps:

[0182] S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array;

[0183] S200, chromosome encoding, for each node in the schedulable node set, chromosome encoding is performed using binary encoding;

[0184] The genetic algorithm in this embodiment uses binary coding, and the number of nodes is obtained as N through the filtering algorithm of Kubernetes itself, and the length of the chromosome is calculated by the following formula:

[0185] 2 x <N≤2 y

[0186] y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i express;

[0187] The decoding of the chromosome is as follows:

[0188]

[0189] Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlice i . There is a one-to-one correspondence between individuals and nodes in the population;

[0190] S300, calculate the fitness value. The fitness value indicates the probability of each node being selected. The larger the fitness value, the greater the probability of being selected. The fitness value of the node with serial number i is expressed as f i It is expressed as:

[0191]

[0192] r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when fi Indicates the fitness value of the node numbered i;

[0193] S400, creating individuals, creating corresponding individuals based on their chromosome codes and fitness values, and the individuals in the population correspond to the nodes one by one;

[0194] For nodeN with sequence number i i , chromosome DNA is obtained through step S200 i And the fitness f obtained in step S300 i , create individual N i ;

[0195] S500, creating an initial population, repeating step S500 P times to create a population;

[0196] For the population P k , where P represents the number of individuals in the population, k represents the generation of population evolution, the generation k value of the initial population is 1, and there are P randomly generated individuals in the population P1;

[0197] S600, select the best individual, for each individual in the population, calculate the fitness value of the individual, and select the individual with the largest fitness value as the best individual N in the population best ;

[0198] The fitness value of an individual is the ratio of the remaining CPU and the remaining memory in the node. The remaining amount is the interpolation between the current remaining resource of the node and the resource requirement of the target pod. The resources correspond to CPU and memory.

[0199] S700, calculating a selection operator, the purpose of the selection operator is to select individual genes with large fitness, select individuals with large fitness from the parent population for reproduction (crossover) to obtain the next generation of individuals, and improve the convergence speed of the genetic algorithm;

[0200] This paper adopts the roulette method to select individuals. The meaning of roulette is that the individual N in the population i The fitness value of the population is divided by the sum of the fitness values ​​of all individuals in the population to obtain a probability F between 0 and 1. i , the sum of the probabilities of all individuals being selected is 1.

[0201]

[0202] F i represents the selection operator of individuals, and P represents the number of individuals in the population;

[0203] Step S08: Calculate the cumulative probability of each individual as q i :

[0204]

[0205] The total probability of each individual being selected is 1;

[0206] S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If

[0207] q i-1 <X≤q i

[0208] The number of individuals N used by sequence number i i Selected as parent;

[0209] For example: the probability F1 of N1 is 0.1, and the probability F2 of N2 is 0.2, then the cumulative probability q1 of N1 is 0.1, and the cumulative probability q2 of N1 is 0.3.

[0210] q1=F1

[0211] q2=F1+F2

[0212] If the random number X is 0.15, individual N2 is selected as the parent;

[0213] SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation;

[0214] SB00, : The parent chromosomes cross over to generate offspring;

[0215] The crossover operator is one of the most important processes in the genetic algorithm. The chromosomes of individuals reproduce the next generation through crossover. The excellent genes of the parents can be guaranteed through selection operations and fitness functions. Then, the offspring are generated through crossover to enrich the diversity of the population. There are many ways to crossover. This embodiment adopts a partial matching crossover operator, such as Figure 3 As shown;

[0216] SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring;

[0217] SD00, for the P newly generated individuals, randomly select V individuals for mutation;

[0218] V=v×P

[0219] Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population;

[0220] SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f iGreater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ;

[0221] SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod.

[0222] The best individual is selected and decoded to find the corresponding node, which is the optimal scheduling node for the target pod.

[0223] As a specific implementation, the module crosses the first parent and the second parent through the matching crossover algorithm through the following steps:

[0224] (1) Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation;

[0225] (2) Copying the second gene string to the corresponding position in the first parent generation to generate the chromosome of the first offspring, and copying the second gene string to the corresponding position in the second parent generation to generate the chromosome of the second offspring.

[0226] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.

Claims

1. A Pod scheduling method based on genetic algorithm, characterized in that Based on the idea of ​​solving the optimal solution with genetic algorithm, in Kubernetes pod scheduling, a node whose ratio between CPU and memory meets the ideal value is selected as the optimal node. The method includes the following steps: Determine the CPU and memory requirements of the target pod; Filter all nodes based on kubernetes' own filtering method, and build a schedulable node set based on all nodes that meet the requirements; For each node in the schedulable node set, based on the difference between the current remaining CPU amount of the node and the CPU requirement of the target pod, and the difference between the current remaining memory amount of the node and the memory requirement of the target pod, calculate the ratio of the current CPU and memory of the node, and record it as the ratio value of the node; The ratio between the CPU demand and memory demand of the target pod is taken as the ideal value. Based on the ratio value corresponding to each node in the schedulable node set, the genetic algorithm is used to solve the optimal solution. The ratio value closest to the ideal value is selected as the optimal ratio value, and the node corresponding to the optimal ratio value is selected as the optimal node. The idea of ​​solving the optimal solution through genetic algorithm is to select the ratio value closest to the ideal value as the optimal ratio value, including the following steps: S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array; S200, for each node in the schedulable node set, a chromosome is encoded using a binary encoding method; S300, for each node in the schedulable node set, calculating the fitness value of the node, where the fitness value indicates the probability of the node being selected; S400, for each node in the schedulable node set, create a corresponding individual based on its chromosome code and fitness value; S500, creating P individuals based on step S400, and creating a population based on the P individuals; S600, for each individual in the population, calculating the fitness value of the individual, and selecting the individual with the largest fitness value as the best individual in the population; The fitness value of the individual is the ratio of the CPU remaining amount to the memory remaining amount in the node. The remaining amount is the interpolation between the current resource remaining amount of the node and the resource requirement of the target pod. The resources correspond to CPU and memory. S700, calculating the selection operator of each individual by roulette, wherein the selection operator represents the probability of the individual being selected as the individual with the maximum fitness value, and the individual N i The selection operator F i The calculation formula is: The F i The value range is [0,1], and the sum of the selection probabilities of all individuals in the population is 1; Where P represents the number of individuals in the population, f i Represents the fitness value of an individual; S800, based on the selection operator of each individual, calculate the cumulative probability q of each individual i ; S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If q i-1 <X≤q i The number of individuals N used by sequence number i i Selected as parent; SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation; SB00, cross the first parent generation and the second parent generation to obtain offspring; SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring; SD00, for the P newly generated individuals, randomly select V individuals for mutation; V=v×P Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population; SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f i Greater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ; SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod; The fitness value f of the node numbered i i The calculation formula is r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when f i Indicates the fitness value of the node numbered i; C i =capacityCPU i -sum(requestedCPU) i -requestCPU M i =capacityMemory i -sum(requestedMemory) i -requestMemory Among them, C i Indicates the current remaining CPU of the node with sequence number i, M i Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, and requestMemory indicates the memory requirement of the target pod.

2. The Pod scheduling method based on genetic algorithm according to claim 1 is characterized in that The formula for calculating chromosome length is: 2 x <N≤2 y y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i Indicates that the chromosome is decoded as follows: Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlice i .

3. The Pod scheduling method based on genetic algorithm according to claim 1 is characterized in that The first parent and the second parent are crossed by a matching crossover algorithm, including the following steps: Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation; The second gene string is copied to the corresponding position in the first parent generation to generate the chromosome of the first child generation, and the second gene string is copied to the corresponding position in the second parent generation to generate the chromosome of the second child generation.

4. A Pod scheduling system based on genetic algorithm, characterized by A system for selecting a scheduling node for a pod by executing a Pod scheduling method based on a genetic algorithm as described in any one of claims 1 to 3, the system comprising: A target pod confirmation module, which is used to determine the CPU requirement and memory requirement of the target pod; A schedulable node set construction module, which is used to filter all nodes based on the filtering method of kubernetes itself, and build a schedulable node set based on all nodes that meet the requirements; A ratio value calculation module, for each node in the schedulable node set, the ratio value calculation module is used to calculate the ratio value of the current CPU and memory of the node based on the difference between the current CPU remaining amount of the node and the CPU requirement of the target pod and the difference between the current memory remaining amount of the node and the memory requirement of the target pod, and record it as the ratio value of the node; An optimization module, which is used to take the ratio between the CPU demand and the memory demand of the target pod as the ideal value, and based on the ratio value corresponding to each node in the schedulable node set, use a genetic algorithm to solve the optimal solution, select the ratio value closest to the ideal value as the optimal ratio value, and select the node corresponding to the optimal ratio value as the optimal node; The optimization module is used to select the ratio value closest to the ideal value as the optimal ratio value based on the idea of ​​solving the optimal solution by genetic algorithm through the following steps: S100, for N nodes in the schedulable node set, sort all nodes in ascending order according to the current remaining CPU amount of the node to obtain an array; S200, for each node in the schedulable node set, a chromosome is encoded using a binary encoding method; S300, for each node in the schedulable node set, calculating the fitness value of the node, where the fitness value indicates the probability of the node being selected; S400, for each node in the schedulable node set, create a corresponding individual based on its chromosome code and fitness value; S500, creating P individuals based on step S400, and creating a population based on the P individuals; S600, for each individual in the population, calculating the fitness value of the individual, and selecting the individual with the largest fitness value as the best individual in the population; The fitness value of the individual is the ratio of the CPU remaining amount to the memory remaining amount in the node. The remaining amount is the interpolation between the current resource remaining amount of the node and the resource requirement of the target pod. The resources correspond to CPU and memory. S700, calculating the selection operator of each individual by roulette, wherein the selection operator represents the probability of the individual being selected as the individual with the maximum fitness value, and the individual N i The selection operator F i The calculation formula is: The F i The value range is [0,1], and the sum of the selection probabilities of all individuals in the population is 1; Where P represents the number of individuals in the population, f i Represents the fitness value of an individual; S800, based on the selection operator of each individual, calculate the cumulative probability q of each individual i ; S900, generate a random number X in the interval [0,1] as a pointer for roulette selection. If q i-1 <X≤q i The number of individuals N used by sequence number i i Selected as parent; SA00, repeat step S900 twice to obtain two parent generations, namely the first parent generation and the second parent generation; SB00, cross the first parent generation and the second parent generation to obtain offspring; SC00, repeating steps S900 to SB00 for a total of P times, obtaining P individuals as offspring; SD00, for the P newly generated individuals, randomly select V individuals for mutation; V=v×P Among them, V represents the number of individuals that produce mutations, v represents the probability of mutation, and P represents the size of the population; SE00, repeat steps SA00-SD00 to create the next generation population, calculate the fitness value of each individual, if the fitness value of the offspring individual is f i Greater than the optimal individual N best The fitness value of the offspring is taken as the optimal individual N best ; SF00, repeat steps S700 and SD00, iterate G times until P is generated. G Generation population, from the P G The best individual is selected from the population, and the best individual N best The corresponding node is the optimal scheduling node for the target pod; The fitness value f of the node numbered i i The calculation formula is: r i It indicates the ratio of CPU and memory of node number i after scheduling pod, z indicates the ratio of CPU and memory in target node, and M indicates when f i Indicates the fitness value of the node numbered i; C i =capacityCPU i -sum(requestedCPU) i -requestCPU M i =capacityMemory i -sum(requestedMemory) i -requestMemory Among them, C i Indicates the current remaining CPU of the node with sequence number i, M i Indicates the remaining amount of memory in the node with sequence number i, where capacityCPU i Indicates the initial maximum CPU usage of the node with sequence number i, sum(requestedCPU) i Indicates the total amount of CPU currently allocated, requestCPU indicates the CPU demand of the target Pod, capacityMemory i Indicates the initial maximum memory size of the node with sequence number i, sum(requestedMemory) i Indicates the total amount of memory currently allocated, and requestMemory indicates the memory requirement of the target pod.

5. The Pod scheduling system based on genetic algorithm according to claim 4 is characterized in that The formula for calculating chromosome length is: 2 x <N≤2 y y represents the length of the chromosome, so an array of length y is created, with values ​​of 1 or 0 in the array, and the chromosome of the node with sequence number i is represented by DNA i Indicates that the chromosome is decoded as follows: Indicates that the individual of this chromosome corresponds to the node N with the subscript i in the slice NodeSlice i .

6. The Pod scheduling system based on genetic algorithm according to claim 4 is characterized in that The optimization module is used to crossover the first parent generation and the second parent generation through a matching crossover algorithm based on the following steps: Two crossover points are randomly generated in the first parent generation and the second parent generation, and the number of genes in the two crossover points is equal, which are divided into the first gene string and the second gene string as the crossover operation; The second gene string is copied to the corresponding position in the first parent generation to generate the chromosome of the first child generation, and the second gene string is copied to the corresponding position in the second parent generation to generate the chromosome of the second child generation.

Citation Information

Patent Citations

  • Optimization method for kubernetes cloud platform configuration based on genetic algorithm

    CN112631612A

  • Kubernetes Pod scheduling method based on cost effectiveness

    CN113946429A