Container resource allocation method and device, equipment and storage medium

By combining historical and real-time data fusion calculations, the future resource usage of containers is predicted, the problem of container resource allocation lag is solved, the accuracy of resource allocation and application stability are improved, and waste is reduced.

CN120407162APending Publication Date: 2025-08-01JINAN INSPUR DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510457454.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-11
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In the prior art, container resource allocation has a lag and cannot cope with sudden changes in load demand in applications, resulting in frequent changes in resource allocation that affect stability and excessive allocation waste.

Method used

By obtaining the historical resource usage and the current resource usage change rate of the target container, the time series prediction model is used to predict future resource usage, and combined with the historical change laws of resource usage and real-time mutation characteristics, a fusion calculation is carried out to determine the accurate resource allocation amount.

Benefits of technology

It realizes rapid response to container resource usage, avoids resource allocation lag, improves application stability and resource utilization efficiency, and reduces waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407162A_ABST
    Figure CN120407162A_ABST
Patent Text Reader

Abstract

The invention discloses a container resource allocation method and device, equipment and a storage medium, and relates to the technical field of computers, and the method comprises the steps: predicting a first resource usage amount based on the historical resource usage amount of a target container, which can reflect the historical change rule of the resource usage amount of the target container; the second resource usage amount predicted based on the resource usage amount change rate of the target container at the current time point can reflect the real-time mutation characteristic of the resource usage amount of the target container. The first resource usage amount and the second resource usage amount are subjected to fusion calculation, which means that the historical change rule and the real-time mutation characteristic of the resource usage amount of the target container are referred to at the same time. Therefore, when the resource usage amount of the target container is suddenly changed, the suddenly changed can be quickly responded, and the resource amount allocated to the target container is ensured to be accurate, so that the problem that resource allocation has hysteresis in some technologies can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and particularly to a method, apparatus, device, and storage medium for container resource allocation. Background Art

[0002] In containerization technologies, an application program and its dependencies can be packaged into a container, and resources can be allocated to the container. Based on the allocated resources, the container can run the application program. Resources include but are not limited to memory resources, CPU (Central Processing Unit) resources, hard disk resources, etc.

[0003] Currently, in some technologies, the resource usage of a container (such as memory usage rate, CPU usage rate, etc.) can be monitored in real time, and based on the monitoring results, the amount of resources allocated to the container can be dynamically adjusted. In this way, during the peak period of the load demand of the application program, more resources can be allocated to the container to meet the performance requirements; during the low period of the load demand of the application program, fewer resources can be allocated to the container to save costs. However, the resource allocation in these technologies has hysteresis and cannot cope with sudden changes in the load demand of the application program. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, computer-readable storage medium, and computer program product for container resource allocation to at least solve the problem of hysteresis in resource allocation in related technologies.

[0005] This application provides a method for container resource allocation, including:

[0006] Obtaining resource information of a target container, where the resource information includes the historical resource usage of the target container and the resource usage change rate at the current time point;

[0007] Predicting a first resource usage of the target container at a future target time point based on the historical resource usage, and predicting a second resource usage of the target container at the target time point based on the resource usage change rate;

[0008] Performing a fusion calculation on the first resource usage and the second resource usage to determine a third resource usage of the target container at the target time point, and allocating resources to the target container according to the third resource usage.

[0009] This application also provides a container resource allocation apparatus, including:

[0010] An information acquisition module, configured to obtain resource information of a target container, where the resource information includes the historical resource usage of the target container and the resource usage change rate at the current time point;

[0011] A prediction module, configured to predict a first resource usage of the target container at a future target time point based on the historical resource usage, and predict a second resource usage of the target container at the target time point based on the resource usage change rate;

[0012] A resource allocation module, configured to perform a fusion calculation on the first resource usage and the second resource usage, determine a third resource usage of the target container at the target time point, and allocate resources to the target container according to the third resource usage.

[0013] This application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any of the above container resource allocation methods when executing the computer program.

[0014] This application also provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above container resource allocation methods are implemented.

[0015] Through this application, the first resource usage predicted based on the historical resource usage of the target container can reflect the historical change law of the resource usage of the target container, and the second resource usage predicted based on the resource usage change rate of the target container at the current time point can reflect the real-time mutation characteristics of the resource usage of the target container. Performing a fusion calculation on the first resource usage and the second resource usage is equivalent to simultaneously referring to the historical change law and the real-time mutation characteristics of the resource usage of the target container. In this way, when a mutation occurs in the resource usage of the target container, the mutation can be quickly responded to, ensuring that the amount of resources allocated to the target container is accurate, thereby solving the problem of resource allocation lag in some technologies. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] To more clearly illustrate the embodiments of this application, the following will briefly introduce the drawings required for the embodiments. Obviously, the drawings in the following description are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0017] Figure 1 A flowchart of a container resource allocation method provided for some embodiments of this application;

[0018] Figure 2 A module diagram of a container resource allocation device provided for some embodiments of this application;

[0019] Figure 3Schematic diagram of modules of an electronic device provided for some embodiments of the present application. Detailed implementation manners

[0020] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0021] It should be noted that in the description of the present application, the terms "including", "comprising" or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0022] In order to enable those skilled in the art of the present technology to better understand the solution of the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific implementation manners.

[0023] Currently, in some containerization technologies, by monitoring the resource usage of containers in real time, the amount of resources allocated to containers can be dynamically adjusted. In this way, while meeting the performance requirements of the application program, the resource cost can also be reduced. However, these technologies have the following problems:

[0024] 1) There is a lag in resource allocation. Specifically, in these technologies, since resource allocation depends on real-time monitoring, usually, after monitoring that the resource usage of the container changes, the amount of resources allocated to the container is adjusted in a timely manner. Therefore, there is a lag in resource allocation and it is impossible to cope with sudden changes in the load demand of the application program. For example, assume that at 10:00:50, it is monitored that the CPU utilization rate of the container is too high (that is, the amount of CPU resources used by the container increases). Then, more CPU resources can be allocated to container A at 10:00:55. Since the problem of too high CPU utilization rate of the container occurred at 10:00:50, but actually more CPU resources were allocated to the container at 10:00:55, there is a lag in the allocation of CPU resources. Moreover, between 10:00:50 and 10:00:55, the CPU resources of the container may not meet the actual requirements (that is, it is impossible to cope with sudden changes in the load demand of the application program).

[0025] 2) The amount of resources allocated to the container changes frequently, affecting the stability of the application. Specifically, in these technologies, usually after monitoring that the resource usage of the container changes, the reallocation of container resources will be triggered. Based on such a resource allocation principle, when there are short-term fluctuations in the resource usage of the container, the amount of resources allocated to the container may change frequently, affecting the stability of the application. For example, assume that at 10:00:50, the container has a problem of excessive CPU utilization, but at 10:00:59, the CPU utilization of the container drops rapidly to the normal value. Usually, such a short-term change in CPU utilization may not require adjusting the CPU resource amount of the container. However, in these technologies, when it is monitored at 10:00:50 that the CPU utilization of the container is too high, more CPU resources will be allocated to the container at 10:00:55, and when it is monitored at 10:00:59 that the CPU utilization of the container drops, the CPU resources allocated to the container will be reduced at 10:01:04. During the frequent switching of the CPU resource amount of the container, problems such as service interruption, data loss, or conflicts may occur in the application, thus affecting the stability of the application.

[0026] 3) Over-allocation and waste of container resources. For example, when there is a short-term increase in the resource usage of the container, usually there is no need to allocate more resources to the container. However, in these technologies, it will trigger the allocation of more resources to the container, resulting in the problems of over-allocation and waste of container resources.

[0027] In view of this, the present application provides a container resource allocation method that can solve the above problems. The container resource allocation method can be applied to a container resource allocation system, or can be applied to an electronic device running the container resource allocation system. The electronic device may include, but is not limited to, a desktop computer, a tablet computer, a laptop computer, a server, etc. Referring jointly to Figure 1 , it is a schematic flowchart of the container resource allocation method provided by some embodiments of the present application. Figure 1 In it, the container resource allocation method includes the following steps:

[0028] Step S101, obtain the resource information of the target container, where the resource information includes the historical resource usage of the target container and the resource usage change rate at the current time point.

[0029] Specifically, a target container refers to one or more containers running on a host. After packaging an application and its dependencies into the target container and allocating some resources on the host (such as some CPU resources, some hard disk resources, some memory resources, etc.) to the target container, the target container can run the application based on the allocated resources. During the process of running the application, the resource usage of the target container can change dynamically, and the resource usage can be divided into memory usage, hard disk usage, CPU usage, etc. according to the resource type. For example, at time point 1, the memory size used by the target container is 1 GB; at time point 2, the memory size used by the target container is 1.1 GB.

[0030] In the host, resource collection software can be deployed. The resource collection software can collect the resource usage of the target container at different time points according to a certain sampling frequency. Specifically, when the resource usage of the target container changes rapidly, the resource usage of the target container can be collected at a higher sampling frequency (such as once per second or once per minute). In this way, the collected data can accurately reflect the instantaneous change of the resource usage. When the resource usage of the target container changes slowly, the resource usage of the target container can be collected at a lower sampling frequency (such as once every 10 minutes). In this way, the data collection volume can be reduced.

[0031] The correspondence between the resource usage collected by the resource collection software and the time point can be saved in a database. In step S101, the current time point can be used as a reference, and the resource usage of the target container within a preset duration before the current time point can be obtained from the database as the historical resource usage. For example, the resource usage of the target container within 2 hours before the current time point is obtained as the historical resource usage.

[0032] In this embodiment, the resource information may further include the resource usage of the target container at the current time point, that is, the current resource usage of the target container. Regarding the current resource usage as a function of time t, taking the first derivative of the current resource usage, or calculating the slope between the current resource usage and the previous historical resource usage, the change rate of the resource usage of the target container at the current time can be obtained. The change rate of resource usage characterizes the change rate and direction of the amount of resources used by the target container at the current time point. When the change rate of resource usage is positive, it indicates that at the current time point, the resource usage of the target container is in an increasing state; when the change rate of resource usage is negative, it indicates that at the current time point, the resource usage of the target container is in a decreasing state. Similar to the resource usage, the change rate of resource usage can also be divided into the change rate of memory usage, the change rate of hard disk usage, the change rate of CPU usage, etc. according to the resource type. For example, if the change rate of memory usage of the target container is -50M / s, it means that the size of the memory used by the target container decreases at a rate of 50M / s. Another example, if the change rate of memory usage of the target container is 50M / s, it means that the size of the memory used by the target container increases at a rate of 50M / s.

[0033] Step S102: Based on the historical resource usage, predict the first resource usage of the target container at a future target time point, and based on the change rate of resource usage, predict the second resource usage of the target container at the target time point.

[0034] Specifically, for each type of resource, step S102 can be executed separately to predict the resource usage of each type of the target container at the target time point. For example, based on the historical memory usage, predict the first memory usage of the target container at a future target time point, and based on the current change rate of memory usage, predict the second memory usage of the target container at the target time point. Another example, based on the historical CPU usage, predict the first CPU usage of the target container at a future target time point, and based on the current change rate of CPU usage, predict the second CPU usage of the target container at the target time point.

[0035] In this embodiment, when predicting the first resource usage of the target container at a future target time point based on the historical resource usage, the historical resource usage can be input into a trained time series prediction model, and the time series prediction model predicts and outputs the first resource usage of the target container at the target time point based on the time series characteristics of the historical resource usage. Specifically, the time series prediction model can be an LSTM (Long Short-Term Memory) model.

[0036] In this embodiment, the target time point is the next time point of the current time point. The calculation formula of the first resource usage can be as shown in Expression (1).

[0037] y 1(t+△t) = f LSTM (X hist )(1)

[0038] where t represents the current time point, t + △t represents the target time point after the current time point, y 1(t+△t) represents the first resource usage, X hist represents the historical resource usage, and f (LSTM) represents the time series prediction model.

[0039] In this embodiment, when predicting the second resource usage of the target container at the target time point based on the resource usage change rate, the historical resource usage and the current resource usage at at least one time point before the current time point can be averaged to obtain the average resource usage of the target container, and the second resource usage can be obtained based on the resource usage change rate and the average resource usage. Specifically, the current resource usage and the historical resource usage at k - 1 time points before the current time point can be averaged to obtain the average resource usage. The value of k is a positive integer greater than or equal to 1, such as 10.

[0040] The calculation formula of the second resource usage can be as shown in Expression (2).

[0041]

[0042] where y 2(t+△t) represents the second resource usage, represents the resource usage change rate, and μ real represents the average resource usage.

[0043] In Expression (2), the average resource usage can be regarded as the optimized current resource usage of the target container. Since the average resource usage is obtained by averaging the current resource usage and the historical resource usage of the target container, the problem of inaccuracy caused by short-term mutations and other reasons in the resource usage of the target container at the current time point can be avoided. Also, since represents the change direction and change amount of the resource usage, therefore, adding the average resource usage and can predict the second resource usage of the target container at the target time point. Specifically, when the resource usage change rate is positive, the second resource usage is greater than the average resource usage, indicating that the resource usage of the target container is gradually increasing; when the resource usage change rate is negative, the second resource usage is less than the average resource usage, indicating that the resource usage of the target container is gradually decreasing.

[0044] Step S103: Perform a fusion calculation on the first resource usage and the second resource usage to determine the third resource usage of the target container at the target time point, and allocate resources to the target container according to the third resource usage.

[0045] Similar to step S102, for each type of resource, step S103 can be executed separately to obtain the usage amounts of various types of resources of the target container at the target time point. For example, perform a fusion calculation on the first memory usage and the second memory usage of the target container at the target time point to obtain the third memory usage of the target container at the target time point; perform a fusion calculation on the first CPU usage and the second CPU usage of the target container at the target time point to obtain the third CPU usage of the target container at the target time point.

[0046] Since the first resource usage is mainly predicted based on the time series characteristics of historical resource usage, when the resource usage of the target container is in a stable period of regular change, the third resource usage can be determined mainly based on the first resource usage. In this way, it can be ensured that the third resource usage conforms to the change law of the resource usage of the target container. Also, since the second resource usage is mainly predicted based on the change rate of the resource usage of the target container at the current time point, when the resource usage of the target container is in a mutation period of irregular change, the third resource usage can be determined mainly based on the second resource usage. In this way, it can quickly respond to the mutation of the resource usage of the target container, ensure that the amount of resources allocated to the target container is accurate, and avoid the problem of prediction lag caused by the inertia of the time series prediction model.

[0047] In summary, in the technical solutions of some embodiments of the present application, the first resource usage predicted based on the historical resource usage of the target container can reflect the historical change law of the resource usage of the target container, and the second resource usage predicted based on the change rate of the resource usage of the target container at the current time point can reflect the real-time mutation characteristics of the resource usage of the target container. Performing a fusion calculation on the first resource usage and the second resource usage is equivalent to simultaneously referring to the historical change law and the real-time mutation characteristics of the resource usage of the target container. In this way, when the resource usage of the target container mutates, it can quickly respond to the mutation, ensure that the amount of resources allocated to the target container is accurate, and thus solve the problem of resource allocation lag in some technologies.

[0048] In some embodiments, the fusion calculation of the first resource usage and the second resource usage in step S103 may include:

[0049] Determine the resource usage fluctuation coefficient of the target container according to the current resource usage and at least part of the historical resource usage;

[0050] Based on the resource usage fluctuation coefficient and a preset fluctuation threshold, determine the confidence level of the first resource usage, and perform a fusion calculation on the first resource usage and the second resource usage based on the confidence level.

[0051] Specifically, the resource usage fluctuation coefficient is used to characterize the mutation characteristics of the resource usage of the target container. The confidence level is used to characterize the credibility of the first resource usage.

[0052] If the resource usage fluctuation coefficient is greater than the preset fluctuation threshold, it indicates that the resource usage of the target container is in a mutation period of irregular change, and the confidence level of the first resource usage can be relatively low. In this case, when performing a fusion calculation on the first resource usage and the second resource usage, the third resource usage can be determined mainly based on the second resource usage.

[0053] If the resource usage fluctuation coefficient is not greater than the preset fluctuation threshold, it indicates that the resource usage of the target container is in a stable period of regular change, and the confidence level of the first resource usage can be relatively high. In this case, when performing a fusion calculation on the first resource usage and the second resource usage, the third resource usage can be determined mainly based on the first resource usage.

[0054] In this embodiment, based on the current resource usage and the historical resource usages at k - 1 time points before the current time point, the resource usage fluctuation coefficient can be calculated through Expression (3).

[0055]

[0056] Among them, regarding t, μ real , k, reference can be made to the above - related description, which will not be elaborated here. σ real (t) represents the resource usage fluctuation coefficient. When the value of k is 1, x i represents the current resource usage of the target container. When the value of k is a positive integer greater than 1, x i represents the historical resource usage of the target container at the i - th time point before the current time point.

[0057] Based on the resource usage fluctuation coefficient, the confidence level of the first resource usage can be calculated through Expression (4).

[0058]

[0059] Among them, α(t) is the confidence level of the first resource usage, σ threshold is the preset fluctuation threshold, and β is a sensitivity parameter used to control the steepness of the change in the confidence level.

[0060] In Expression (4), the following relationship can exist: When σrea (t) > σ threshold When, the value of α(t) approaches 0; when σ rea (t) < σ threshold When, the value of α(t) approaches 1.

[0061] Based on the confidence of the first resource usage, the first resource usage and the second resource usage can be fused and calculated through Expression (5).

[0062]

[0063] Among them, regarding f LSTM (X hist ), α(t), μ real , t, reference can be made to the above relevant descriptions and will not be elaborated here. y (t+△t) represents the third resource usage obtained after fusing and calculating the first resource usage and the second resource usage, and λ represents the adjustment factor of the resource usage change rate.

[0064] Referring to Expressions (4) and (5) in combination, when the resource usage fluctuation coefficient σ rea (t) is greater than the preset fluctuation threshold σ threshold , it indicates that the resource usage of the target container is in a mutation period of irregular change, and the value of α(t) approaches 0. At this time, the value of y (t+△t) is agreed to be That is, the third resource usage is agreed to be the second resource usage. In this way, the mutation of the resource usage of the target container can be quickly responded to, ensuring that the resource amount allocated to the target container is accurate and avoiding the problem of prediction lag caused by the inertia of the time series prediction model. When the resource usage fluctuation coefficient σ rea (t) is less than the preset fluctuation threshold σ threshold , it indicates that the resource usage of the target container is in a stable period of regular change, and the value of α(t) approaches 1. At this time, the value of y (t+△t) is agreed to be f LSTM (X hist ), that is, the third resource usage is agreed to be the first resource usage. In this way, the third resource usage can conform to the change law of the resource usage of the target container.

[0065] Furthermore, the above α(t) and 1 - α(t) can be used as the weights of the first resource usage and the second resource usage, and, based on the resource usage fluctuation coefficient σ rea(t), dynamic adjustment of weights can be performed. In this way, it can be well adapted when the resource usage of the target container enters the mutation period and the steady period. Compared with setting the weights of the first resource usage and the second resource usage as fixed values (such as 7:3) in some technologies, the allocation method of the present application can have better adaptability.

[0066] In some embodiments, after allocating resources to the target container at the target time point, the resource metrics of the target container at the target time point can also be obtained. Specifically, the resource metrics are used to characterize the resource characteristics of the target container at the target time point. The resource characteristics may include at least one of the following characteristics: resource usage characteristics and resource allocation amount characteristics. Among them, the resource usage characteristics are used to characterize the resource usage situation of the target container, and the resource allocation amount characteristics are used to characterize the characteristics of the resources allocated to the target container.

[0067] In some embodiments, the resource metrics may include at least one of the actual resource utilization rate of the target container, the resource cost of the unused resources, and the change stability of the resources allocated to the target container. Specifically, the calculation formula of the actual resource utilization rate can be as shown in Expression (6).

[0068]

[0069] Among them, U actual represents the actual resource utilization rate of the target container, allocated represents the amount of resources allocated to the target container at the target time point, and used represents the amount of resources actually used by the target container at the target time point.

[0070] The calculation formula of the resource cost can be as shown in Expression (7).

[0071] C = η·(allocated - used) (7)

[0072] Among them, for allocated and used, reference can be made to the description of Expression (6) above, which will not be elaborated here. C represents the resource cost of the unused resources, and η represents the cost conversion coefficient.

[0073] The calculation formula of the change stability can be as shown in Expression (8).

[0074]

[0075] Among them, for allocated, reference can be made to the description of Expression (6) above, which will not be elaborated here. t represents time, and S represents the change stability of the resources allocated to the target container.

[0076] The change stability is mainly used to characterize whether the growth rate or deceleration (i.e., acceleration) of the amount of resources allocated to the target container is stable. For example, assume that the memory allocated to the target container at time point 1 is 10M, the memory allocated to the target container at time point 2 is 20M, and the memory allocated to the target container at time point 3 is 30M. Between time point 1 and time point 2, and between time point 2 and time point 3, the memory allocated to the target container increases at a rate of 10M, indicating that the change in the allocated memory amount is stable. Conversely, assume that the memory allocated to the target container at time point 1 is 10M, the memory allocated to the target container at time point 2 is 5M, and the memory allocated to the target container at time point 3 is 20M. Between time point 1 and time point 2, the allocated memory amount decreases by 5M, and between time point 2 and time point 3, the allocated memory amount increases by 15M, indicating that the change in the allocated memory amount is unstable.

[0077] Among the above resource metrics, the actual resource usage rate and resource cost can be used as resource usage characteristics, and the change stability of the amount of resources allocated to the target container can be used as a resource allocation amount characteristic. Based on the resource metrics, the accuracy of the amount of resources allocated to the target container can be evaluated. For example, when the actual resource usage rate is too low or the resource cost is too high, it indicates that too much resources are allocated to the target container, which is likely to cause resource waste. Another example is that when the change stability is too low, it indicates that the amount of resources allocated to the target container is not stable enough, affecting the stability of the application program.

[0078] In some embodiments, the resource metrics can be used as feedback after resource allocation, and based on the reinforcement learning algorithm, the generation logic of the third resource usage amount can be optimized online. Specifically, the resource allocation feedback value can be determined according to the resource metrics. The resource allocation feedback value refers to the value obtained by comprehensively evaluating multiple resource metrics and is used to characterize the accuracy of the amount of resources allocated to the target container. According to the resource allocation feedback value, the preset fluctuation threshold can be adjusted. According to the above expressions (3), (4), and (5), it can be seen that when the resource usage amount fluctuation coefficient is the same, if the preset fluctuation threshold is different, the obtained confidence level can be different. When the confidence level is different, the obtained third resource usage amount can be different. In this way, the accuracy of resource allocation can be improved. At the same time, when there is a sudden change in the amount of resources used by the target container, the response speed can also be improved.

[0079] In some embodiments, each resource metric has its corresponding feedback function. The above determination of the resource allocation feedback value according to the resource metrics may include:

[0080] According to the feedback function, the feedback values of each resource metric are determined respectively;

[0081] According to the index weights of each resource index, the feedback values of each resource index are fused and calculated to obtain the resource allocation feedback value.

[0082] Specifically, in some embodiments, when the resource index includes the actual resource utilization rate, the feedback function corresponding to the actual resource utilization rate can be as shown in Expression (9).

[0083]

[0084] Among them, R util represents the feedback value corresponding to the actual resource utilization rate, U actual represents the actual resource utilization rate, U lower represents the minimum resource utilization rate, U upper represents the maximum resource utilization rate, U lower ~U upper The interval between can be regarded as the target interval of resource utilization rate.

[0085] According to Expression (9), the feedback value R util represents the reward value after resource allocation is executed. When U actual is located between U lower ~U upper , the output of the tanh function increases nearly linearly, encouraging the actual resource utilization rate R util to approach the target interval. When U actual >U upper , the derivative of the tanh function drops rapidly, resulting in a sudden drop in the growth rate of the feedback value R util and tending to saturation. In this way, soft overload protection can be achieved. The so-called soft overload protection refers to the progressive suppression of overload. In this way, it is possible to avoid incorrect adjustment of the resource amount caused by a sudden change in the resource amount used by the target container, and thus effectively solve the problem in some technologies that the resource amount allocated to the container changes frequently, affecting the stability of the application program. At the same time, it can also solve the problem of excessive resource allocation in some technologies. When U actual <U upper , the output of the tanh function decays symmetrically, which can punish inaccurate resource allocation.

[0086] In some embodiments, when the resource index includes the resource cost, the feedback function corresponding to the resource cost can be as shown in Expression (10).

[0087] R cost =-log(1 + η·(allocated - used)(10)

[0088] Among them, R costThe feedback value corresponding to the resource cost, allocated represents the amount of resources allocated to the target container at the target time point, used represents the amount of resources actually used by the target container at the target time point, and η represents the cost conversion coefficient.

[0089] In expression (10), the feedback value R cost represents the penalty term after resource allocation, and the penalty term has a logarithmic relationship with the resource waste amount allocated - used. When resources are over - allocated, that is, when allocated - used is greater than 0, the initial growth rate of the penalty term is relatively fast, so that resource waste can be effectively suppressed. However, as the difference of allocated - used increases, the growth rate of the penalty term slows down, so that the strategy can be prevented from being too conservative.

[0090] In some embodiments, when the resource metric includes the change stability, the feedback function corresponding to the change stability can be as shown in expression (11).

[0091]

[0092] Among them, R stab represents the feedback value corresponding to the change stability, allocated represents the amount of resources allocated to the target container at the target time point, t represents time, and γ represents the stability conversion coefficient.

[0093] In expression (11), the feedback value R stab represents the penalty term after resource allocation, and this penalty term is used to penalize the change acceleration of the resource allocation amount. Through the change acceleration, the sudden change of resource allocation can be effectively captured, such as when the resource allocation amount suddenly decreases after increasing continuously twice. Based on the absolute value of the change acceleration, short - term normal resource fluctuations caused by prediction errors in resource allocation (i.e., fluctuations with a smaller change acceleration) can be filtered out, but continuous oscillations in resource allocation (fluctuations with a larger change acceleration) can be effectively suppressed, thereby improving the stability of the application program.

[0094] In some embodiments, the feedback values of each resource metric can be fused and calculated according to expression (12).

[0095] R total =ω(t1)·R util +ω(t2)·R cost +ω(t3)·R stab (12)

[0096] Among them, R total represents the resource allocation feedback value, ω(t1) represents the index weight of the actual resource utilization rate R util ω(t2) represents the resource cost R costThe index weight, and ω(t3) represents the change stability R stab The index weight of.

[0097] In some embodiments, the values of ω(t1) and ω(t3) described above can be 1, and the value of ω(t2) can be dynamically adjusted. Specifically, the target resource utilization U can be set opt . The target resource utilization U opt can be the above-mentioned minimum resource utilization U lower and the maximum resource utilization U upper One of the resource utilizations between them. If the actual resource usage rate U actual is less than the target resource usage rate U opt , the index weight of the resource cost is the first weight; if the actual resource usage rate U actual is equal to the target resource usage rate U opt , the index weight of the resource cost is the second weight; if the actual resource usage rate U actual is greater than the target resource usage rate U opt , the index weight of the resource cost is the third weight. Among them, the first weight is greater than the second weight, and the second weight is greater than the third weight. In this way, when there is resource redundancy in the target container (i.e., when U actual >U opt ), the value of ω(t2) can be relatively large, so as to strengthen the resource cost penalty; when the resources of the target container are in short supply (i.e., when U actual <U opt ), the value of ω(t2) can be relatively small, so as to weaken the resource cost penalty and give priority to ensuring the performance of the application program.

[0098] In some embodiments, the index weight ω(t2) of the resource cost can be determined according to expression (13).

[0099]

[0100] Among them, α represents the weight conversion coefficient.

[0101] The architecture of the time series prediction model will be described below.

[0102] In some embodiments, when predicting the first resource usage amount of the target container at a future target time point based on the time series prediction model, the time series prediction model may include an input layer, a first LSTM layer, a second LSTM layer, a fully connected layer, and an output layer.

[0103] The input layer is used to receive the historical resource usage amounts after data cleaning.

[0104] The first LSTM layer is used to extract low-level time series features and capture short-term dependencies.

[0105] The second - layer LSTM is used to extract high - level time - series features and capture long - term dependencies based on the first - layer LSTM.

[0106] The fully - connected layer is used to map the output of the second - layer LSTM to the first resource usage;

[0107] The output layer is used to output the first resource usage.

[0108] In some embodiments, when training the time - series prediction model, the Adam optimizer can be used. In this way, the learning rate can be adaptively adjusted during training, thereby accelerating the convergence speed of the model and improving the training effect. At the same time, the mean - squared error can be used as the loss function, which can effectively measure the difference between the predicted value and the true value and is suitable for regression tasks.

[0109] In some embodiments, the training of the time - series prediction model can be supervised training. Appropriate activation functions (such as ReLU or Tanh) can be added between each layer of LSTM to introduce non - linearity and enhance the expression ability of the model. A Dropout layer can be added after each layer of LSTM to prevent overfitting and improve the generalization ability of the model.

[0110] In some embodiments, to prevent model overfitting, an early - stopping mechanism can be introduced. When the loss value on the validation set has not decreased for multiple consecutive rounds, the training can be terminated in advance to ensure that the model stops training in the best state.

[0111] In some embodiments, to further improve the training effect of the model, a learning - rate decay strategy can be adopted. That is, during training, as the number of training rounds increases, the learning rate can be gradually decreased, enabling the model to adjust parameters more precisely and improve the prediction accuracy.

[0112] In some embodiments, to improve the generalization ability of the model, data augmentation techniques can be introduced. By adding noise to the original training data or performing data mixing, the model can better adapt to different input situations and enhance the robustness of the prediction.

[0113] In some embodiments, in addition to the mean - squared error, other evaluation metrics such as the mean absolute error and the mean absolute percentage error can be introduced to comprehensively evaluate the performance of the model from multiple perspectives and ensure the applicability of the model in different business scenarios.

[0114] Thus, the description of the method of this application is completed.

[0115] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method.

[0116] Referring to Figure 2 , a schematic module diagram of a container resource allocation device provided in some embodiments of the present application.

[0117] An information acquisition module 201, configured to acquire resource information of a target container, where the resource information includes the historical resource usage of the target container and the change rate of the resource usage at the current time point;

[0118] A prediction module 202, configured to predict the first resource usage of the target container at a future target time point based on the historical resource usage, and predict the second resource usage of the target container at the target time point based on the change rate of the resource usage;

[0119] A resource allocation module 203, configured to perform a fusion calculation on the first resource usage and the second resource usage, determine the third resource usage of the target container at the target time point, and allocate resources to the target container according to the third resource usage.

[0120] In some embodiments, the resource information further includes the current resource usage of the target container; the resource allocation module 203 is specifically configured to:

[0121] Determine the resource usage fluctuation coefficient of the target container according to the current resource usage and at least part of the historical resource usage;

[0122] Based on the resource usage fluctuation coefficient and a preset fluctuation threshold, determine the confidence level of the first resource usage, and perform a fusion calculation on the first resource usage and the second resource usage based on the confidence level.

[0123] In some embodiments, after allocating resources to the target container at the target time point, the resource allocation module 203 is further configured to:

[0124] Acquire the resource metrics of the target container at the target time point;

[0125] Determine a resource allocation feedback value according to the resource metrics, where the resource allocation feedback value characterizes the accuracy of the amount of resources allocated to the target container;

[0126] Adjust the preset fluctuation threshold according to the resource allocation feedback value, where, in the case of the same resource usage fluctuation coefficient, different preset fluctuation thresholds result in different confidence levels.

[0127] In some embodiments, the resource metrics include at least one of the actual resource utilization rate of the target container, the resource cost of the unused resources, and the stability of the change in the amount of resources allocated to the target container. Each resource metric has its corresponding feedback function. The resource allocation module 203 is specifically configured to:

[0128] According to the feedback function, determine the feedback values of each resource metric respectively;

[0129] According to the metric weights of each resource metric, perform a fusion calculation on the feedback values of each resource metric to obtain a resource allocation feedback value.

[0130] In some embodiments, when the resource metrics include the actual resource utilization rate and the resource cost, the resource allocation module 203 is specifically configured to determine the metric weight of the resource cost based on the following method:

[0131] If the actual resource utilization rate is less than the target resource utilization rate, the metric weight of the resource cost is the first weight;

[0132] If the actual resource utilization rate is equal to the target resource utilization rate, the metric weight of the resource cost is the second weight;

[0133] If the actual resource utilization rate is greater than the target resource utilization rate, the metric weight of the resource cost is the third weight;

[0134] Wherein, the first weight is greater than the second weight, and the second weight is greater than the third weight.

[0135] In some embodiments, when the resource metric includes the actual resource utilization rate, the feedback function corresponding to the actual resource utilization rate is as follows:

[0136]

[0137] R util represents the feedback value corresponding to the actual resource utilization rate, U actual represents the actual resource utilization rate, U lower represents the minimum resource utilization rate, U upper represents the maximum resource utilization rate; and / or

[0138] When the resource metric includes the resource cost, the feedback function corresponding to the resource cost is as follows:

[0139] R cost =-log(1 + η·(allocated - used)

[0140] R costfeedback value corresponding to the resource cost, allocated represents the amount of resources allocated to the target container at the target time point, used represents the amount of resources actually used by the target container at the target time point, and η represents the cost conversion coefficient; and / or

[0141] When the resource metric includes the change stability, the feedback function corresponding to the change stability is as follows:

[0142]

[0143] R stab represents the feedback value corresponding to the change stability, allocated represents the amount of resources allocated to the target container at the target time point, t represents time, and γ represents the stability conversion coefficient.

[0144] In some embodiments, the prediction module 202 is specifically configured to:

[0145] perform an average calculation on the historical resource usage at at least one time point before the current time point and the current resource usage to obtain the average resource usage of the target container;

[0146] obtain the second resource usage based on the resource usage change rate and the average resource usage.

[0147] For the description of the features in the corresponding embodiments of the container resource allocation device, reference can be made to the relevant descriptions in the corresponding embodiments of the sample data processing method, which will not be elaborated here one by one.

[0148] In combination with reference to Figure 3 , an embodiment of the present application further provides an electronic device, including a memory 10 and a processor 20. A computer program is stored in the memory 10, and the processor 20 is configured to run the computer program to execute the steps in any one of the above embodiments of the container resource allocation method.

[0149] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any one of the above embodiments of the container resource allocation method when running.

[0150] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: various media such as USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), mobile hard disks, magnetic disks, or optical discs that can store computer programs.

[0151] An embodiment of the present application also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the steps in any of the above-described embodiments of the container resource allocation method are implemented.

[0152] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-described embodiments of the container resource allocation method are implemented.

[0153] Those skilled in the art can further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0154] The above has introduced in detail a container resource allocation method, device, equipment, and storage medium provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A method for allocating container resources, characterized in that, The method includes: Obtaining resource information of a target container, where the resource information includes the historical resource usage of the target container and the rate of change of the resource usage at the current time point; Predicting a first resource usage of the target container at a future target time point based on the historical resource usage, and predicting a second resource usage of the target container at the target time point based on the rate of change of the resource usage; Performing a fusion calculation on the first resource usage and the second resource usage to determine a third resource usage of the target container at the target time point, and allocating resources to the target container according to the third resource usage.

2. The container resource allocation method according to claim 1, wherein The resource information further includes the current resource usage of the target container; The performing a fusion calculation on the first resource usage and the second resource usage includes: Determining a resource usage fluctuation coefficient of the target container according to the current resource usage and at least part of the historical resource usage; Determining the confidence level of the first resource usage based on the resource usage fluctuation coefficient and a preset fluctuation threshold, and performing a fusion calculation on the first resource usage and the second resource usage based on the confidence level.

3. The container resource allocation method according to claim 2, wherein, After allocating resources to the target container at the target time point, the method further includes: Obtaining a resource metric of the target container at the target time point; Determining a resource allocation feedback value according to the resource metric, where the resource allocation feedback value represents the accuracy of the amount of resources allocated to the target container; Adjusting the preset fluctuation threshold according to the resource allocation feedback value, where, in the case of the same resource usage fluctuation coefficient, different preset fluctuation thresholds result in different confidence levels.

4. The container resource allocation method according to claim 3, wherein The resource metric includes at least one of the actual resource utilization rate of the target container, the resource cost of the unused resources, and the change stability of the amount of resources allocated to the target container, and each resource metric has a corresponding feedback function; The determining a resource allocation feedback value according to the resource metric includes: Determining the feedback value of each resource metric respectively according to the feedback function; Performing a fusion calculation on the feedback values of each resource metric according to the metric weights of each resource metric to obtain the resource allocation feedback value.

5. The container resource allocation method according to claim 4, wherein When the resource metric includes the actual resource utilization rate and the resource cost, the metric weight of the resource cost is determined based on the following method: If the actual resource utilization rate is less than the target resource utilization rate, the metric weight of the resource cost is the first weight; If the actual resource utilization rate is equal to the target resource utilization rate, the metric weight of the resource cost is the second weight; If the actual resource utilization rate is greater than the target resource utilization rate, the metric weight of the resource cost is the third weight; Wherein, the first weight is greater than the second weight, and the second weight is greater than the third weight.

6. The container resource allocation method according to claim 4, wherein When the resource metric includes the actual resource utilization rate, the feedback function corresponding to the actual resource utilization rate is as follows: R util represents the feedback value corresponding to the actual resource utilization rate, U actual represents the actual resource utilization rate, U lower represents the minimum resource utilization rate, U upper represents the maximum resource utilization rate; and / or When the resource metric includes the resource cost, the feedback function corresponding to the resource cost is as follows: R cost = -log(1 + η·(allocated - used) R cost represents the feedback value corresponding to the resource cost, allocated represents the amount of resources allocated to the target container at the target time point, used represents the amount of resources actually used by the target container at the target time point, and η represents the cost conversion coefficient; and / or When the resource index includes the change stability, the feedback function corresponding to the change stability is as follows: R stab represents the feedback value corresponding to the change stability, allocated represents the amount of resources allocated to the target container at the target time point, t represents time, and γ represents the stability conversion coefficient.

7. The container resource allocation method according to claim 2, wherein Predicting the second resource usage of the target container at the target time point based on the change rate of the resource usage includes: Performing an average calculation on the historical resource usages at at least one time point before the current time point and the current resource usage to obtain the average resource usage of the target container; Based on the change rate of the resource usage and the average resource usage, obtaining the second resource usage.

8. A container resource allocation device, characterized in that, The device includes: An information acquisition module, configured to acquire resource information of a target container, where the resource information includes the historical resource usage of the target container and the change rate of the resource usage at the current time point; A prediction module, configured to predict the first resource usage of the target container at a future target time point based on the historical resource usage, and predict the second resource usage of the target container at the target time point based on the change rate of the resource usage; A resource allocation module, configured to perform a fusion calculation on the first resource usage and the second resource usage, determine the third resource usage of the target container at the target time point, and allocate resources to the target container according to the third resource usage.

9. An electronic device, characterized in that, Including: A memory, configured to store a computer program; A processor, configured to implement the steps of the container resource allocation method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, where the computer program implements the steps of the container resource allocation method according to any one of claims 1 to 7 when executed by a processor.