Resource quota adjustment method, device and equipment for micro-service and storage medium
By obtaining real-time performance indicator data of microservices and using machine learning models to predict resource demands, and dynamically adjusting the resource quota of microservices, the problems of inefficient resource utilization and instability in the existing technology are solved, and more efficient resource management and performance guarantees are achieved.
Patent Information
- Application Number
- CN202510263772.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-06-24
AI Technical Summary
The prior art uses a fixed resource quota allocation strategy in microservice architecture to lead to inefficient resource utilization and unstable system performance, especially in the case of high traffic fluctuations.
By obtaining real-time performance indicator data of each microservice, using machine learning models to generate resource demand prediction results, and dynamically adjusting the resource quota of each microservice based on the prediction results.
It improves resource utilization and system performance, can respond to system load changes in time, and avoid resource waste and service performance degradation.
Smart Images

Figure CN120196436A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of resource quota adjustment, and particularly to a method, device, equipment and storage medium for adjusting the resource quota of microservices. Background Art
[0002] The microservice architecture is a cloud-native architecture method that decomposes an application into a set of small, independent services called microservices. Each microservice is an independent entity with its own business logic and data management model. In large-scale distributed applications, the microservice architecture is widely used in various systems.
[0003] Currently, when allocating resources to each microservice through traditional resource management methods, a fixed resource quota allocation strategy is usually adopted. Although the configuration process is relatively simple, this method can lead to low resource utilization efficiency and unstable system performance. When the system load changes, this resource quota allocation strategy cannot respond in a timely manner, which may cause resource waste or service performance degradation. Especially in the case of high traffic fluctuations, it cannot meet the system's resource requirements.
[0004] Therefore, how to adjust the resource quota of microservices to improve resource utilization and system performance is a problem that needs to be solved by those skilled in the art. Summary of the Invention
[0005] This application provides a method, device, equipment and storage medium for adjusting the resource quota of microservices to adjust the resource quota of microservices and improve resource utilization and system performance.
[0006] In a first aspect, this application provides a method for adjusting the resource quota of microservices, including:
[0007] Obtaining real-time performance metric data of each microservice;
[0008] Generating a prediction result by using the real-time performance metric data and a machine learning model; the machine learning model is a prediction model trained by historical performance metric data; the prediction result is the predicted resource demand result of each microservice;
[0009] Adjusting the resource quota of each microservice according to the prediction result.
[0010] Optionally, before obtaining the real-time performance metric data of each microservice, it further includes:
[0011] Collecting historical performance metric data of each microservice;
[0012] Generate target historical performance metric data and resource analysis results based on the historical performance metric data; the resource analysis results include at least one of: traffic patterns, resource demand trends, and resource usage patterns.
[0013] Train an initial time series prediction model using the target historical performance metric data and the resource analysis results to obtain a trained machine learning model.
[0014] Optionally, the generating of the target historical performance metric data and the resource analysis results based on the historical performance metric data includes
[0015] Analyze and process the historical performance metric data through a Hadoop architecture and / or a Spark engine to generate the target historical performance metric data and the resource analysis results.
[0016] Optionally, after generating the resource analysis results, it further includes:
[0017] Generate a statistical report for each microservice according to the resource analysis results.
[0018] Optionally, the training of the initial time series prediction model using the target historical performance metric data and the resource analysis results to obtain a trained machine learning model includes:
[0019] Preprocess the target historical performance metric data; the preprocessing includes at least one of: data cleaning, feature extraction, and normalization processing.
[0020] Train the initial time series prediction model using the preprocessed target historical performance metric data and the resource analysis results to obtain a trained machine learning model.
[0021] Optionally, the adjusting of the resource quotas of each microservice according to the prediction results includes:
[0022] Generate a resource allocation plan according to the prediction results and the resource analysis results;
[0023] Adjust the resource quotas of each microservice using the resource allocation plan.
[0024] Optionally, the generating of the prediction results using the real-time performance metric data and the machine learning model includes:
[0025] Input the real-time performance metric data into the machine learning model; the real-time performance metric data is the real-time performance metric data within a first predetermined time period.
[0026] Generate a prediction result by using the machine learning model, the real-time performance metric data, and the resource analysis result; the prediction result is the predicted resource requirements of each microservice within a second predetermined time period.
[0027] In a second aspect, the present application provides a resource quota adjustment device for microservices, including:
[0028] An acquisition module, configured to acquire the real-time performance metric data of each microservice;
[0029] A prediction module, configured to generate a prediction result by using the real-time performance metric data and a machine learning model; the machine learning model is a prediction model trained by historical performance metric data; the prediction result is the predicted resource requirements of each microservice;
[0030] An adjustment module, configured to adjust the resource quota of each microservice according to the prediction result.
[0031] In a third aspect, the present application provides an electronic device, including:
[0032] A processor, a memory, and a computer program stored on the memory and executable on the processor, and the processor executes the steps of the resource quota adjustment method of the present application through the computer program.
[0033] In a fourth aspect, the present application further provides a computer storage medium, and the computer storage medium stores computer executable instructions, and the computer executable instructions are used to execute the steps of the resource quota adjustment method of the present application.
[0034] The above technical solutions provided by the embodiments of the present application have the following advantages compared with the prior art: The present application discloses a resource quota adjustment method, device, equipment, and storage medium for microservices; the present application needs to acquire the real-time performance metric data of each microservice, and generate a prediction result by using the real-time performance metric data and a machine learning model; the machine learning model is a prediction model trained by historical performance metric data; the prediction result is the predicted resource requirements of each microservice; the resource quota of each microservice is adjusted according to the prediction result. It can be seen that when adjusting the resource quota, the present application only needs to input the real-time performance metric data of each microservice into the machine learning model to obtain the predicted resource requirements of each microservice, and dynamically adjust the resource quota through the prediction result, improving resource utilization and system performance. Description of the Drawings
[0035] The drawings here are incorporated into the specification and constitute a part of this specification, showing embodiments that conform to the present invention, and are used together with the specification to explain the principles of the present invention.
[0036] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0037] One or more embodiments are exemplarily illustrated by the pictures in the corresponding accompanying drawings. These exemplary illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the drawings in the figures do not constitute a proportional limitation.
[0038] Figure 1 Schematic diagram of the process for adjusting resource quotas of a microservice provided by an embodiment of this application;
[0039] Figure 2 Schematic diagram of another process for adjusting resource quotas of a microservice provided by an embodiment of this application;
[0040] Figure 3 Schematic diagram of another process for adjusting resource quotas of a microservice provided by an embodiment of this application;
[0041] Figure 4 Schematic diagram of the structure of a microservice quota management and resource allocation system provided by an embodiment of this application;
[0042] Figure 5 Schematic diagram of the structure of a device for adjusting resource quotas of a microservice provided by an embodiment of this application;
[0043] Figure 6 Schematic diagram of the structure of an electronic device provided by an embodiment of this application. Detailed implementation manners
[0044] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are some, but not all, of the embodiments of this application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of this application without creative efforts fall within the scope of protection of this application.
[0045] The following disclosure provides many different embodiments or examples for implementing different structures of the present invention. To simplify the disclosure of the present invention, the components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit the present invention. In addition, the present invention may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0046] In order to solve the problem of inefficiency in resource utilization and quota allocation in the microservices architecture, the present application proposes a method, device, equipment, and storage medium for adjusting resource quotas of microservices. The present application can dynamically evaluate the resource requirements of each microservice by combining real-time performance metric data and resource analysis results generated from historical performance metric data with a machine learning model, realize intelligent prediction of traffic fluctuations, and automatically adjust the resource allocation of each microservice according to the prediction results. For example, dynamically adjust the resource quotas such as CPU (Central Processing Unit) and memory of each microservice. The present application ensures sufficient resource allocation during high demand and reasonable resource recycling during low demand through a dynamic quota strategy, avoiding waste and ensuring service performance, and realizing efficient and intelligent resource management.
[0047] See Figure 1 , which is a schematic flowchart of a method for adjusting resource quotas of microservices provided by an embodiment of the present application. The method includes:
[0048] S101. Obtain the real-time performance metric data of each microservice;
[0049] In the present application, the real-time performance metric data is the key performance metric data of each microservice obtained through real-time monitoring. The key performance metric data can reflect the current operating state of each microservice, including the CPU utilization rate, memory usage, network traffic, etc. of each microservice, which is not specifically limited herein; input the real-time performance metric data into the machine learning model to predict the future resource requirements of each microservice.
[0050] When obtaining the real-time performance metric data in the present application, Prometheus (a real-time monitoring tool) can be specifically used to collect the real-time performance metric data of each microservice, or other real-time monitoring tools can be used to obtain the real-time performance metric data, which is not specifically limited herein.
[0051] S102. Generate a prediction result by using the real-time performance metric data and the machine learning model; the machine learning model is a prediction model trained by historical performance metric data; the prediction result is the prediction result of the resource requirements of each microservice;
[0052] In this application, the machine learning model is a prediction model trained with historical performance metric data, which is the historical resource usage records of each microservice, including key performance metric data such as CPU, memory, and network traffic of each microservice. The machine learning model can be a time series prediction model, such as: LSTM (Long-Short Term Memory, Recurrent Neural Network), ARIMA (Autoregressive Integrated Moving Average Model), GRU (Gate Recurrent Unit), etc., which are not specifically limited here. Among them, the LSTM model can effectively capture long-term patterns in data, so the LSTM model has a good effect when dealing with time series data with long-term dependencies; the ARIMA model has a lower computational complexity and is more suitable for dealing with simple time series data; the GRU model has higher computational efficiency and can achieve better prediction results in scenarios with high computational requirements. Users can select a suitable model according to actual needs to generate resource demand prediction results.
[0053] In this embodiment, the LSTM model is used as an example to illustrate this solution. When this application uses the LSTM model for prediction, the number of layers, the number of neurons, the activation function, etc. of the LSTM model can be modified according to actual needs. The LSTM model usually includes an input layer, multiple LSTM hidden layers, and an output layer. The input layer receives the preprocessed historical performance metric data. Each LSTM hidden layer is composed of multiple LSTM units and is used to learn the long-term dependencies of time series data. The output layer outputs the predicted resource demand value. The process of training the initial LSTM model in this application includes: using the preprocessed historical performance metric data as training data, dividing the training data into a training set and a validation set, calculating the loss function (such as mean squared error) through the backpropagation algorithm, and using an optimization algorithm (such as the Adam optimizer) to update the parameters of the model, and continuously iterating the training until the performance of the model on the validation set reaches a satisfactory level; when training the model, cross-validation and evaluation can be performed on the model, and hyperparameters can be adjusted to improve the prediction accuracy.
[0054] In this application, after the machine learning model is trained, the real-time performance metric data in the latest period of time can be input into the trained LSTM model, and the LSTM model is used to predict the resource demand value in the future period of time to generate a prediction result.
[0055] S103. Adjust the resource quotas of each microservice according to the prediction result.
[0056] In this application, after the machine learning model generates the resource demand prediction results for each microservice, a resource allocation plan for the next time period can be automatically generated based on the prediction results. When generating the resource allocation plan, the resource allocation plan can be generated through pre-set resource allocation rules, which can limit the adjustment range of resource quotas, etc., to avoid excessive adjustment.
[0057] Moreover, after this application generates the resource allocation plan, specifically, Kubernetes (container orchestration engine) HPA (Horizontal Pod Autoscaler) can be used to dynamically adjust the resource quotas of each microservice according to the resource configuration plan, ensuring that each microservice still operates efficiently when the load changes, and improving resource utilization and service performance. For example: for a microservice whose resource demand is predicted to increase significantly, increase the resource quota of this microservice; for a microservice whose resource demand is predicted to be stable or decrease, appropriately reduce the resource quota of this microservice.
[0058] In this application, it is necessary to regularly review and optimize the dynamic adjustment strategy to ensure the continuous optimization of resource utilization. The dynamic adjustment strategy refers to the strategy used in the entire resource quota adjustment plan, including: resource allocation rules, training strategies of machine learning models, prediction strategies, etc., which are not specifically limited here.
[0059] This application can optimize the dynamic adjustment strategy in the following ways:
[0060] 1. Data analysis: Regularly collect and analyze the operation data of the system, including resource usage, prediction accuracy, service performance indicators, etc. By comparing the prediction results with the actual resource usage, evaluate the effectiveness of the dynamic adjustment strategy.
[0061] 2. Rule adjustment: According to the results of data analysis, adjust the resource allocation rules and thresholds. Specifically, this application can continuously monitor the operation status of each microservice, and compare the actual resource usage with the prediction results. If it is found that there is a large deviation between the prediction result and the actual situation, adjust the parameters of the machine learning model or optimize the resource allocation rules to improve the performance and resource utilization efficiency of the system; for example: if the prediction result is always lower than the actual resource demand, appropriately increase the adjustment range of the resource quota; if it is found that the resource adjustment of some microservices is too frequent, the adjustment time interval can be increased.
[0062] 3. Model update: As the system runs and data accumulates, regularly update the machine learning prediction model. Retrain the model using the latest historical data, and adjust the parameters and structure of the model to improve the prediction accuracy.
[0063] 4. Expert experience integration: Integrate the experience of operation and maintenance personnel and business requirements to optimize the dynamic adjustment strategy. For example, for microservices of some key businesses, a higher resource guarantee level can be set; for microservices of some non-critical businesses, the priority of resource allocation can be appropriately reduced.
[0064] 5. Simulation experiment: Conduct simulation experiments outside the production environment to test the impact of different dynamic adjustment strategies on system performance and resource utilization efficiency. Select the optimal strategy based on the experimental results and apply it to the production environment.
[0065] In summary, in order to achieve the dynamic adjustment of the resource quota of each microservice, this application can pre-train a machine learning model through the historical performance index data of each microservice. When adjusting the resource quota, only the real-time performance index data of each microservice needs to be input into the machine learning model, and the resource demand prediction results of each microservice can be obtained, and the resource quota can be dynamically adjusted through the prediction results to improve resource utilization and system performance.
[0066] See Figure 2 , which is a schematic flow diagram of another method for adjusting the resource quota of microservices provided by the embodiment of this application. The method includes:
[0067] S201. Collect the historical performance index data of each microservice;
[0068] S202. Generate target historical performance index data and resource analysis results through the historical performance index data; the resource analysis results include at least one of traffic patterns, resource demand trends, and resource usage patterns;
[0069] S203. Use the target historical performance index data and resource analysis results to train the initial time series prediction model to obtain the trained machine learning model;
[0070] S204. Obtain the real-time performance index data of each microservice;
[0071] S205. Generate prediction results using the real-time performance index data and the machine learning model; the machine learning model is a prediction model trained through historical performance index data; the prediction results are the resource demand prediction results of each microservice;
[0072] S206. Adjust the resource quota of each microservice according to the prediction results.
[0073] In this application, historical operation data needs to be collected. This historical operation data is the historical performance metric data, including the CPU utilization rate, memory usage, network traffic, etc. of each microservice. The historical performance metric data reflects the operation status and resource consumption of each microservice in the past period of time, and is the basis for historical data analysis. After obtaining the historical performance metric data, it is first necessary to perform preliminary processing on this historical performance metric data to generate target historical performance metric data. Among them, the preliminary processing includes: performing simple aggregation, sorting and other operations on the historical performance metric data, and converting the original historical performance metric data into structured target historical performance metric data. Secondly, this application needs to analyze the target historical performance metric data to generate a resource analysis result. The resource analysis result includes at least one of a traffic pattern, a resource demand trend, and a resource usage pattern.
[0074] Among them: The traffic pattern is the change rule of the external request traffic borne by the microservice. For example, the peak and trough times of the traffic, the fluctuation range, etc. The traffic pattern includes a periodic pattern, a burst pattern, and a stable pattern. The periodic pattern means that the traffic shows regular periodic changes. For example, at a certain time period every day, certain days of the week, or specific dates of each month, the traffic will peak or trough. For example, the traffic of an e-commerce platform will increase significantly on weekends or during promotional activities; The burst pattern means that the traffic suddenly increases or decreases significantly in a short period of time without obvious rules. For example, a sudden hot event causes the traffic of related services to soar instantly; The stable pattern means that the traffic remains relatively stable for a long time with small fluctuations. For example, some basic services or microservices of non-popular services may show this traffic pattern.
[0075] The resource demand trend is information such as the change direction and rate of resource demand over time, including the peak period, rising period, falling period, and stable period of resource demand, as well as information such as the change rate. The resource usage pattern refers to the usage methods and characteristics of resources such as CPU, memory, and network within the microservice. For example, the change trend of CPU usage rate in different time periods, the allocation and release rules of memory, etc. After this application obtains the target historical performance metric data, it is also necessary to train the initial time series prediction model through the target historical performance metric data and the resource analysis result to obtain a trained machine learning model. This machine learning model is the trained time series prediction model.
[0076] In summary, before adjusting resource quotas, this application needs to generate target historical performance metric data and resource analysis results through historical performance metric data. The resource analysis results include traffic patterns, resource demand trends, resource usage patterns, etc. During the training process, the resource analysis results can be combined to train the time series prediction model more effectively, helping the model learn the rules of resource usage so that the trained machine learning model can generate more accurate resource demand prediction results for each microservice.
[0077] In another embodiment of this application, the process of generating target historical performance metric data and resource analysis results through historical performance metric data may include: analyzing and processing the historical performance metric data through the Hadoop architecture and / or the Spark engine to generate the target historical performance metric data and resource analysis results.
[0078] In this embodiment, Hadoop and / or Spark can be used to process the collected historical performance metric data; where Hadoop is an open-source distributed system infrastructure and Spark is a big data processing engine. When performing data analysis, either only one of Hadoop and Spark can be selected according to the actual situation, or both Hadoop and Spark can be used simultaneously.
[0079] For example: If the amount of data to be processed is relatively small and only simple data analysis and processing are required, the MapReduce framework of Hadoop may be sufficient to meet the requirements. In this case, Spark can be not used and Hadoop can be directly used to complete the data processing and analysis tasks; if the data is already stored in a data source suitable for Spark processing and the amount of data is not particularly large, Spark can independently complete data processing, analysis, and machine learning tasks. At this time, Spark can directly read the data from the data source and use its built-in algorithm library for data analysis and model training without relying on the storage and processing capabilities of Hadoop. When the amount of data is very large and complex data analysis and mining are required, both Hadoop and Spark can be used simultaneously. Hadoop's HDFS (Hadoop Distributed File System) is suitable for distributed storage of large-scale data, and MapReduce can perform preliminary distributed processing and aggregation of the data, while Spark has fast in-memory computing capabilities and can efficiently perform complex data analysis and machine learning tasks; when using both Hadoop and Spark simultaneously, Hadoop can be first used to store and preliminarily process the massive historical monitoring data, and then the processed data can be transferred to Spark for in-depth data analysis and model training.
[0080] In this embodiment, taking the analysis and processing of historical performance metric data using Hadoop and Spark simultaneously as an example for illustration. After the present application obtains the historical performance metric data, it can store the historical performance metric data through Hadoop and perform preliminary processing on the historical performance metric data to generate target historical performance metric data. Among them, the HDFS of Hadoop can store a large amount of historical monitoring data, and the MapReduce framework can perform distributed preliminary processing on the data, such as performing simple aggregation, sorting, etc. on the historical performance metric data, and converting the original monitoring data into structured target historical performance metric data. Then Spark obtains the processed target historical performance metric data from the HDFS of Hadoop and uses its fast in-memory computing ability to perform more complex data analysis to obtain a resource analysis result. Among them, Spark can perform operations such as data mining and machine learning, such as analyzing the correlation of resource usage and clustering analysis to identify resource usage patterns, etc.
[0081] Here, taking the generation of target historical performance metric data through the Hadoop architecture and Spark engine in the present application, and the resource usage pattern and peak period in the resource analysis result as an example for illustration, this process includes the following steps:
[0082] Step 1, Data Preparation: Use Hadoop to store and preliminarily process the collected historical performance metric data, convert the data into a format suitable for Spark analysis, and generate target historical performance metric data;
[0083] Step 2, Feature Selection: In Spark, select features related to resource usage patterns and peak periods, such as CPU utilization, memory usage, timestamp, etc.
[0084] Step 3, Clustering Analysis: Use a clustering algorithm to cluster the data, group similar resource usage situations into one category, so as to identify different resource usage patterns. Among them, the clustering algorithm can be the K-means algorithm.
[0085] Step 4, Peak Detection: Detect the peaks in the data by setting thresholds or using statistical methods to determine the peak periods of resource usage. The statistical method can be the moving average method.
[0086] Step 5, Result Verification and Optimization: Verify the extracted resource usage patterns and peak periods, etc., and adjust the parameters of the clustering algorithm or thresholds according to the actual situation to improve the accuracy of the extraction results.
[0087] It should be noted that the analysis operations in the above steps 3-5 are mainly executed by Spark. Spark has powerful data analysis capabilities and can use its built-in machine learning libraries and data mining algorithms to analyze the processed target historical performance metric data, thereby obtaining resource analysis results such as resource usage patterns and peak periods.
[0088] In another embodiment of the present application, after generating the resource analysis results, statistical reports for each microservice can also be generated according to the resource analysis results.
[0089] In the present application, the statistical reports record resource analysis results such as traffic patterns, resource demand trends, and resource usage patterns. Through these statistical reports, the present application can summarize and visualize the historical monitoring data, facilitating developers and managers to intuitively understand the resource usage of each microservice. Moreover, the resource analysis results in the statistical reports can be used as part of the training data to help the model learn the rules of resource usage; the resource analysis results in the statistical reports can also provide a reference for generating resource allocation plans to ensure the reasonable allocation of resources.
[0090] In summary, when obtaining the resource analysis results, the present application can specifically use the Hadoop architecture and / or the Spark engine to analyze and process the historical performance metric data, so as to quickly and accurately obtain the target historical performance metric data and the resource analysis results; after obtaining the resource analysis results, the present application can generate statistical reports according to the resource analysis results. Through these statistical reports, the present application can summarize and visualize the historical performance metric data, facilitating developers and managers to intuitively understand the resource usage of each microservice.
[0091] In another embodiment of the present application, the process of training the initial time series prediction model using the target historical performance metric data and the resource analysis results may include:
[0092] Preprocessing the target historical performance metric data; the preprocessing includes at least one of data cleaning, feature extraction, and normalization processing; using the preprocessed target historical performance metric data and the resource analysis results to train the initial time series prediction model to obtain a trained machine learning model.
[0093] In this embodiment, it is necessary to train the initial time series prediction model with the target historical performance metric data after preliminary processing. Since the processed target historical performance metric data is more standardized and structured, it is more suitable for data preprocessing and model training. Moreover, before model training, the present application also needs to preprocess the target historical performance metric data, and the preprocessing includes at least one of data cleaning, feature extraction, and normalization processing.
[0094] Data cleaning refers to: checking whether there are problems such as missing values and outliers in the data. For missing values, interpolation methods (such as linear interpolation and polynomial interpolation) can be used, or records containing missing values can be deleted; for outliers, statistical methods (such as methods based on standard deviation) can be used for identification and processing. For example, data points exceeding a certain standard deviation are regarded as outliers and corrected or deleted; Feature extraction refers to: extracting features related to resource demand prediction from the cleaned data. For example, CPU utilization, memory usage, network traffic, etc. are selected as features. At the same time, feature combination and transformation can be performed to generate new features, such as the ratio of CPU utilization to memory usage; Normalization processing refers to: normalizing the feature data so that data of different features have the same scale. Common normalization methods include min-max normalization and Z-score normalization; among them, min-max normalization scales the data to the interval [0,1]; Z-score normalization converts the data into a distribution with a mean of 0 and a standard deviation of 1.
[0095] After preprocessing the target historical performance metric data of this application, the preprocessed target historical performance metric data and the resource analysis result can be used to train the initial time series prediction model to obtain the trained machine learning model.
[0096] In summary, when training the model in this application, the target historical performance metric data generated by analysis and processing through the Hadoop architecture and / or Spark engine can be obtained for processing, improving the training rate; this application can also preprocess the target historical performance metric data through operations such as data cleaning, feature extraction, and normalization processing to improve the quality of the training data, improve the performance, training effect, and prediction effect of the model; and, this application uses the resource analysis result to train the initial time series prediction model together, which can help the model learn the rules of resource usage and improve the prediction accuracy of the time series prediction model.
[0097] See Figure 3 , which is a schematic flowchart of another method for adjusting the resource quota of a microservice provided by an embodiment of this application. The method includes:
[0098] S301. Obtain the real-time performance metric data of each microservice;
[0099] S302. Input the real-time performance metric data into the machine learning model; the real-time performance metric data is: the real-time performance metric data within the first predetermined time period; the machine learning model is a prediction model trained through historical performance metric data;
[0100] S303. Generate a prediction result by using the machine learning model, the real-time performance metric data, and the resource analysis result; the prediction result is: the resource demand prediction result of each microservice within the second predetermined time period;
[0101] S304. Generate a resource allocation plan based on the prediction result and the resource analysis result;
[0102] S305. Adjust the resource quotas of each microservice using the resource allocation plan.
[0103] In this application, the obtained real-time performance metric data is specifically the real-time performance metric data within a first predetermined time period, and this first predetermined time period can be a user-defined time period. For example, if the first predetermined time period is one hour, then the real-time performance metric data of each microservice within the past hour is obtained.
[0104] After this application obtains the real-time performance metric data within the first predetermined time period, it is input into a pre-trained machine learning model. This machine learning model can generate a resource demand prediction result for each microservice within a second predetermined time period based on the real-time performance metric data within the first predetermined time period and the resource analysis result. This second predetermined time period can be a user-defined time period. For example, if the second predetermined time period is 0.5 hour, then the generated prediction result is: the resource demand prediction result for each microservice within the next 0.5 hour. Among them, the machine learning model in this application can more accurately predict the resource demand of each microservice and generate a prediction result through the traffic pattern, resource demand trend, and resource usage pattern in the resource analysis result. For example, the machine learning model uses the resource demand trend and can more accurately predict future resource demands by combining the resource demand trend with the real-time performance metric data.
[0105] Moreover, after this application obtains the prediction result, it can generate a resource allocation plan in combination with the resource analysis result so as to adjust the resource quotas of each microservice using the resource allocation plan. For example, generating a resource allocation plan according to the traffic pattern can make advance resource planning and allocation according to different resource consumption situations. For a periodic traffic pattern, the resource quota can be adjusted in advance according to the historical cycle rule; for a burst pattern, an early warning mechanism can be set up to increase resources in a timely manner when the traffic approaches the burst threshold; the resource demand trend can also provide a basis for generating a reasonable resource allocation plan, and the resource usage pattern can also provide a reference for generating a resource allocation plan. For example, the resource quota can be increased in advance during peak periods, and resources can be reasonably allocated according to the resource usage pattern. It can be seen that through the resource analysis result, this application can help the system more comprehensively understand the dynamic changes in resource demands, thereby making more reasonable resource allocation decisions.
[0106] After the present application generates a resource allocation plan based on the prediction result and the resource analysis result, the resource quotas of each microservice can be adjusted according to the resource allocation plan. For example, for the resource allocation plan generated by the HPA of Kubernetes, the CPU and memory quotas of the microservice need to be dynamically adjusted. For example, if it is predicted that the CPU utilization rate of a certain microservice will increase from the current 30% to 60%, at this time, the system can adjust the CPU quota of this microservice from 1 core to 2 cores.
[0107] Here, the resource quota adjustment method of the present application will be specifically described. The resource quota adjustment method includes the following parts:
[0108] Model prediction: If the system includes an order processing microservice, the machine learning model simultaneously predicts the CPU utilization rate and memory usage of the order processing microservice. During the prediction, the real-time performance metric data of the past hour is input each time, and the resource requirements for the next 30 minutes are predicted to generate the resource requirement prediction result of the order processing microservice.
[0109] Resource allocation plan generation: If the prediction result shows that the CPU utilization rate of the order processing microservice will increase from the current 20% to 50% and the memory usage will increase from 500MB to 800MB in the next 30 minutes. A resource allocation plan is generated according to the preset resource allocation rules, and the CPU quota of this order processing microservice is increased from 0.5 core to 1 core, and the memory quota is increased from 1GB to 1.5GB.
[0110] Dynamic adjustment: Kubernetes HPA automatically adjusts the CPU and memory quotas of the order processing microservice according to the generated resource allocation plan. After the adjustment, continue to monitor the running status of this microservice and give feedback and optimization according to the actual situation.
[0111] See Figure 4 , which is a schematic structural diagram of the microservice quota management and resource allocation system provided by the embodiment of the present application. As shown in the figure, this system includes a monitoring module, a data analysis module, a machine learning prediction module, and a resource management module. Among them, the monitoring module includes the real-time monitoring tool Prometheus and the visualization tool Grafana; the data analysis module includes the real-time data processing tool Spark and the big data processing tool Hadoop, the machine learning prediction module includes the machine learning framework TensorFlow, and the resource management module includes a resource configuration algorithm and Kubernetes HPA.
[0112] Among them, the real-time monitoring tool is used to collect real-time performance metric data, including performance metric data such as the CPU utilization rate, memory usage, and network traffic of each microservice; the visualization tool is used to display the resource usage of each microservice in real time. This application can present the data to be displayed to the user in the form of intuitive charts, reports, etc. Through the visualization interface, the user can timely understand the running status and resource consumption of the microservice, so as to make monitoring and management decisions. For example, the operation and maintenance personnel can quickly discover the abnormal resource usage of a certain microservice through the visualization tool and take measures to adjust it in time.
[0113] The real-time data processing tool Spark and the big data processing tool Hadoop in the data analysis module are used to analyze and process the historical performance metric data, generate the target historical performance metric data and resource analysis results after preliminary processing, and generate the machine learning model in the machine learning prediction module after training the model. The machine learning prediction module can generate prediction results based on the real-time performance metric data and resource analysis results. The resource configuration algorithm in the resource management module is used to generate a resource allocation plan through the pre-set resource allocation rules and prediction results, and adjust the resource quota according to the resource allocation plan through Kubernetes HPA.
[0114] Among them, the resource configuration algorithm is connected to the visualization tool and may include the following situations:
[0115] User interaction modification algorithm: The user can intuitively view the relevant parameters and rules of the resource configuration algorithm through the visualization tool, and modify and adjust the resource configuration algorithm according to the actual needs and the monitored system operation situation. For example, the user can adjust parameters such as the threshold and adjustment range of resource allocation to optimize the resource allocation strategy.
[0116] Algorithm display and feedback: The visualization tool can display the operation results and effects of the resource configuration algorithm, such as indicators such as resource allocation plans and resource utilization rates. The user can evaluate and feedback on the performance of the algorithm based on these display information, providing a basis for subsequent algorithm optimization.
[0117] Data input and synchronization: The visualization tool can synchronize some data input by the user (such as business priorities, resource limitations, etc.) to the resource configuration algorithm, enabling the algorithm to generate a more reasonable resource allocation plan based on the latest information.
[0118] When adjusting the resource quotas of each microservice in this application, it is necessary to generate a resource allocation plan according to the dynamic adjustment strategy and prediction results, and adjust the resource quotas of each microservice according to this resource allocation plan, so as to realize the dynamic adjustment of the resource quotas of each microservice. When adjusting the resource quotas of each microservice in this application, it is necessary to generate a resource allocation plan according to the prediction results and resource analysis results, and adjust the resource quotas of each microservice according to this resource allocation plan, so as to realize the dynamic adjustment of the resource quotas of each microservice. When generating the prediction results in this application, it is necessary to input the real-time performance index data within the first predetermined time period into the machine learning model. The machine learning model combines the resource analysis results to obtain the prediction results of each microservice in the second predetermined time period. Through the prediction results of the second predetermined time period, the resource demand trends of each microservice can be reflected, so as to more effectively adjust the resource quotas of each microservice and improve resource utilization rate and system performance.
[0119] In summary, this application can realize intelligent microservice quota management and resource allocation by adopting real-time monitoring and machine learning models. Among them, this application can combine real-time monitoring data and historical data, and use machine learning algorithms such as LSTM for resource demand prediction to improve resource allocation efficiency and accuracy; dynamically adjust the resource quotas of each microservice according to the prediction results, so that the system can adapt to instantaneous traffic changes and ensure efficient operation; this application can also use intelligent monitoring and automated scheduling tools to build an adaptive feedback system to continuously optimize the resource management strategy; in this way, resource waste can be effectively avoided, resource utilization rate and system performance can be improved; and this solution can also intelligently handle high traffic fluctuations, ensure service stability and availability, reduce manual intervention, and realize the automation and intelligence of resource management.
[0120] This application can be applied to various distributed systems that require efficient resource management, such as Internet companies, e-commerce platforms, financial institutions, etc. By improving resource quotas and management efficiency, it can significantly reduce operating costs, improve system performance and user experience, and enhance market competitiveness.
[0121] See Figure 5 , Figure 5 FIG.
[0122] The acquisition module 11 is used to acquire the real-time performance index data of each microservice;
[0123] The prediction module 12 is used to generate prediction results by using the real-time performance index data and the machine learning model; the machine learning model is a prediction model trained by historical performance index data; the prediction results are the resource demand prediction results of each microservice;
[0124] Adjustment module 13, configured to adjust the resource quotas of each microservice according to the prediction result.
[0125] As an optional embodiment, the resource quota adjustment device further includes:
[0126] Collection module, configured to collect the historical performance metric data of each microservice;
[0127] Analysis module, configured to generate target historical performance metric data and a resource analysis result through the historical performance metric data; the resource analysis result includes at least one of: traffic pattern, resource demand trend, and resource usage pattern;
[0128] Training module, configured to train an initial time series prediction model using the target historical performance metric data and the resource analysis result to obtain a trained machine learning model.
[0129] As an optional embodiment, the analysis module is specifically configured to: analyze and process the historical performance metric data through a Hadoop architecture and / or a Spark engine to generate target historical performance metric data and a resource analysis result.
[0130] As an optional embodiment, the resource quota adjustment device further includes:
[0131] Generation module, configured to generate a statistical report for each microservice according to the resource analysis result.
[0132] As an optional embodiment, the training module includes:
[0133] Preprocessing unit, configured to preprocess the target historical performance metric data; the preprocessing includes at least one of: data cleaning, feature extraction, and normalization processing;
[0134] Training unit, configured to train an initial time series prediction model using the preprocessed target historical performance metric data and the resource analysis result to obtain a trained machine learning model.
[0135] As an optional embodiment, the adjustment module includes:
[0136] Generation unit, configured to generate a resource allocation plan according to the prediction result and the resource analysis result;
[0137] Adjustment unit, configured to adjust the resource quotas of each microservice using the resource allocation plan.
[0138] As an optional embodiment, the prediction module is specifically configured to:
[0139] Input the real-time performance metric data into a machine learning model; the real-time performance metric data is the real-time performance metric data within a first predetermined time period; generate a prediction result by using the machine learning model, the real-time performance metric data, and the resource analysis result; the prediction result is the predicted resource requirements of each microservice within a second predetermined time period.
[0140] Regarding the device in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.
[0141] See Figure 6 , Figure 6 FIG. is a schematic structural diagram of an electronic device provided by an embodiment of the present application. The electronic device specifically includes:
[0142] A processor 21, a memory 22, and a computer program stored on the memory 22 and executable on the processor 21. The processor 21 executes the steps of the resource quota adjustment method described in any of the above method embodiments through the computer program.
[0143] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may further include an AI (Artificial Intelligence) processor, and the AI processor is used to process computational operations related to machine learning.
[0144] The memory 22 may include one or more computer-readable storage media, which may be non-transitory. The memory 22 may also include high-speed random access memory and non-volatile memory, such as one or more magnetic disk storage devices and flash storage devices. In this embodiment, the memory 22 is at least used to store the following computer program 221. After the computer program is loaded and executed by the processor 21, the relevant steps in the resource quota adjustment method disclosed in any of the foregoing embodiments can be implemented. In addition, the resources stored in the memory 22 may also include an operating system 222, data 223, etc., and the storage method may be transient storage or permanent storage. Among them, the operating system 222 may include Windows, Unix, Linux, etc.
[0145] In some embodiments, the electronic device may further include a display screen 23, an input / output interface 24, a communication interface 25, a sensor 26, a power supply 27, and a communication bus 28.
[0146] Of course, Figure 6 The structure of the illustrated electronic device does not limit the electronic device in the embodiments of the present application. In practical applications, the electronic device may include more or fewer components than Figure 6 those shown, or combine certain components.
[0147] In another exemplary embodiment, a computer storage medium is further provided. When the program instructions are executed by the processor, the steps of the resource quota adjustment method described in any of the foregoing method embodiments are implemented. Among them, the storage medium may include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs.
[0148] Optionally, the specific examples in this embodiment may refer to the examples described in the foregoing embodiments, and details are not described herein again.
[0149] It should be understood that the terms used herein are for the purpose of describing particular example embodiments only and are not intended to be limiting. Unless the context clearly dictates otherwise, the singular forms "a", "an", and "the" as used herein may also include the plural forms. The terms "comprising", "including", "containing", and "having" are inclusive and thus specify the presence of stated features, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring their performance in the particular order described or illustrated, unless an execution order is explicitly stated. It should also be understood that additional or alternative steps may be used.
[0150] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather will be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for adjusting resource quota of a microservice, characterized in that: include: Get real-time performance indicator data for each microservice; Generate prediction results using the real-time performance indicator data and the machine learning model; The machine learning model is a prediction model trained by historical performance indicator data; the prediction result is a resource demand prediction result of each microservice; The resource quota of each microservice is adjusted according to the prediction result.
2. The resource quota adjustment method according to claim 1, characterized in that: Before obtaining the real-time performance indicator data of each microservice, the following steps are also included: Collect historical performance indicator data for each microservice; Generate target historical performance indicator data and resource analysis results through the historical performance indicator data; the resource analysis results include: at least one of: traffic pattern, resource demand trend, and resource usage pattern; The target historical performance indicator data and the resource analysis results are used to train the initial time series prediction model to obtain a trained machine learning model.
3. The resource quota adjustment method according to claim 2, characterized in that: The target historical performance indicator data and resource analysis results are generated by the historical performance indicator data, including The historical performance indicator data is analyzed and processed through the Hadoop architecture and / or the Spark engine to generate target historical performance indicator data and resource analysis results.
4. The resource quota adjustment method according to claim 3, characterized in that: After generating resource analysis results, it also includes: Generate a statistical report for each microservice based on the resource analysis results.
5. The resource quota adjustment method according to claim 2, characterized in that: The step of training the initial time series prediction model using the target historical performance indicator data and the resource analysis results to obtain a trained machine learning model includes: Preprocessing the target historical performance indicator data; the preprocessing includes: at least one of data cleaning, feature extraction and normalization processing; The preprocessed target historical performance indicator data and the resource analysis results are used to train the initial time series prediction model to obtain a trained machine learning model.
6. The resource quota adjustment method according to claim 2, characterized in that: The adjusting the resource quota of each microservice according to the prediction result includes: Generate a resource allocation plan according to the prediction result and the resource analysis result; The resource allocation plan is used to adjust the resource quota of each microservice.
7. The resource quota adjustment method according to any one of claims 2 to 6, characterized in that: The generating prediction results by using the real-time performance indicator data and the machine learning model includes: Inputting the real-time performance indicator data into a machine learning model; the real-time performance indicator data is: real-time performance indicator data within a first predetermined time period; Generate a prediction result using the machine learning model, the real-time performance indicator data and the resource analysis result; the prediction result is: a resource demand prediction result of each microservice within a second predetermined time period.
8. A resource quota adjustment device for a microservice, characterized in that: include: The acquisition module is used to obtain real-time performance indicator data of each microservice; A prediction module, used to generate prediction results using the real-time performance indicator data and the machine learning model; The machine learning model is a prediction model trained by historical performance indicator data; the prediction result is a resource demand prediction result of each microservice; The adjustment module is used to adjust the resource quota of each microservice according to the prediction result.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of the resource quota adjustment method described in any one of claims 1 to 7 of the present application through the computer program.
10. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, and the computer executable instructions are used to execute the steps of the resource quota adjustment method described in any one of claims 1 to 7 of the present application.
Citation Information
Cited By
Hadoop adaptive resource allocation method and device based on AI, equipment and medium
CN120567799A