Automatic scaling method, device, computer storage medium and program product
By using fractional-order PID controllers and data preprocessing techniques in Kubernetes, the problems of response lag and over-tuning in existing technologies are solved, enabling precise scaling of Pods and stable resource management, thereby improving the system's responsiveness and resource utilization efficiency.
Patent Information
- Application Number
- CN202611508297.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-24
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, Kubernetes' auto-scaling and scaling methods are slow to respond, unable to predict sudden traffic surges, and over-adjustment leads to resource fluctuations and waste. Furthermore, they lack a historical error smoothing mechanism, resulting in low resource utilization and service unavailability.
By adopting a target replica number decision formula based on a fractional-order PID controller, combined with outlier removal and moving average filtering, and by acquiring Pod metric data in Kubernetes, the FOPID controller is deeply integrated into the Kubernetes control plane to achieve automatic scaling of Pods, avoiding over-adjustment and resource waste.
It achieves accurate prediction and stable adjustment of the number of replicas, reduces resource fluctuations, improves resource utilization and service availability, and can quickly respond to sudden traffic surges.
Smart Images

Figure CN123157451A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cloud computing technology, and in particular to an automatic scaling method, device, computer storage medium, and program product. Background Technology
[0002] In existing technologies, the main approach is proportional control, which automatically scales up and down by dynamically adjusting the number of replicas. However, because it uses a purely reactive model and relies on real-time indicator thresholds to trigger scaling up and down, the response is severely delayed and cannot predict sudden traffic surges. Moreover, existing solutions are sensitive to short-term noise and lack a historical error smoothing mechanism, which can lead to resource fluctuations and waste due to over-adjustment. Summary of the Invention
[0003] This application provides an automatic scaling method, apparatus, computer storage medium, and program product.
[0004] The technical solution of this application is implemented as follows: This application provides an automatic scaling method, the method comprising: Retrieve metric data for multiple Pods currently managed by the target controller in Kubernetes; Based on the metric data and target metric values of the multiple Pods, determine the current metric error value; The current index error value is processed using the target replica number decision formula based on a fractional-order PID controller to obtain the replica adjustment amount; The target number of replicas is determined based on the replica adjustment amount and the total number of Pods currently managed by the target controller; Scaling up or down is performed based on the target number of replicas.
[0005] This application provides an electronic device, the device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the automatic scaling method provided by one or more of the foregoing technical solutions.
[0006] This application provides a computer storage medium storing a computer program; when the computer program is executed, it can implement the automatic scaling method provided by one or more of the aforementioned technical solutions.
[0007] This application provides a computer program product, including a computer program that, when executed by a processor, implements the automatic scaling method provided by one or more of the aforementioned technical solutions.
[0008] This application provides an automatic scaling method, which involves: acquiring metric data of multiple Pods currently managed by a target controller in Kubernetes; determining a current metric error value based on the metric data of the multiple Pods and a target metric value; processing the current metric error value using a target replica number decision formula based on a fractional-order PID controller to obtain a replica adjustment amount; determining a target replica number based on the replica adjustment amount and the total number of Pods currently managed by the target controller; and performing scaling processing based on the target replica number.
[0009] As can be seen, in this embodiment, after determining the current indicator error value based on the indicator data of multiple Pods currently managed by the target controller, the target replica number decision formula based on the FOPID controller is used to process the current indicator error value and determine the replica adjustment amount; that is, the FOPID controller is deeply integrated into the Kubernetes control plane to realize the automatic scaling of Pods. Since the target replica number decision formula based on the FOPID controller includes fractional integral operators and differential operators, the fractional integral operator can smooth long-term historical indicator errors and avoid resource oscillations and waste caused by over-adjustment, while the fractional differential operator can accurately capture the subtle changing trend of indicator errors, predict sudden traffic, and avoid response lag; thus, accurate prediction and stable adjustment of the replica number can be achieved. Attached Figure Description
[0010] Figure 1 A flowchart illustrating an automatic expansion / shrinkage method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the composition structure of an automatic expansion and contraction system provided in an embodiment of this application; Figure 3 This is a schematic diagram of the composition structure of the FOPID decision layer provided in an embodiment of this application; Figure 4 This is a schematic diagram of the composition structure of the parameter optimization layer provided in the embodiments of this application; Figure 5 This is a schematic diagram of the composition structure of the execution layer provided in an embodiment of this application; Figure 6 This is a schematic diagram of the composition structure of the state storage layer provided in an embodiment of this application; Figure 7 This is a schematic diagram of the composition structure of an automatic expansion and contraction device provided in an embodiment of this application; Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0011] The technical solutions in this application will now be clearly and completely described with reference to the accompanying drawings.
[0012] The present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the embodiments provided herein are merely illustrative of the present application and are not intended to limit the present application. Furthermore, the embodiments provided below are some embodiments for implementing the present application, and not all embodiments for implementing the present application. Unless otherwise specified, the technical solutions described in the present application can be implemented in any combination.
[0013] It should be noted that, in this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a method or apparatus that includes a list of elements includes not only the elements expressly described, but also other elements not expressly listed, or elements inherent to implementing the method or apparatus. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other related elements (e.g., steps in the method or units in the apparatus, such as portions of a processor, program, or software, etc.) in the method or apparatus that includes that element.
[0014] For example, the automatic scaling method provided in this application includes a series of steps, but the automatic scaling method provided in this application is not limited to the steps described. Similarly, the automatic scaling device provided in this application includes a series of modules, but the automatic scaling device provided in this application is not limited to the modules explicitly described, but may also include modules that need to be set up for obtaining relevant information or processing based on the information.
[0015] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0016] Kubernetes, or k8s for short, is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. A Pod is the smallest unit of deployment in k8s, used to host and run actual applications, and is also the smallest unit of scheduling in k8s.
[0017] Currently, Kubernetes Horizontal Pod Autoscaler (HPA) primarily employs a proportional control strategy, dynamically adjusting the number of replicas using the following formula: Replica count decision formula:
[0018] in, The rounding up symbol, For the desired number of replicas, This represents the current number of replicas. Current metric values, such as Central Processing Unit (CPU) utilization. The target threshold is set. The control process includes the following steps: 1) Metrics collection: Collect Pod resource data, such as CPU or memory.
[0019] 2) Decision calculation: The HPA controller compares the current indicator value with the target threshold and calculates the expected number of replicas.
[0020] 3) Replica adjustment: Modify the replicas field of controllers such as Deployment to trigger Pod scaling up or down.
[0021] 4) Cooling mechanism: The default cooling time for shrinking capacity is 5 minutes (to avoid frequent oscillations), and the cooling time for expanding capacity is 3 minutes.
[0022] Based on the analysis of automatic scaling technology, existing solutions (such as native HPA proportional control and traditional PID control) have the following shortcomings: 1) Severe response lag, unable to predict sudden traffic: Existing technology adopts a pure reactive model, which relies on real-time indicator thresholds to trigger scaling up and down. From the time the indicator exceeds the threshold to the Pod being ready, there is a collection delay (15-30 seconds), scheduling delay, and Pod initialization (1-5 minutes), with a cumulative delay of several minutes. Under sudden traffic (such as e-commerce promotions), the service queue is backed up, the request delay is greater than 500ms, and the service is highly unavailable.
[0023] 2) Over-adjustment leads to resource fluctuations and waste: Traditional HPA uses proportional control, which is sensitive to short-term noise and lacks a historical error smoothing mechanism.
[0024] 3) Noise sensitivity leads to a high rate of misoperation: Traditional differential terms Amplifying high-frequency disturbances and causing brief fluctuations in CPU utilization (less than 1 second) can trigger an increase in the number of replicas and an increase in the error rate.
[0025] 4) It is difficult to balance resource efficiency with Service Level Agreements (SLAs). Static parameters cannot dynamically respond to changes in the scenario. The fixed 5-minute scaling-down cooldown time leads to high resource idle rates during low-load periods. Scaling down too early will also cause service degradation (such as session interruption) and low resource utilization.
[0026] Based on the above-mentioned technical problems, the following embodiments are proposed.
[0027] In some embodiments of this application, the automatic scaling method can be implemented using a processor in an automatic scaling device. The processor can be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a CPU, a controller, a microcontroller, or a microprocessor.
[0028] It should be noted that the collection, use, storage, sharing and transfer of user personal information involved in the technical solution of this application all comply with the provisions of relevant laws and regulations, and require notification to users and obtaining their consent or authorization. Where applicable, user personal information has been subjected to de-identification and / or anonymization and / or encryption technical processing.
[0029] Figure 1 This is a flowchart illustrating an automatic scaling method provided in an embodiment of this application, as shown below. Figure 1 As shown, the method includes the following steps: Step 100: Obtain metric data for the multiple Pods currently managed by the target controller in Kubernetes.
[0030] In this embodiment of the application, the Prometheus component can be used to obtain metric data of multiple Pods currently managed by the target controller in Kubernetes.
[0031] Here, the target controller can be any controller built into Kubernetes, and its type is not limited. For example, it can be a Deployment controller or a StatefulSet controller. The following explanation will use the Deployment controller as an example.
[0032] For example, the metric data may include the metric values of container-level metrics and the metric values of custom metrics; wherein, container-level metrics refer to the resource usage metrics of the container, which may include metrics such as CPU utilization, memory utilization, and network input / output (I / O); custom metrics refer to application-level metrics accessed through the Prometheus Adapter, which may include metrics such as Queries Per Second (QPS) and request latency.
[0033] For example, the container-level metrics of each Pod currently managed by the target controller can be captured through the cAdvisor built into kubele. The Prometheus component pulls the container-level metrics of each Pod from the kubelet of each node and aggregates them to obtain the metric values of the container-level metrics of multiple Pods.
[0034] For example, the Prometheus component can periodically obtain the metric data of each metric Pod according to a preset sampling period; here, there is no specific limitation on the value of the sampling period, which can be a value between 0.5s and 5s, for example, it can be 1s.
[0035] In some embodiments, the above method may further include: preprocessing the metric data of each Pod to obtain preprocessed metric data.
[0036] In this embodiment of the application, after obtaining the metric data of each Pod currently managed by the target controller, the metric data can be preprocessed to obtain preprocessed metric data.
[0037] For example, preprocessing may include outlier removal and moving average filtering; in an optional embodiment, outlier removal may be performed on the metric data of each Pod to obtain intermediate metric data; then, moving average filtering may be performed on the intermediate metric data to obtain preprocessed metric data.
[0038] For example, it can be utilized The criteria remove outliers from the indicator data; for example, for a given indicator, the mean of the 30 most recently collected indicator values can be maintained. with standard deviation The newly collected index values fall within [ Points outside the baseline mean are identified as outliers. Replace the outlier while retaining the sampling time location; do not delete the point on the timeline.
[0039] For example, after removing outliers to obtain intermediate index data, the intermediate index data can be further filtered by moving average; correspondingly, the intermediate index data with outliers removed is arithmetically averaged according to a preset window to obtain preprocessed index data.
[0040] Here, the size of the preset window can be dynamically adjusted according to the volatility of the indicator. There is no specific limitation here. For example, the preset window for the CPU utilization indicator can be 5 points, and the preset window for the network I / O indicator can be 3 points.
[0041] Understandably, the reason for performing outlier removal before moving average filtering is that if moving average filtering is performed first, outliers will enter the averaging window and pollute the entire window's output. Furthermore, after filtering, individual anomalies are diluted and difficult to trigger. Outlier removal.
[0042] As can be seen from the embodiments of this application, by removing outliers from the obtained metric data of each Pod, it is possible to prevent spikes from triggering erroneous expansion or contraction; by using moving average filtering, the metric curve can be made smoother, reducing frequent adjustments caused by normal fluctuations and lowering the probability of oscillation.
[0043] Step 101: Determine the current metric error value based on the metric data and target metric values of multiple Pods.
[0044] In one optional embodiment, after obtaining the metric data of multiple Pods, the current metric error value can be determined based on the metric data of multiple Pods and the target metric value. In another optional embodiment, after obtaining the preprocessed metric data of multiple Pods, the current metric error value can be determined based on the preprocessed metric data of multiple Pods and the target metric value. The process of determining the current metric error value is similar in both embodiments, and the process of determining the current metric error value will be explained below using the first case as an example.
[0045] For example, the metrics data for each Pod may include the values of multiple metrics. For instance, suppose the Deployment controller currently manages three Pods, namely Pod1, Pod2 and Pod3, where the CPU utilization of Pod1, Pod2 and Pod3 is 85%, 75% and 60% respectively, and the memory utilization of Pod1, Pod2 and Pod3 is 70%, 65% and 50% respectively.
[0046] In some embodiments, determining the current metric error value based on the metric data of multiple Pods and the target metric value may include: weighting the metric values of the same metric in different Pods according to the weights corresponding to each of the multiple Pods to obtain a weighted average value for each metric; weighting the weighted average value of multiple metrics according to the weights corresponding to each of the multiple metrics to obtain a weighted metric value; and determining the current metric error value based on the weighted metric value and the target metric value.
[0047] Here, the weights of each Pod and each metric can be preset according to the actual situation. No specific restrictions are made here. For example, assuming that the Deployment controller currently manages Pod1, Pod2 and Pod3, and each Pod includes two metrics: CPU utilization and memory utilization, the weights of Pod1, Pod2 and Pod3 can be preset to 0.5, 0.3 and 0.2 respectively; and the weights of CPU utilization and memory utilization can be preset to 0.7 and 0.3 respectively.
[0048] For example, since the metric data for each Pod includes the values of multiple metrics, after obtaining the metric data for multiple Pods, the metric values of the same metric in different Pods can be weighted according to the weights corresponding to each Pod, to obtain the weighted average of each metric, as shown in the following formula:
[0049] in, This is the weighted average of the metrics, where N is the number of Pods; Let be the metric value of a certain metric for the i-th Pod; Let be the weight corresponding to the i-th Pod.
[0050] For example, assuming the weights of Pod1, Pod2, and Pod3 are 0.5, 0.3, and 0.2 respectively, and their CPU utilization rates are 85%, 75%, and 60%, respectively, and their memory utilization rates are 70%, 65%, and 50%, respectively, then substituting these values into the formula above yields the weighted average of CPU utilization. =(0.5×85%+0.3×75%+0.2×60%)=77%, the weighted average of memory usage. =(0.5×70%+0.3×65%+0.2×50%)=64.5%.
[0051] For example, after obtaining the weighted average of each indicator, the weighted average of multiple indicators can be weighted according to the weights corresponding to each indicator, to obtain the weighted indicator value; the corresponding formula is as follows:
[0052] in, The weighted index value. and These are the respective weights for CPU utilization and memory utilization.
[0053] For example, assuming the weights for CPU utilization and memory utilization are set to 0.7 and 0.3 respectively, the weighted average of CPU utilization... The weighted average of memory usage is 77%. If the value is 64.5%, then substituting it into the above formula, we can obtain the weighted index value. =0.7×77%+0.3×64.5%=73.25%.
[0054] In this embodiment of the application, after obtaining the weighted index value Then, the weighted index value can be calculated. Subtract the target value The difference is determined as the current indicator error value. The corresponding formula is as follows:
[0055] Here, the target indicator value It is obtained by weighting the target thresholds of multiple indicators, and the weights of each indicator are the same as the weights of the indicators used in calculating the weighted indicator value; for example, assuming the target threshold for CPU utilization is 80% and the target threshold for memory utilization is 70%, then the target indicator value is... =0.7×80%+0.3×70%=77%; if the weighted index value =73.25%, then the corresponding current indicator error value is =73.25%-77%= 3.75%; at this point, the overall underload is 3.75%.
[0056] Step 102: Use the target replica number decision formula based on the fractional-order PID controller to process the current index error value and obtain the replica adjustment amount.
[0057] In this embodiment of the application, after obtaining the current index error value according to the above steps, the current index error value can be processed using the target replica number decision formula based on a fractional order PID controller (FOPID) to obtain the replica adjustment amount. Here, the target replica number decision formula can be obtained by processing a pre-constructed initial replica number decision formula, and the process is illustrated below.
[0058] In some embodiments, the above method may further include: constructing an initial replica number decision formula based on a fractional-order PID controller; the initial replica number decision formula includes a proportional term, a fractional-order integral term, and a fractional-order derivative term, wherein the fractional-order integral term includes an integral operator, and the fractional-order derivative term includes a derivative operator; calculating the weight coefficients of the integral operator and the derivative operator using the GL (Grünwald-Letnikov) discretization method; using their respective weight coefficients to perform weighted summation on the index error value sequence within a preset time window to obtain the discretized integral operator and the discretized derivative operator; and determining the target replica number decision formula based on the fractional-order integral term including the discretized integral operator, the fractional-order derivative term including the discretized derivative operator, and the proportional term.
[0059] For example, an initial replica number decision formula based on a fractional-order PID controller can be constructed first. This initial replica number decision formula includes a proportional term, a fractional-order integral term, and a fractional-order derivative term. The fractional-order integral term includes an integral operator, and the fractional-order derivative term includes a differential operator. The proportional term, fractional-order integral term, and fractional-order derivative term each have their own adjustable parameters, as shown in the following formula:
[0060] in, This is a proportional term, and it has an adjustable parameter of... ; It is a fractional integral term with an adjustable parameter of . and , For integration operators; It is a fractional differential term with an adjustable parameter of and , It is a differential operator.
[0061] The differential operator in the initial replica number decision formula can be immediately obtained. pass Subtle trends in order prediction metric error, pre-starting Pods, can significantly shorten automatic scaling time; integral operator by The order smooths out the accumulation of historical errors, avoiding resource fluctuations and waste caused by over-adjustment.
[0062] In this embodiment of the application, after obtaining the above-mentioned initial replica number decision formula, the GL discretization method can be used to discretize the initial replica number decision formula to obtain the target replica number decision formula.
[0063] For example, the discretization process may include: calculating the weight coefficients of the integral operator and the differential operator using the GL discretization method; using their respective weight coefficients to perform weighted summation on the index error value sequence within a preset time window to obtain the discretized integral operator and the discretized differential operator; and determining the target replica number decision formula based on the fractional integral term of the discretized integral operator, the fractional differential term of the discretized differential operator, and the proportional term.
[0064] The mathematical properties of fractional operators are described using the Riemann-Liouville definition, which is difficult to implement directly. In engineering implementation, the GL discretization method can be used to directly map them into code; GL weight coefficients... It is the core of fractional calculus calculations. Its theoretical value is the generalized binomial coefficient. The weight recursive formula can be derived by using the recursive property of the Gamma function, and then used to calculate the weight coefficients of the fractional integral term and the fractional differential term. The corresponding formulas are as follows:
[0065]
[0066] in, The value can be or ; when the value is At that time, the weighting coefficients of the integral operator can be obtained. ; when the value is At that time, the weighting coefficients of the differential operator can be obtained. .
[0067] For example, after obtaining the weight coefficients of the integral operator and the differential operator, the weight coefficients of the integral operator can be used to perform a weighted summation on the index error value sequence within a preset time window to obtain the discretized integral operator; the weight coefficients of the differential operator can be used to perform a weighted summation on the index error value sequence within a preset time window to obtain the discretized differential operator; here, the index error value sequence within the preset time window may include the index error values at the current time and the most recent historical time period; the value of the most recent historical time period can be determined according to the actual situation, for example, it can be the most recent 2 minutes.
[0068] For example, after obtaining the discretized integral operator and discretized differential operators Then, they can be multiplied by their respective adjustable parameters. , This yields the fractional integral term including the discretized integral operator and the fractional differential term including the discretized differential operator. Adding these two terms to the proportional term gives the target replica number decision formula, as shown below:
[0069] Where n is the index of the current discrete time step, representing the nth sampling point (t=n Ts, where Ts is the sampling period for the indicator data, and as mentioned above, its value can be 1 second. The discretized integral operator; The differential operator is discretized; N is the number of index error values within the preset time window. The selection of N depends on the sampling time Ts and the main time constant of the system. There is no specific limitation here. For example, N=120 can be set. When N=120 and Ts=1 second, it corresponds to the time window of the most recent 2 minutes. This represents the historical offset. k=0 represents the current moment, k=1 represents the previous moment, such as one second ago, and so on.
[0070] In this embodiment, after obtaining the target replica number decision formula based on the fractional-order PID controller according to the above steps, the target replica number decision formula can be used to process the current index error value to obtain the replica adjustment amount; correspondingly, the obtained current index error value can be... Substituting into the target replica number decision formula above, we obtain the replica adjustment amount. .
[0071] Understandably, using the GL discretization method to discretize fractional integral operators and fractional differential operators can more precisely characterize the historical accumulation trend of errors and predict future changes. Among them, fractional integral operators can smooth long-term errors and avoid the overshoot risk of integer integrals; fractional differential operators can more accurately capture the subtle changing trend of errors, and in pulse flow scenarios, they can quickly respond to load fluctuations and suppress overshoot, making the scaling decisions more in line with the nonlinear characteristics of the actual load.
[0072] It should be noted that the adjustable parameter in the target replica count decision formula... , , , and The approach employs a combination of preset initial values and online adjustment using Proximal Policy Optimization (PPO), rather than fixed values. In other words, the target replica count decision formula initially uses the initial values of these adjustable parameters, and these updated values are then used after subsequent PPO updates. The initial values of these adjustable parameters are not specifically limited; for example, they can be set to... =3.0、 =0.3、 =0.2, λ=0.7, μ=0.3.
[0073] In some embodiments, the proportional term, fractional integral term, and fractional derivative term in the target replica number decision formula have their own adjustable parameters, corresponding to the aforementioned adjustable parameters. , , , and The above method may further include: periodically acquiring Kubernetes runtime status data, constructing a state space vector using the runtime status data; processing the state space vector using a PPO-based reinforcement learning policy network to obtain the adjustment amount of the adjustable parameters, and updating the adjustable parameters according to the adjustment amount; acquiring the runtime effect data corresponding to the updated adjustable parameters, processing the runtime effect data using a target reward function to obtain the reward value corresponding to the updated adjustable parameters; and optimizing the reinforcement learning policy network using the reward value.
[0074] In this embodiment, Kubernetes runtime status data can be acquired periodically; this period is equivalent to the optimization period of the adjustable parameters; here, the value of this period is not specifically limited, for example, it can be 5 minutes or 10 minutes, etc.
[0075] For example, runtime status parameters may include core characteristic data that reflects the runtime status of Kubernetes. No specific limitations are imposed here; for instance, they may include the current metric error value. Error change rate And SLA default rate, here, the current indicator error value Real-time metric error is the difference between the target metric value and the actual metric value. For example, target CPU utilization of 80% - actual CPU utilization of 75% = 5%; error change rate. It can reflect the trend of error changes; the SLA default rate can measure service quality, and the corresponding formula is as follows:
[0076] Among them, I( ) is the indicator function, and T is the duration of the statistical window.
[0077] For example, a state space vector can be constructed using runtime state data, and can be represented by the following formula:
[0078] For example, after obtaining the state space vector Then, a PPO-based reinforcement learning policy network can be used to process the state space vector to obtain the adjustment amount of the adjustable parameters, and the adjustable parameters can be updated according to the adjustment amount. Here, the output of the reinforcement learning policy network is the adjustment amount of the adjustable parameters, which is equivalent to the action space, and is expressed by the following formula:
[0079] in, , , , and These are adjustable parameters. , , , and The adjustment amount.
[0080] For example, after obtaining the adjustment amount of the adjustable parameters, the adjustable parameters can be updated according to the adjustment amount; and the running effect data corresponding to the updated adjustable parameters in the next optimization cycle can be obtained. The running effect data can be processed using the target reward function to obtain the reward value corresponding to the updated adjustable parameters; and the reward value can be used to optimize the reinforcement learning policy network.
[0081] Here, the target reward function can be preset and is the objective function of PPO. This function guides parameter optimization by punishing negative behaviors, and the corresponding formula is as follows:
[0082] in, Scaling deviation represents the difference between the target number of replicas and the actual number of replicas; the larger the deviation, the heavier the penalty. The level of CPU overload can be quantified, for example, by the percentage of time the CPU usage is greater than 90%. The more severe the overload, the heavier the penalty. The SLA default rate represents the percentage of service delays exceeding a threshold; the more frequent the defaults, the heavier the penalty. , and This represents the weight of each item; it can be set to a default value, for example, it can be set to... It can also be adjusted according to business priorities; the negative sign indicates the reward value. The smaller the value, the worse the behavior; the target reward function should allow the reward value to... The larger the penalty, the smaller the punishment.
[0083] For example, after obtaining the reward value corresponding to the adjustable parameter. Afterwards, the reward value can be used. The reinforcement learning policy network is optimized, and the optimized reinforcement learning policy network is used for the next round of parameter updates.
[0084] Understandably, existing parameter tuning largely relies on manual presets or fixed rules, making it impossible to dynamically adjust according to business load. This application's embodiment introduces PPO reinforcement learning to achieve parameter self-optimization. It constructs a state space using real-time error, error change rate, and SLA default rate, and uses the adjustment amount of adjustable parameters as the action space. Combined with a multi-objective penalty-type reward function addressing scaling deviation, CPU overload, and SLA default, the algorithm automatically explores the optimal parameter combination. This eliminates the need for manual parameter exhaustiveness, adapts to the load characteristics of different businesses (such as high-latency sensitive businesses and high-resource-utilization businesses), continuously optimizes parameters during long-term operation, and improves the system's adaptability to complex scenarios.
[0085] It should be noted that, during PPO online adjustment, adjustable parameters can be preset to avoid parameter anomalies. , , , and The limiting step size and constraint interval can be set, for example, the limiting step size can be set to ΔKp∈[ 0.5,+0.5]、ΔKi∈[ 0.2,+0.2]、ΔKd∈[ 0.1, +0.1], Δλ∈[-0.05, +0.05], Δμ∈[-0.03, +0.03]; set the constraint intervals as Kp∈[0.5, 8], Ki∈[0, 1], Kd∈[0, 1], λ∈[0.1, 0.9], μ∈[0.1, 0.5]. For fractional integral terms, an anti-windup limit can also be set to prevent the replica adjustment amount from exceeding the remaining expandable quota.
[0086] As can be seen, in this embodiment, the PPO reinforcement learning algorithm is used as the core. By sensing the running status of Kubernetes, the amount of output parameter adjustment, and receiving reward value feedback, the adjustable parameters of the proportional term, fractional integral term, and fractional derivative term in the target replica number decision formula are automatically optimized. This ensures that the target replica number decision formula can adapt to different load scenarios and balance scaling accuracy, resource utilization, and SLA compliance rate.
[0087] Step 103: Determine the target number of replicas based on the replica adjustment amount and the total number of Pods currently managed by the target controller.
[0088] In this embodiment of the application, after obtaining the replica adjustment amount corresponding to the current indicator error value according to the above steps, the target number of replicas can be determined together based on the replica adjustment amount and the total number of Pods currently managed by the target controller.
[0089] In some embodiments, determining the target number of replicas based on the replica adjustment amount and the total number of Pods currently managed by the target controller may include: summing the replica adjustment amount and the total number of Pods currently managed by the target controller to obtain the summed replica number; rounding the summed replica number up to obtain the rounded replica number; determining a safe boundary interval for the replica number; and performing constraint optimization on the rounded replica number within the safe boundary interval to obtain the target replica number.
[0090] For example, the replica adjustment amount can be positive, negative, or a decimal. After obtaining the replica adjustment amount, it can be summed with the total number of Pods currently managed by the target controller, and then the summed replica number can be rounded up. For example, assuming the total number of Pods currently managed by the target controller is 4, and the calculated replica adjustment amount is +1.3, then after summing and rounding up, the summed replica number can be determined to be 6. In another embodiment, the replica adjustment amount can also be rounded up first, and then summed with the total number of Pods currently managed by the target controller.
[0091] For example, the security boundary range can include a lower limit and an upper limit, which can be represented as [Nmin, Nmax]. The lower limit Nmin can be preset according to the actual situation to ensure continuous service during rolling updates and avoid single points of service. There is no specific limitation here. For example, it can be set to a value greater than or equal to 2. The upper limit Nmax is dynamically adjusted according to the actual available resources of Kubernetes. It can be understood that dynamically calculating a reasonable maximum replica limit based on the actual available resources of the current cluster can prevent blind expansion of containers from exhausting node resources.
[0092] For example, the limit Nmax can be dynamically calculated using the node's allocable CPU and the Pod's request CPU, as shown in the following formula:
[0093] Node Allocatable CPU represents the total amount of CPU that a node can allocate. It is not the total number of physical CPUs on the node, but rather the total amount of CPU actually available for Pods after subtracting the resources reserved by system components (such as Kubelet and operating system). Pod Request CPU represents the amount of CPU resources requested by each Pod. This is defined in the Kubernetes Pod configuration and represents the minimum amount of CPU that the container is guaranteed to obtain.
[0094] In this embodiment of the application, the purpose of using the squeeze principle to constrain and optimize the rounded replica number within the safety boundary interval is to ensure that the final target replica number is obtained. To improve the safety of the expansion and contraction process while always staying within the range of [Nmin, Nmax], the following formula can be used for constraint optimization:
[0095] It should be noted that if the target number of replicas after the squeeze is the same as the current number of replicas, then there is no need to perform this scaling up / down process. In this case, the current control cycle will end directly.
[0096] Step 104: Perform scaling up or down processing based on the target number of replicas.
[0097] In this embodiment of the application, after obtaining the target number of replicas according to the above steps, scaling up or down can be performed based on the target number of replicas.
[0098] In some embodiments, scaling up or down based on the target number of replicas may include: determining the absolute value of the error change rate based on the current indicator error value; determining the cooldown time based on the absolute value of the error change rate; determining whether the time interval between the current time point and the last scaling up or down time point is greater than or equal to the cooldown time; and performing scaling up or down based on the target number of replicas if the time interval is determined to be greater than or equal to the cooldown time.
[0099] Here, no specific limitation is made on the method for determining the absolute value of the error change rate. For example, the absolute value of the error change rate can be obtained by subtracting the index error value at a certain historical time from the index error value at the current time and then dividing by the time interval. Alternatively, linear regression fitting or other methods can be used to determine it. No specific limitation is made here.
[0100] For example, after obtaining the absolute value of the error rate of change, the cooling time can be determined based on the absolute value of the error rate of change. To achieve more accurate expansion and contraction processing, the cooling time can be determined by combining a piecewise function, and the corresponding formula is as follows:
[0101] in, The absolute value of the rate of change of error. This refers to the cooling time.
[0102] Based on the above formula, it can be seen that when the absolute value of the error change rate is large ( When the system experiences drastic fluctuations (e.g., flow rate doubling every second), setting the cooling time to 1 second allows the system to respond more quickly and perform the next scaling up / down operation to keep up with the changes; when the absolute value of the error rate of change is small ( If the system is very stable, set the cooling time to 300 seconds to avoid unnecessary frequent checks and meaningless scaling up and down operations, allowing the system to run stably; otherwise, set the cooling time to 60 seconds.
[0103] In this embodiment of the application, after determining the cooling time according to the above formula, it is further determined whether the time interval between the current time point and the last expansion / shrinkage time point is greater than or equal to the cooling time; if the time interval is determined to be greater than or equal to the cooling time, expansion / shrinkage processing is performed according to the target number of replicas.
[0104] For example, if the time interval is greater than or equal to the cooldown duration, the number of replicas (replicas field) of the Deployment controller can be dynamically modified via the Kubernetes API to perform scaling up or down operations.
[0105] As can be seen, in this embodiment of the application, the absolute value of the error change rate is determined based on the current index error value in order to dynamically adjust the cooling time. This can prevent the expansion and contraction operations from being too frequent, avoid the system from oscillating violently when the index fluctuates (for example, frequently expanding and then immediately contracting), and improve the system stability.
[0106] It should be noted that a sharp drop in traffic also meets the criteria. The 1-second fast channel is entered at that time, but fast only refers to the evaluation frequency, not to rapid and large-scale reduction; the reduction direction is protected by four special measures: (1) Single-step amplitude limit: the change in the number of replicas per cycle satisfies |ΔN|≤max(1, 0.1• (2) Additional cooling for volume reduction: The cooling time in the volume reduction direction is taken as max( The asymmetric design of ,30s) means that after each scaling down, at least 30s must be waited before the next scaling down can be carried out. This can reduce the frequency of scaling down decisions and avoid scaling down errors; (3) Emptying and budget constraints: The execution layer Pod management module calls the PreStop hook and terminationGracePeriodSeconds to wait for the in-transit requests to complete, and follows the PodDisruptionBudget (PDB) limit on the number of concurrent offlines; In the cloud computer session affinity scenario, the Pod where the active session is located is tagged, and the scaling down prioritizes the Pod with zero active connections; (4) Closed-loop self-healing: If the SLA default rate increases after scaling down, the error turns positive again and triggers back-expansion. The SLA-related penalty terms in the reward function R drive the parameter optimization layer to converge to a more conservative parameter combination, and subsequent scaling down will be more cautious.
[0107] In this embodiment, the automatic scaling method can be applied to an automatic scaling system. See [link to relevant documentation]. Figure 2 The system may include a data acquisition layer 20, an FOPID decision layer 21, a parameter optimization layer 22, an execution layer 23, a state storage layer 24, and a service carrying layer 25.
[0108] For example, the service delivery layer 25 is used to provide metric data for each Pod; the data acquisition layer 20 uses the Prometheus component to collect metric data (CPU / QPS / request latency) of multiple Pods currently managed by the target controller in Kubernetes at a collection cycle of 1 second; the FOPID decision layer 21 is used to determine the current metric error value based on the collected metric data of multiple Pods and the target metric value; the current metric error value is processed using the target replica number decision formula based on the fractional PID controller to obtain the replica adjustment amount; the target replica number is determined based on the replica adjustment amount and the total number of Pods currently managed by the target controller; the parameter optimization layer 22 is used to generate the adjustment amount (ΔKp / ΔKi, etc.) of the adjustable parameters through the reinforcement learning policy network and update the adjustable parameters; the execution layer 23 sends the target replica number output by the FOPID decision layer 21 to the Kubernetes API Server, through the Deployment Controller to the ReplicaSet, and performs scaling processing to adjust the number of Pods in the service delivery layer 25. The state storage layer 24 can adopt a Redis hierarchical storage architecture. Redis can use the TimeSeries module to store the sequence of index error values within a preset time window and feed it back to the FOPID decision layer 21 to calculate the discretized integral operator and the discretized differential operator.
[0109] For example, the TimeSeries module of Redis's hierarchical storage architecture can store data in tiers based on retention periods. For instance, hot sequences (retention = 5 minutes, 300 points) rebuild a 120-point error queue after a FOPID decision layer 21 restart (cold start recovery, avoiding decision gaps) and PPO state feature statistics, with read / write operations at the second level. Warm sequences (retention = 1 hour, 3600 points) serve PPO experience playback and FOPID parameter effect backtracking, with batch reads at the minute level and without occupying 1 second of online path space. During normal operation, FOPID's GL calculation only uses the 120-point (2-minute) error queue in the State Manager (SM) memory. The Redis hot sequence serves as the data source for fault-tolerant recovery paths and PPO feature statistics. The two levels of retention are declared separately by TS.CREATE.
[0110] Understandably, existing state storage solutions often employ a single-structure storage or polling-based data interaction, resulting in high data read / write latency or insufficient utilization of historical data. In this embodiment, a layered state storage is adopted. RedisTimeSeries is specifically designed for real-time time-series data, supporting millisecond-level writes and low-latency range queries to ensure the response speed of FOPID real-time calculation. A hash structure persists FOPID parameter logs and SLA default records, providing sufficient historical training data for PPO. Simultaneously, each layer is decoupled through standardized interfaces: FOPID focuses on real-time decision-making, PPO is responsible for long-term parameter optimization, the execution layer ensures command delivery, and the state storage acts as a data hub, forming a strong closed loop of collection, decision-making, optimization, execution, and feedback. This achieves a better balance between response speed, resource utilization, and SLA compliance, resulting in more stable performance under complex dynamic loads.
[0111] In this embodiment of the application, the automatic scaling system includes the following processing flow: (1) Metric data collection and preprocessing: The data collection layer uses the Prometheus component to collect metric data of multiple Pods currently managed by the target controller in Kubernetes at a collection cycle of 1 second and performs preprocessing. (2) Calculation of indicator error value: The current indicator error value e(t) is obtained by subtracting the target indicator value from the preprocessed indicator data output by the data acquisition layer (de / dt is calculated synchronously). The calculation of the current indicator error value is performed before the calculation of the integral operator and the differential operator, providing input for them; e(t) is combined with the indicator error value sequence fed back by Redis, and the target replica number decision formula is used to output the replica adjustment amount, and the target replica number is determined based on the replica adjustment amount and the total number of Pods currently managed by the target controller; (3) Execution adjustment: The target replica number output from the FOPID decision layer will adjust the number of Pods through the APIServer of the K8s Client, generate new Pod generation indicator data, and send it back to Prometheus to complete the control loop; (4) Parameter optimization: The state features such as e(t) and de / dt output by the FOPID decision layer are combined with the index error value sequence within the preset time window and trained by the PPO Agent to output the adjustment amount of the adjustable parameters (ΔKp / ΔKi, etc.), update the adjustable parameters, and complete the parameter optimization closed loop.
[0112] In this embodiment, the FOPID decision layer focuses on real-time error calculation, fractional operator calculation, and replica number decision. The FOPID decision layer can complete the core control logic from indicators to instructions through sub-module division of labor.
[0113] For example, Figure 3 This is a schematic diagram of the composition structure of the FOPID decision layer provided in the embodiments of this application, as shown below. Figure 3 As shown, the FOPID decision layer may include an error processing module 30, a fractional-order operator module 31, a parameter management module 32, and a decision output module 33; wherein, the error processing module 30 is used to calculate the current index error value. The error change rate de / dt is calculated, and the error range is verified and filtered. The fractional operator module 31 is used to calculate fractional integral and differential operators, which can rely on the index error value sequence within a preset time window to complete the discretization of the operators. The parameter management module 32 is used to maintain adjustable parameters. , , , and It also receives the adjustment amount parameters of the adjustable parameters determined by the parameter optimization layer to update the adjustable parameters; the decision output module 33 is used to calculate the target number of replicas and output scaling instructions to the execution layer.
[0114] For example, the FOPID decision layer may include the following processing flow: determining the current metric error value based on the metric data of each Pod obtained by Prometheus, inputting the current metric error value into the target replica number decision formula based on the FOPID controller, and obtaining the replica adjustment amount. Long-term historical error feedback is introduced. The TimeSeries module in the Redis hierarchical storage architecture stores the sequence of metric error values, such as error data with two levels of retention: the past 5 minutes (hot sequence, service FOPID restart state reconstruction) and 1 hour (warm sequence, service PPO experience playback), to avoid short-term fluctuations affecting decision-making. Regarding short-term historical error feedback, the state manager inside the FOPID decision layer maintains the sequence of metric error values for the most recent 120 seconds in memory for quickly calculating the error change rate de / dt, supporting the sensitivity of FOPID real-time adjustments. FOPID outputs control commands to the execution layer to implement scaling operations. Error feedback storage: FOPID uses the state manager (SM) and Redis to store the real-time calculated current metric error value e(t) in short-term cache and long-term storage, providing historical metric error value input for the next round of FOPID calculation, completing the feedback loop.
[0115] It can be seen that the PPO Agent not only outputs parameters to the FOPID decision layer, but also receives the current index error value e(t) and error change rate de / dt from the FOPID decision layer as the basis for evaluating whether the current FOPID parameters are optimal, and then dynamically adjusts the adjustable parameters to form a parameter optimization feedback loop.
[0116] In this embodiment, the parameter optimization layer uses the PPO reinforcement learning algorithm as its core. By sensing the running status of Kubernetes, outputting parameter adjustment amounts, and receiving reward value feedback, it automatically optimizes the adjustable parameters of the proportional term, fractional integral term, and fractional derivative term in the target replica number decision formula. This ensures that the target replica number decision formula can adapt to different load scenarios and balance scaling accuracy, resource utilization, and SLA compliance rate.
[0117] For example, Figure 4 This is a schematic diagram of the composition structure of the parameter optimization layer provided in the embodiments of this application, as shown below. Figure 4As shown, the parameter optimization layer may include a data preprocessing module 40, a policy network module 41, a reward calculation module 42, and a parameter update module 43. Specifically, the data preprocessing module 40 reads runtime state data from the state storage layer to construct a state space vector; the policy network module 41 processes the state space vector using a PPO-based reinforcement learning policy network to obtain the adjustment amount of the adjustable parameters; the reward calculation module 42 calculates the reward value R based on SLA achievement rate, scaling deviation, etc., providing feedback signals for policy optimization; and the parameter update module 43 optimizes the reinforcement learning policy network using the reward value, updates the adjustable parameters according to the adjustment amount, and pushes them to the FOPID decision layer.
[0118] For example, the parameter optimization layer and the FOPID decision layer engage in real-time closed-loop interaction. The interaction process may include: state acquisition, whereby the parameter optimization layer obtains e(t) and de / dt from the error processing module of the FOPID decision layer, and obtains from the state storage layer... This forms a state space vector; Action execution: The parameter optimization layer outputs the adjustment amount of the adjustable parameters, which is then updated through the parameter management module of the FOPID decision layer; Reward feedback: After the FOPID decision layer executes the new parameters, the parameter optimization layer obtains the reward from the execution layer. , Retrieved from the state storage layer Calculate the reward value R, which will be used for the next round of optimization.
[0119] In this embodiment, the execution layer is located between the FOPID decision layer and Kubernetes. It is responsible for converting the target replica count output by the FOPID decision layer into actual Pod scaling operations and providing real-time feedback on the execution results to ensure that the decision instructions are implemented and effective. Its core objectives are: to efficiently execute scaling instructions, accurately track operation status, and provide real-time feedback on the actual replica count, thus supporting the integrity of the entire control loop.
[0120] For example, Figure 5 This is a schematic diagram of the composition structure of the execution layer provided in the embodiments of this application, as shown below. Figure 5 As shown, the execution layer may include a K8s API interaction module 50, a controller linkage module 51, and a Pod management module 52. These modules work together to complete the entire process from receiving instructions to receiving status feedback. Specifically, the K8s API interaction module is used to call the K8s Scale API and send scaling requests for the target number of replicas. The controller linkage module 51 is used to connect to the target controller, such as a Deployment controller or a ReplicaSet controller, and track the execution status of scaling operations. The Pod management module 52 is used to monitor the lifecycle of each Pod (creation, destruction, readiness, etc.) and provide feedback on the actual number of replicas to the upper-layer modules.
[0121] In this embodiment, the state storage layer serves as the system's data hub, responsible for persistently storing real-time monitoring data (such as errors and replica counts), historical decision data (such as FOPID parameter logs), and parameter optimization training data. It also provides data support to the FOPID decision-making layer and parameter optimization layer through standardized interfaces. The core objectives are: to capture and store key indicators of the FOPID decision-making process in real time; to retain historical data long-term to provide training material for reinforcement learning in parameter optimization; and to ensure low latency and high reliability for data read / write operations, supporting the real-time nature of the control loop.
[0122] For example, Figure 6 This is a schematic diagram of the composition structure of the state storage layer provided in the embodiments of this application, as shown below. Figure 6 As shown, the state storage layer may include a time-series data storage module 60, a historical data management module 61, and a read / write interface module 62, which work together to complete the entire process of data storage, management, and distribution; among them, the time-series data storage module 60 is used for storage of the Redis-based TimeSeries module. , , Time-series metrics; Historical data management module 61 is used to persist FOPID parameter logs, SLA default records, and provide a batch historical data query interface; Read / write interface module 62 is used to expose data read / write APIs to the outside world, connecting to the FOPID decision layer (write in real time, read in history) and parameter optimization layer (read in history).
[0123] As can be seen, the automatic scaling system constructed in this application includes data processing flows such as FOPID decision-making, PPO parameter optimization, hierarchical state storage, and efficient execution. It solves the problem of insufficient adaptation of traditional PID to nonlinear loads by integrating fractional calculus (using the GL discretization method) with FOPID. The parameter optimization layer takes PPO reinforcement learning as its core, and dynamically outputs adjustable parameter adjustment amounts based on the state space of error, error change rate, and SLA default rate and a multi-objective penalty reward function to achieve parameter self-adaptation. The state storage layer adopts Redis TimeSeries and hash structure for hierarchical storage, while supporting low-latency reading and writing of real-time time series data and persistence of historical data, providing a data hub for the decision-making and optimization layers. The execution layer efficiently executes scaling instructions and feeds back the status. Each layer forms a complete closed loop of data acquisition, decision-making, optimization, and execution through standardized interfaces, taking into account both control real-time performance and intelligent parameter optimization.
[0124] Figure 7 This is a schematic diagram of the composition structure of an automatic expansion and contraction device provided in an embodiment of this application, as shown below. Figure 7As shown, the device includes: an acquisition module 700, a first determination module 701, a obtaining module 702, a second determination module 703, and a processing module 704, wherein: The acquisition module 700 is used to acquire metric data for multiple Pods currently managed by the target controller in Kubernetes; The first determining module 701 is used to determine the current indicator error value based on the indicator data and target indicator values of multiple Pods; Module 702 is obtained, which is used to process the current index error value using the target replica number decision formula based on the fractional-order PID controller to obtain the replica adjustment amount; The second determining module 703 is used to determine the target number of replicas based on the replica adjustment amount and the total number of Pods currently managed by the target controller; Processing module 704 is used to perform scaling up and down processing based on the target number of replicas.
[0125] In some embodiments, module 702 is further configured to: Construct an initial replica number decision formula based on a fractional-order PID controller; the initial replica number decision formula includes a proportional term, a fractional-order integral term, and a fractional-order derivative term, the fractional-order integral term includes an integral operator, and the fractional-order derivative term includes a derivative operator; The weighting coefficients of the integral and differential operators are calculated using the GL discretization method. The index error value sequence within the preset time window is weighted and summed using their respective weight coefficients to obtain the discretized integral operator and the discretized differential operator. The target replica number decision formula is determined based on the fractional integral term of the discretized integral operator, the fractional differential term of the discretized differential operator, and the proportional term.
[0126] In some embodiments, the above-described apparatus further includes an optimization module, which is configured to: The proportional term, fractional integral term, and fractional differential term in the target replica number decision formula each have their own adjustable parameters. The method also includes: Periodically retrieve Kubernetes runtime status data and use the runtime status data to construct a state space vector; The state space vector is processed using a reinforcement learning policy network based on proximal policy optimization to obtain the adjustment amount of the adjustable parameters, and the adjustable parameters are updated according to the adjustment amount. Obtain the running effect data corresponding to the updated adjustable parameters, process the running effect data using the target reward function, and obtain the reward value corresponding to the updated adjustable parameters; The reinforcement learning policy network is optimized using reward values.
[0127] In some embodiments, the second determining module 703 is further configured to: The replica adjustment amount is summed with the total number of Pods currently managed by the target controller to obtain the summed replica count. Round up the summed number of replicas to get the rounded number of replicas. Determine the safe boundary range for the number of replicas; Within the safe boundary interval, the rounded replica number is constrained and optimized to obtain the target replica number.
[0128] In some embodiments, the processing module 704 is further configured to: Determine the absolute value of the error change rate based on the current indicator error value; The cooling time is determined based on the absolute value of the rate of change of error; Determine whether the time interval between the current time point and the last expansion / contraction time point is greater than or equal to the cooldown time; If the time interval is greater than or equal to the cooldown duration, scaling up or down is performed based on the target number of replicas.
[0129] In some embodiments, the metric data for each Pod includes metric values for multiple metrics, and the first determining module 701 is further configured to: Based on the weights corresponding to each of the multiple Pods, the weighted average of the same metric values in different Pods is calculated to obtain the weighted average of each metric. Based on the weights of each indicator, the weighted average of the multiple indicators is weighted to obtain the weighted indicator value; The current indicator error value is determined based on the weighted indicator value and the target indicator value.
[0130] In some embodiments, the acquisition module 700 is further configured to: The metric data for each Pod is preprocessed to obtain preprocessed metric data; the preprocessing includes outlier removal and moving average filtering. Accordingly, the first determining module 701 is also used for: The current metric error value is determined based on the preprocessed metric data and target metric values from multiple Pods.
[0131] In practical applications, the above-mentioned acquisition module 700, first determination module 701, obtaining module 702, second determination module 703, processing module 704, and optimization module can all be implemented by a processor located in an electronic device. The processor can be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor.
[0132] Furthermore, in this embodiment, the functional modules can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional module.
[0133] If the integrated unit is implemented as a software functional module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment, in essence, or the part that contributes to related technologies, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the method of this embodiment. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0134] Specifically, the computer program instructions corresponding to an automatic scaling method in this embodiment can be stored on storage media such as optical discs, hard disks, and USB flash drives. When the computer program instructions corresponding to an automatic scaling method in the storage media are read or executed by an electronic device, any of the automatic scaling methods in the aforementioned embodiments are implemented.
[0135] Based on the same technical concept as the foregoing embodiments, see Figure 8 It illustrates an electronic device 800 provided in an embodiment of this application, which may include: a memory 801 and a processor 802; wherein, Memory 801 is used to store computer programs and data; The processor 802 is configured to execute a computer program stored in the memory to implement any of the automatic scaling methods described in the foregoing embodiments.
[0136] In practical applications, the memory 801 mentioned above can be volatile memory, such as RAM; or non-volatile memory, such as ROM, flash memory, hard disk drive (HDD) or solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 802.
[0137] The processor 802 described above can be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor. It is understood that, for different model training devices, the electronic device used to implement the above processor function can also be other types, and this application embodiment does not specifically limit it.
[0138] This application provides a computer program product, including a computer program that, when executed by a processor, implements any of the automatic scaling methods described in the foregoing embodiments.
[0139] In some embodiments, the functions or modules of the apparatus provided in this application can be used to perform the methods described in the above method embodiments. Specific implementations can be referred to the descriptions of the above method embodiments, and for brevity, will not be repeated here. The descriptions of the various embodiments above tend to emphasize the differences between them; their similarities or commonalities can be referred to each other, and for brevity, will not be repeated here.
[0140] The methods disclosed in the various method embodiments provided in this application can be arbitrarily combined to obtain new method embodiments without conflict. The features disclosed in the various product embodiments provided in this application can be arbitrarily combined to obtain new product embodiments without conflict. The features disclosed in the various method or device embodiments provided in this application can be arbitrarily combined to obtain new method embodiments or device embodiments without conflict.
[0141] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0142] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0143] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0144] The above are merely preferred embodiments of this application and are not intended to limit the scope of protection of this application.
Claims
1. An automatic scaling method, characterized in that, The method includes: Retrieve metric data for multiple Pods currently managed by the target controller in Kubernetes; Based on the metric data and target metric values of the multiple Pods, determine the current metric error value; The current index error value is processed using the target replica number decision formula based on a fractional-order PID controller to obtain the replica adjustment amount; The target number of replicas is determined based on the replica adjustment amount and the total number of Pods currently managed by the target controller; Scaling up or down is performed based on the target number of replicas.
2. The method of claim 1, wherein, The method further includes: A decision formula for the initial replica number based on a fractional-order PID controller is constructed. The initial replica number decision formula includes a proportional term, a fractional-order integral term, and a fractional-order derivative term. The fractional-order integral term includes an integral operator, and the fractional-order derivative term includes a derivative operator. The weight coefficients of the integral operator and the differential operator are calculated using the GL discretization method. The respective weighting coefficients are used to perform weighted summation on the index error value sequence within the preset time window to obtain the discretized integral operator and the discretized differential operator. The target replica number decision formula is determined based on the fractional integral term of the discretized integral operator, the fractional differential term of the discretized differential operator, and the proportional term.
3. The method of claim 2, wherein, The proportional term, fractional integral term, and fractional differential term in the target replica number decision formula have their own adjustable parameters, and the method further includes: The runtime status data of the Kubernetes system is periodically acquired, and the runtime status data is used to construct a state space vector. The state space vector is processed using a reinforcement learning policy network based on proximal policy optimization to obtain the adjustment amount of the adjustable parameters, and the adjustable parameters are updated according to the adjustment amount. Obtain the running effect data corresponding to the updated adjustable parameters, process the running effect data using the target reward function, and obtain the reward value corresponding to the updated adjustable parameters; The reward value is used to optimize the reinforcement learning policy network.
4. The method of claim 1, wherein, The step of determining the target number of replicas based on the replica adjustment amount and the total number of Pods currently managed by the target controller includes: The replica adjustment amount is summed with the total number of Pods currently managed by the target controller to obtain the summed replica count; The summed replica count is rounded up to obtain the rounded replica count. Determine the safe boundary range for the number of replicas; Within the safety boundary interval, the rounded replica number is constrained and optimized to obtain the target replica number.
5. The method of claim 1, wherein, The scaling up / down process based on the target number of replicas includes: Determine the absolute value of the error change rate based on the current indicator error value; The cooling time is determined based on the absolute value of the error change rate. Determine whether the time interval between the current time point and the last expansion / contraction time point is greater than or equal to the cooling duration; If the time interval is determined to be greater than or equal to the cooling duration, scaling up or down is performed based on the target number of replicas.
6. The method according to any one of claims 1 to 5, characterized in that, Each Pod's metric data includes the values of multiple metrics. Determining the current metric error value based on the metric data of the multiple Pods and the target metric value includes: Based on the weights corresponding to each of the multiple Pods, the metric values of the same metric in different Pods are weighted and averaged to obtain the weighted average value of each metric. Based on the weights corresponding to each of the multiple indicators, the weighted average of the multiple indicators is weighted to obtain the weighted indicator value; The current indicator error value is determined based on the weighted indicator value and the target indicator value.
7. The method according to any one of claims 1 to 5, characterized in that, The method further includes: The metric data for each Pod is preprocessed to obtain preprocessed metric data; the preprocessing includes outlier removal and moving average filtering. Based on the metric data and target metric values of the multiple Pods, determine the current metric error value, including: The current metric error value is determined based on the preprocessed metric data and target metric values of the multiple Pods.
8. An electronic device, comprising: The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method according to any one of claims 1 to 7.
9. A computer storage medium having stored thereon a computer program, characterized in that When executed by a processor, the computer program implements the method described in any one of claims 1 to 7.
10. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 7.
