Method for dynamically adjusting and optimizing thread pool based on AI large model
Through the dynamic tuning of thread pool method based on AI large model, the problem of lack of flexibility and adaptability of thread pool parameter adjustment in the existing technology is solved, and intelligent dynamic adjustment of thread pool configuration is realized, and resource utilization and system performance are improved.
Patent Information
- Application Number
- CN202411773168.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-12-04
AI Technical Summary
The prior art lacks flexibility and adaptability when adjusting thread pool parameters, and cannot accurately adjust according to real-time task execution and dynamic changes in system load, resulting in waste of resources or delay in task processing.
The dynamic tuning thread pool method based on AI big model is adopted. By creating a dynamic thread pool, regularly querying recommended configurations, querying historical thread pool data, predicting future load, obtaining recommended configuration data sets, generating prompt words, calling the LLM big model to generate recommended configurations and dynamically adjusting thread pool parameters.
It realizes intelligent dynamic adjustment of thread pool configuration, improves resource utilization, enhances system performance and stability, reduces manual intervention and operation and maintenance costs, and can quickly adapt to load changes and improve prediction accuracy.
Smart Images

Figure CN119621280A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of dynamically tuning thread pools, and in particular to a method for dynamically tuning thread pools based on an AI large model. Background Art
[0002] In the prior art, thread pool parameters are adjusted mainly based on the following methods:
[0003] 1) Static adjustment based on fixed configuration values: During the system initialization phase, the core parameters of the thread pool, such as the number of core threads, the maximum number of threads, and the queue capacity, are pre-set. These values remain unchanged during the system operation cycle. This method is suitable for application scenarios with relatively stable loads, but it is easy to cause uneven resource allocation or over-configuration when facing dynamically changing loads;
[0004] 2) Semi-automatic adjustment based on simple threshold judgment: By setting thresholds, such as task queue length, CPU usage, etc., when the monitored indicators exceed these thresholds, the thread pool parameters are adjusted, such as increasing or decreasing the number of threads. Although this method is more flexible than completely static configuration, it only makes decisions based on one or two indicators, ignoring the multi-dimensional characteristics of system load, which may cause the timing and magnitude of adjustments to be inaccurate.
[0005] The existing thread pool adjustment scheme has the following disadvantages:
[0006] 1) Lack of flexibility and adaptability: It is impossible to make precise adjustments based on the real-time task execution and dynamic changes in system load, which can easily lead to resource waste or task processing delays. For example, when a large number of concurrent tasks appear in a short period of time, the task backlog may occur due to insufficient number of threads;
[0007] 2) Incomplete consideration of factors: Judgment is based on only a limited number of indicators or thresholds, and multiple factors such as thread busyness and system resource usage cannot be comprehensively considered. Summary of the invention
[0008] The present invention aims to solve the problems of lack of flexibility and adaptability: the inability to make precise adjustments according to the real-time task execution and the dynamic changes of the system load, which easily leads to waste of resources or delays in task processing. For example, when a large number of concurrent tasks appear in a short period of time, a backlog of tasks may occur due to insufficient number of threads; the technical problem of incomplete consideration of factors: only judging based on a limited number of indicators or thresholds, and failing to comprehensively consider multiple factors such as the busyness of the thread and the usage of system resources, provides a method for dynamically tuning the thread pool based on a large AI model.
[0009] The present invention solves the above technical problems through the following technical solutions:
[0010] The present invention provides a method for dynamically tuning a thread pool based on an AI large model, and the method for dynamically tuning a thread pool based on an AI large model comprises the following steps:
[0011] S1. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in the business logic;
[0012] S2. Regularly query recommended configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application;
[0013] S3. Query historical thread pool data: connect to the database that stores the application thread pool operation information, and query the thread pool operation data of the business application within the last hour;
[0014] S4. Predict future load: Based on the queried historical thread pool operation information of the business application as a data set, call the LSTM model to predict the load data within the next hour, including CPU usage and thread pool load;
[0015] S5. Get recommended configuration data set: Connect to the vector database and get recommended thread pool configuration data set. These data sets are generated after stress testing and optimization, and are stored in the vector database in advance. The data set covers recommended thread pool configuration parameters in various environments.
[0016] S6. Generate prompt words: extract the number of CPUs based on the data queried in step 3, and the load data predicted in the next hour from step 4, and combine with the recommended thread pool configuration data queried from the vector database in step 5 to generate prompt words for querying the LLM large model; the prompt words will specify the data format returned by the LLM large model;
[0017] S7. Call the LLM big model to generate recommended configuration: call the LLM big model, pass in the generated prompt words, generate the recommended thread pool configuration, and return;
[0018] S8. Dynamically adjust thread pool parameters: The thread pool component receives the recommended thread pool configuration returned by the AIAgent application, and then uses the configuration to dynamically adjust thread parameters.
[0019] Furthermore, the process of dynamically tuning the thread pool mainly describes that the thread pool component obtains the recommended configuration by periodically calling the AIAgent interface, and then dynamically optimizes and adjusts the thread pool parameters. The process of dynamically tuning the thread pool includes the following steps:
[0020] a. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in business logic;
[0021] b. Regularly query the recommended thread pool configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application. Then, based on the received recommended configuration, the thread pool component dynamically adjusts the core thread number, maximum thread number and other parameters of the thread pool to adapt to the current system load.
[0022] c. Dynamically adjust thread pool parameters: Based on the recommended configuration received, the thread pool component dynamically adjusts parameters such as the number of core threads and maximum number of threads in the thread pool to adapt to the current system load.
[0023] Furthermore, the thread pool runs the data collection process, which mainly describes the entire process from creating a thread pool to data collection, transmission and persistence. The thread pool runs the data collection process and includes the following steps:
[0024] a. Create a thread pool: Create a thread pool by using the thread pool component;
[0025] b. Regularly collect operation data: The thread pool component regularly obtains the operation data of the thread pool, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information;
[0026] c. Output data to log files: Output the collected system and thread pool operation data and other information to log files for subsequent data collection and processing;
[0027] d. Log collection: Use a log collector (open source log collectors such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files. Every time a log file changes, the collection operation will be performed;
[0028] e. Data transmission: The log collector sends the collected data to the message middleware (such as Kafka, RabbitMQ, etc.) for buffering;
[0029] f. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage.
[0030] Furthermore, the process of constructing the recommended thread pool configuration data set describes the entire process from adjusting the number of system CPUs to data cleaning, calculation, screening of the optimal configuration and storage; the optimal thread pool configuration finally screened out will serve as a reference data set for the recommended thread pool configuration given in the LLM model.
[0031] Furthermore, the process of constructing the recommended thread pool configuration data set includes the following steps:
[0032] a. Adjust the number of system CPUs: Adjust the number of system CPUs and set different CPU configurations, such as 4, 8, 12, 16 and other common configurations. This is to collect thread pool operation information under different CPU numbers in the future;
[0033] b. Deploy business applications: Redeploy business applications that have introduced thread pool components under the specified number of CPUs, and provide business interfaces for subsequent stress testing;
[0034] c. Adjust the thread pool configuration parameters: Adjust the thread pool configuration parameters, such as setting the number of core threads to 2, 3, 4, 5, etc., but not exceeding 2n+1 of the number of system CPUs. This is to generate thread pool operation data under different configurations;
[0035] d. Simulate business access scenarios: Use stress testing tools (such as JMeter) to stress test the business interfaces in business applications. During the stress testing process, ensure that the CPU usage rate gradually increases from low utilization to high utilization and reaches the CPU upper limit. The stress testing time lasts for 1 hour.
[0036] e. Collecting operation data: The thread pool component regularly obtains thread pool operation data, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information;
[0037] f. Output data to log file: Output the collected thread pool and CPU data to the log file for subsequent data collection and processing;
[0038] g. Log collection and transmission: Use log collectors (such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files and send the collected data to message middleware (such as Kafka, RabbitMQ, etc.) for buffering;
[0039] h. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage;
[0040] i. Data cleaning and calculation: Use Python tools to connect to the database, read the thread pool running data of the stored business application stress test, and perform data cleaning and calculation;
[0041] j. Filter the optimal configuration: group according to the number of core threads in the thread pool, the number of CPUs, the average CPU usage (1 hour), and the average thread pool load (1 hour), filter according to the thread pool throughput (1 hour), and select the data records with the highest thread pool throughput in different groups;
[0042] k. Store optimal configuration: Store the selected optimal configuration data records in a CSV file for subsequent use.
[0043] Furthermore, the data cleaning and calculation specific operation steps include:
[0044] (1) Data integrity check: discard or fill in incomplete data;
[0045] (2) Data deduplication: discard duplicate data to avoid data duplication;
[0046] (3) Data formatting: converting timestamps into date and time, etc.
[0047] (4) Data anomaly check: processing data whose task execution time exceeds the normal time range;
[0048] (5) Data calculation:
[0049] (6) Thread pool throughput (1 hour): the number of tasks that the thread pool can complete per unit time; the calculation formula is: (number of tasks completed by the thread pool (current time) / number of tasks completed by the thread pool (1 hour ago)) / 60;
[0050] (7) Average CPU usage (1 hour): The average CPU usage per unit time. The calculation formula is: Total CPU usage (1 hour) / 60.
[0051] (8) Average thread pool load (1 hour): The average thread pool load per unit time. The calculation formula is: Total thread pool load (1 hour) / 60.
[0052] Furthermore, the process of storing the recommended thread pool configuration into the vector database mainly describes the entire process from loading the recommended configuration data set to data conversion, generating vectors, creating vector data indexes and storing them into the vector database; the process of storing the recommended thread pool configuration into the vector database includes the following steps:
[0053] a. Load the recommended configuration dataset: load the recommended thread pool configuration dataset CSV file in the local computer.
[0054] b. Connect to vector database: Establish a connection with the vector database and prepare to store the recommended configuration data into the database;
[0055] c. Initial embedding model: Initialize the embedding model, for example, using the sentence-transformers / all-MiniLM-L6-v2 model based on HuggingFace to convert text data into vectors;
[0056] d. Data conversion: Convert the data in the loaded CSV file into strings row by row; define two fields: input_str (a string containing CPU usage and thread pool load) and recommended_threads (a recommended thread pool configuration string);
[0057] e. Generate vectors: Use the embedding model to convert string data into vectors; each recommended configuration record will generate a corresponding vector representation;
[0058] f. Store in vector database: Insert the generated vector data into the vector database; these vector data will be used as a reference for subsequent calls to the AI large model to improve the accuracy of generating recommended thread pool configurations.
[0059] Furthermore, the LSTM model construction process describes the entire process from connecting to the historical information database to checking the model existence, selecting features, data preprocessing, dividing the data set, building the LSTM model, training the model and saving the model; building the LSTM model is mainly used for subsequent prediction of the application load; the LSTM model construction process includes the following steps:
[0060] a. Connect to the historical information database: connect to the database that stores the historical thread pool information of business applications and read the historical thread pool operation data set; these data sets include information such as the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, and thread pool load;
[0061] b. Check whether the model exists: Determine whether there is a trained LSTM model. If not, it means that the model has not been built yet and full training is required using the full data. If it exists, you only need to load the locally trained model, and then use the latest data for incremental training, and start a scheduled task to perform incremental training every hour.
[0062] c. Select features: Select features that are closely related to thread pool load and CPU usage, such as "CPU number", "Number of active threads in thread pool", "Number of tasks in thread pool queue", "Number of core threads in thread pool", "Thread pool queue size", "CPU usage", "Thread pool load", etc.
[0063] d. Data preprocessing: normalize the data and normalize all eigenvalues to the range of [0, 1] to improve the convergence and stability of model training;
[0064] e. Divide the data set: Divide the data set into a training set and a test set. Usually 80% of the data is used as the training set and 20% of the data is used as the test set to train the model and evaluate the performance of the model.
[0065] f. Build LSTM model;
[0066] g. Training model: Use the training set data to train the LSTM model; during the training process, you can set multiple epochs and batch sizes to ensure that the model fully learns the patterns in the data;
[0067] h. Save model: After training is completed, save the model to a file for subsequent use.
[0068] Furthermore, the LSTM model is constructed using the Keras framework and includes the following steps:
[0069] (1) Create a sequential model: Create a sequential model to stack each neural network layer;
[0070] (2) Add LSTM layer: Add two LSTM layers, the number of units in each LSTM layer is 150, and set the input shape to input_shape = (time_step, len(features));
[0071] (3) Add Dropout layer: Add a Dropout layer with a dropout rate of 0.2 to prevent overfitting;
[0072] (4) Add a fully connected layer: Add a fully connected layer and output two values, corresponding to the future thread pool load and CPU usage;
[0073] (5) Compile the model: Compile the model using the Adam optimizer and the mean square error loss function.
[0074] Furthermore, the AIAgent application execution process mainly describes the entire process from providing an API interface to loading an LLM model, querying historical data, calling an LSTM model for prediction, connecting a vector database, building a prompt word template, calling an LLM model to generate a recommended configuration, and returning the recommended configuration; the AIAgent application execution process includes the following steps:
[0075] a. API interface: The AIAgent application provides an API interface for calling thread pool components and querying recommended thread pool configurations;
[0076] b. Load the LLM large model: Use the transformers library to load the local large language model (LLM), such as the Qwen2.5 model; this step is used for subsequent generation of the recommended thread pool configuration;
[0077] c. Query historical thread pool operation data: connect to the historical information database and query the thread pool operation data of the business application in the last hour; these data include "CPU number", "number of active threads in the thread pool", "number of tasks in the thread pool queue", "number of core threads in the thread pool", "thread pool queue size", "CPU usage", "thread pool load" and other information to build a data set;
[0078] d. Call the LSTM model for prediction: Call the built LSTM model, pass in the data set generated in step 3, and get the predicted average CPU usage and average thread pool load in the next hour;
[0079] e. Connect to the vector database: Connect to the vector database and read the previously stored recommended thread pool configuration data sets; these data sets contain the best performing thread pool configurations under different CPU numbers and load conditions;
[0080] f. Build prompt word template: Build prompt word template, splice parameters, splice CPU quantity, average CPU usage and average thread pool load values with the template, build the final prompt word, require to return the recommended thread pool configuration, and stipulate that the data format returned by the large model is JSON;
[0081] g. Call the LLM big model to generate recommended configuration: Use the Langchain framework to call the loaded LLM big model, and according to the built prompt words, make the big model generate the recommended thread pool configuration;
[0082] h. Return recommended configuration: Convert the generated thread pool configuration parameters into JSON format and return them to the client through the API interface.
[0083] On the basis of being in accordance with the common sense in the art, the above-mentioned preferred conditions can be arbitrarily combined to obtain the preferred embodiments of the present invention.
[0084] The positive and progressive effects of the present invention are:
[0085] The above-mentioned method of dynamically tuning the thread pool based on the AI large model realizes the intelligent dynamic adjustment of the thread pool configuration by combining deep learning technology and large language model.
[0086] (1) Improve resource utilization: It can intelligently and dynamically adjust the thread pool configuration according to the real-time thread pool load and system resource usage, reduce the number of threads during business off-peak periods to avoid idle resources; and quickly increase the number of threads during peak periods to shorten task processing time. This significantly improves resource utilization and reduces resource waste.
[0087] (2) Enhance system performance: Through precise parameter adjustment, the present invention can effectively improve the system's processing power and response speed, ensuring that the system can still operate efficiently under high load conditions, thereby improving user experience.
[0088] (3) Improving system stability: The present invention avoids system crash or performance degradation caused by insufficient resources or over-configuration by accurately predicting and adjusting thread pool configuration, thereby enhancing system stability and reliability.
[0089] (4) Reduce manual intervention: Traditional thread pool configuration requires manual adjustment, which is time-consuming and prone to errors. The present invention realizes automatic adjustment, reduces the need for manual intervention, reduces operation and maintenance costs, and reduces the risk of human error.
[0090] (5) Adapt to load changes: It can quickly adapt to dynamic changes in load. Whether it is a sudden high load or a long period of low load, the thread pool configuration can be adjusted in time to ensure that the system is always in the best operating state.
[0091] (6) Improving prediction accuracy: By using the LSTM model and the large language model, the present invention can more accurately predict future system load and CPU usage, thereby generating more reasonable thread pool configuration suggestions, thereby improving the accuracy and reliability of the prediction.
[0092] It not only improves the system's resource utilization and performance, but also enhances the system's stability and reliability, reduces operation and maintenance costs, and provides comprehensive optimization support for business applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0093] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application.
[0094] Figure 1The present invention is an overall flow chart of the method for dynamically tuning the thread pool based on the AI large model.
[0095] Figure 2 The present invention is a flowchart of dynamically tuning thread pool parameters based on the AI large model dynamic tuning thread pool method.
[0096] Figure 3 The present invention is a thread pool operation data collection flow chart of the method for dynamically tuning the thread pool based on the AI large model.
[0097] Figure 4 The present invention is a flowchart of a recommended thread pool configuration data set for a method for dynamically tuning thread pools based on an AI large model.
[0098] Figure 5 The recommended thread pool configuration of the thread pool dynamic tuning method based on the AI large model of the present invention is stored in the vector database flow chart.
[0099] Figure 6 The present invention is a flow chart of building an LSTM model based on the method of dynamically tuning the thread pool of the AI large model.
[0100] Figure 7 This is a flowchart of the AIAgent application execution of the thread pool dynamic tuning method based on the AI large model of the present invention.
[0101] Figure 8 The present invention is a flow chart of a method for dynamically optimizing thread pools based on an AI large model. DETAILED DESCRIPTION
[0102] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0103] Example:
[0104] like Figure 1-8 As shown, a method for dynamically tuning a thread pool based on an AI large model includes the following steps:
[0105] S1. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in the business logic;
[0106] S2. Regularly query recommended configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application;
[0107] S3. Query historical thread pool data: connect to the database that stores the application thread pool operation information, and query the thread pool operation data of the business application within the last hour;
[0108] S4. Predict future load: Based on the queried historical thread pool operation information of the business application as a data set, call the LSTM model to predict the load data within the next hour, including CPU usage and thread pool load;
[0109] S5. Get recommended configuration data set: Connect to the vector database and get recommended thread pool configuration data set. These data sets are generated after stress testing and optimization, and are stored in the vector database in advance. The data set covers recommended thread pool configuration parameters in various environments.
[0110] S6. Generate prompt words: extract the number of CPUs based on the data queried in step 3, and the load data predicted in the next hour from step 4, and combine with the recommended thread pool configuration data queried from the vector database in step 5 to generate prompt words for querying the LLM large model; the prompt words will specify the data format returned by the LLM large model;
[0111] S7. Call the LLM big model to generate recommended configuration: call the LLM big model, pass in the generated prompt words, generate the recommended thread pool configuration, and return;
[0112] S8. Dynamically adjust thread pool parameters: The thread pool component receives the recommended thread pool configuration returned by the AIAgent application, and then uses the configuration to dynamically adjust thread parameters.
[0113] The process of dynamically tuning the thread pool mainly describes that the thread pool component obtains the recommended configuration by periodically calling the AI Agent interface, and then dynamically optimizes and adjusts the thread pool parameters. The process of dynamically tuning the thread pool includes the following steps:
[0114] a. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in business logic;
[0115] b. Regularly query the recommended thread pool configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application. Then, based on the received recommended configuration, the thread pool component dynamically adjusts the core thread number, maximum thread number and other parameters of the thread pool to adapt to the current system load.
[0116] c. Dynamically adjust thread pool parameters: Based on the recommended configuration received, the thread pool component dynamically adjusts parameters such as the number of core threads and maximum number of threads in the thread pool to adapt to the current system load.
[0117] The thread pool runs the data collection process, which mainly describes the entire process from creating a thread pool to data collection, transmission and persistence. The thread pool runs the data collection process and includes the following steps:
[0118] a. Create a thread pool: Create a thread pool by using the thread pool component;
[0119] b. Regularly collect operation data: The thread pool component regularly obtains the operation data of the thread pool, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information;
[0120] c. Output data to log files: Output the collected system and thread pool operation data and other information to log files for subsequent data collection and processing;
[0121] d. Log collection: Use a log collector (open source log collectors such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files. Every time a log file changes, the collection operation will be performed;
[0122] e. Data transmission: The log collector sends the collected data to the message middleware (such as Kafka, RabbitMQ, etc.) for buffering;
[0123] f. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage.
[0124] The process of constructing the recommended thread pool configuration data set describes the entire process from adjusting the number of system CPUs to data cleaning, calculation, screening of the optimal configuration and storage; the optimal thread pool configuration finally screened out will serve as a reference data set for the recommended thread pool configuration given in the LLM model.
[0125] The process of constructing the recommended thread pool configuration data set includes the following steps:
[0126] a. Adjust the number of system CPUs: Adjust the number of system CPUs and set different CPU configurations, such as 4, 8, 12, 16 and other common configurations. This is to collect thread pool operation information under different CPU numbers in the future;
[0127] b. Deploy business applications: Redeploy business applications that have introduced thread pool components under the specified number of CPUs, and provide business interfaces for subsequent stress testing;
[0128] c. Adjust the thread pool configuration parameters: Adjust the thread pool configuration parameters, such as setting the number of core threads to 2, 3, 4, 5, etc., but not exceeding 2n+1 of the number of system CPUs. This is to generate thread pool operation data under different configurations;
[0129] d. Simulate business access scenarios: Use stress testing tools (such as JMeter) to stress test the business interfaces in business applications. During the stress testing process, ensure that the CPU usage rate gradually increases from low utilization to high utilization and reaches the CPU upper limit. The stress testing time lasts for 1 hour.
[0130] e. Collecting operation data: The thread pool component regularly obtains thread pool operation data, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information;
[0131] f. Output data to log file: Output the collected thread pool and CPU data to the log file for subsequent data collection and processing;
[0132] g. Log collection and transmission: Use log collectors (such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files and send the collected data to message middleware (such as Kafka, RabbitMQ, etc.) for buffering;
[0133] h. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage;
[0134] i. Data cleaning and calculation: Use Python tools to connect to the database, read the thread pool running data of the stored business application stress test, and perform data cleaning and calculation;
[0135] j. Filter the optimal configuration: group according to the number of core threads in the thread pool, the number of CPUs, the average CPU usage (1 hour), and the average thread pool load (1 hour), filter according to the thread pool throughput (1 hour), and select the data records with the highest thread pool throughput in different groups;
[0136] k. Store optimal configuration: Store the selected optimal configuration data records in a CSV file for subsequent use.
[0137] The specific steps of data cleaning and calculation include:
[0138] (1) Data integrity check: discard or fill in incomplete data;
[0139] (2) Data deduplication: discard duplicate data to avoid data duplication;
[0140] (3) Data formatting: converting timestamps into date and time, etc.
[0141] (4) Data anomaly check: processing data whose task execution time exceeds the normal time range;
[0142] (5) Data calculation:
[0143] (6) Thread pool throughput (1 hour): the number of tasks that the thread pool can complete per unit time; the calculation formula is: (number of tasks completed by the thread pool (current time) / number of tasks completed by the thread pool (1 hour ago)) / 60;
[0144] (7) Average CPU usage (1 hour): The average CPU usage per unit time. The calculation formula is: Total CPU usage (1 hour) / 60.
[0145] (8) Average thread pool load (1 hour): The average thread pool load per unit time. The calculation formula is: Total thread pool load (1 hour) / 60.
[0146] The process of storing the recommended thread pool configuration into the vector database mainly describes the entire process from loading the recommended configuration data set to data conversion, generating vectors, creating vector data indexes and storing them into the vector database; the process of storing the recommended thread pool configuration data set includes the following steps:
[0147] a. Load the recommended configuration dataset: load the recommended thread pool configuration dataset CSV file in the local computer.
[0148] b. Connect to vector database: Establish a connection with the vector database and prepare to store the recommended configuration data into the database;
[0149] c. Initial embedding model: Initialize the embedding model, for example, using the sentence-transformers / all-MiniLM-L6-v2 model based on HuggingFace to convert text data into vectors;
[0150] d. Data conversion: Convert the data in the loaded CSV file into strings row by row; define two fields: input_str (a string containing CPU usage and thread pool load) and recommended_threads (a recommended thread pool configuration string);
[0151] e. Generate vectors: Use the embedding model to convert string data into vectors; each recommended configuration record will generate a corresponding vector representation;
[0152] f. Store in vector database: Insert the generated vector data into the vector database; these vector data will be used as a reference for subsequent calls to the AI large model to improve the accuracy of generating recommended thread pool configurations.
[0153] The LSTM model construction process describes the entire process from connecting to the historical information database to checking the model existence, selecting features, data preprocessing, dividing the data set, building the LSTM model, training the model, and saving the model; building the LSTM model is mainly used for subsequent prediction of the application load; the LSTM model construction process includes the following steps:
[0154] a. Connect to the historical information database: connect to the database that stores the historical thread pool information of business applications and read the historical thread pool operation data set; these data sets include information such as the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, and thread pool load;
[0155] b. Check whether the model exists: Determine whether there is a trained LSTM model. If not, it means that the model has not been built yet and full training is required using the full data. If it exists, you only need to load the locally trained model, and then use the latest data for incremental training, and start a scheduled task to perform incremental training every hour.
[0156] c. Select features: Select features that are closely related to thread pool load and CPU usage, such as "CPU number", "Number of active threads in thread pool", "Number of tasks in thread pool queue", "Number of core threads in thread pool", "Thread pool queue size", "CPU usage", "Thread pool load", etc.
[0157] d. Data preprocessing: normalize the data and normalize all eigenvalues to the range of [0, 1] to improve the convergence and stability of model training;
[0158] e. Divide the data set: Divide the data set into a training set and a test set. Usually 80% of the data is used as the training set and 20% of the data is used as the test set to train the model and evaluate the performance of the model.
[0159] f. Build LSTM model;
[0160] g. Training model: Use the training set data to train the LSTM model; during the training process, you can set multiple epochs and batch sizes to ensure that the model fully learns the patterns in the data;
[0161] h. Save model: After training is completed, save the model to a file for subsequent use.
[0162] The LSTM model is constructed using the Keras framework and includes the following steps:
[0163] (1) Create a sequential model: Create a sequential model to stack each neural network layer;
[0164] (2) Add LSTM layer: Add two LSTM layers, the number of units in each LSTM layer is 150, and set the input shape to input_shape = (time_step, len(features));
[0165] (3) Add Dropout layer: Add a Dropout layer with a dropout rate of 0.2 to prevent overfitting;
[0166] (4) Add a fully connected layer: Add a fully connected layer and output two values, corresponding to the future thread pool load and CPU usage;
[0167] (5) Compile the model: Compile the model using the Adam optimizer and the mean square error loss function.
[0168] The AIAgent application execution process mainly describes the entire process from providing an API interface to loading the LLM model, querying historical data, calling the LSTM model for prediction, connecting the vector database, building a prompt word template, calling the LLM model to generate a recommended configuration, and returning the recommended configuration; the AIAgent application execution process includes the following steps:
[0169] a. API interface: The AIAgent application provides an API interface for calling thread pool components and querying recommended thread pool configurations;
[0170] b. Load the LLM large model: Use the transformers library to load the local large language model (LLM), such as the Qwen2.5 model; this step is used for subsequent generation of the recommended thread pool configuration;
[0171] c. Query historical thread pool operation data: connect to the historical information database and query the thread pool operation data of the business application in the last hour; these data include "CPU number", "number of active threads in the thread pool", "number of tasks in the thread pool queue", "number of core threads in the thread pool", "thread pool queue size", "CPU usage", "thread pool load" and other information to build a data set;
[0172] d. Call the LSTM model for prediction: Call the built LSTM model, pass in the data set generated in step 3, and get the predicted average CPU usage and average thread pool load in the next hour;
[0173] e. Connect to the vector database: Connect to the vector database and read the previously stored recommended thread pool configuration data sets; these data sets contain the best performing thread pool configurations under different CPU numbers and load conditions;
[0174] f. Build prompt word template: Build prompt word template, splice parameters, splice CPU quantity, average CPU usage and average thread pool load values with the template, build the final prompt word, require to return the recommended thread pool configuration, and stipulate that the data format returned by the large model is JSON;
[0175] g. Call the LLM big model to generate recommended configuration: Use the Langchain framework to call the loaded LLM big model, and according to the built prompt words, make the big model generate the recommended thread pool configuration;
[0176] h. Return recommended configuration: Convert the generated thread pool configuration parameters into JSON format and return them to the client through the API interface.
[0177] This method of dynamically tuning the thread pool based on the AI large model realizes the intelligent dynamic adjustment of the thread pool configuration and improves resource utilization by combining deep learning technology and large language models: the present invention can intelligently and dynamically adjust the thread pool configuration according to the real-time thread pool load and system resource usage. Reduce the number of threads during business troughs to avoid idle resources; quickly increase the number of threads during peak periods to shorten task processing time. This significantly improves resource utilization, reduces resource waste, and enhances system performance: through precise parameter adjustment, the present invention can effectively improve the system's processing power and response speed, ensure that the system can still run efficiently under high load conditions, improve user experience, and improve system stability: the present invention avoids system crashes or performance degradation caused by insufficient or over-configuration of resources by accurately predicting and adjusting the thread pool configuration, enhances the stability and reliability of the system, and reduces manual intervention: traditional thread pool configuration requires manual adjustment, which is time-consuming and error-prone. The present invention realizes automatic adjustment, reduces the need for manual intervention, reduces operation and maintenance costs and the risk of human error, and adapts to load changes: the present invention can quickly adapt to dynamic changes in load, whether it is a sudden high load or a long period of low load, and can adjust the thread pool configuration in time to ensure that the system is always in the best operating state, and improve prediction accuracy: by using LSTM models and large language models, the present invention can more accurately predict future system loads and CPU usage, thereby generating more reasonable thread pool configuration suggestions, improving the accuracy and reliability of predictions, not only improving the resource utilization and performance of the system, but also enhancing the stability and reliability of the system, reducing operation and maintenance costs, and providing comprehensive optimization support for business applications.
[0178] The present invention is not limited to the above-mentioned embodiments. Any changes in shape or structure are within the protection scope of the present invention. The protection scope of the present invention is defined by the attached claims. Those skilled in the art can make various changes or modifications to these embodiments without departing from the principle and essence of the present invention, but these changes and modifications are within the protection scope of the present invention.
Claims
1. A method for dynamically tuning thread pool based on AI large model, characterized in that: The method for dynamically tuning the thread pool based on the AI large model includes the following steps: S1. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in the business logic; S2. Regularly query recommended configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application; S3. Query historical thread pool data: connect to the database that stores the application thread pool operation information, and query the thread pool operation data of the business application within the last hour; S4. Predict future load: Based on the queried historical thread pool operation information of the business application as a data set, call the LSTM model to predict the load data within the next hour, including CPU usage and thread pool load; S5. Obtain a recommended configuration data set: connect to the vector database and obtain a recommended thread pool configuration data set; These data sets are generated after stress testing and optimization, and are stored in the vector database in advance. The data sets also cover the recommended thread pool configuration parameters in various environments. S6. Generate prompt words: extract the number of CPUs based on the data queried in step 3, and the load data predicted in the next hour from step 4, and combine with the recommended thread pool configuration data queried from the vector database in step 5 to generate prompt words for querying the LLM large model; the prompt words will specify the data format returned by the LLM large model; S7. Call the LLM big model to generate recommended configuration: call the LLM big model, pass in the generated prompt words, generate the recommended thread pool configuration, and return; S8. Dynamically adjust thread pool parameters: The thread pool component receives the recommended thread pool configuration returned by the AIAgent application, and then uses the configuration to dynamically adjust thread parameters.
2. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The process of dynamically tuning the thread pool mainly describes that the thread pool component obtains the recommended configuration by periodically calling the AI Agent interface, and then dynamically optimizes and adjusts the thread pool parameters. The process of dynamically tuning the thread pool includes the following steps: a. Create a dynamic thread pool: By using the thread pool component, create a thread pool that supports dynamic configuration adjustment and apply it in business logic; b. Regularly query the recommended thread pool configuration: The thread pool component regularly calls the AIAgent application interface, passes in the business application name, and queries the recommended thread pool configuration parameters of the current application. Then, based on the received recommended configuration, the thread pool component dynamically adjusts the core thread number, maximum thread number and other parameters of the thread pool to adapt to the current system load. c. Dynamically adjust thread pool parameters: Based on the recommended configuration received, the thread pool component dynamically adjusts parameters such as the number of core threads and maximum number of threads in the thread pool to adapt to the current system load.
3. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The thread pool runs the data collection process, which mainly describes the entire process from creating a thread pool to data collection, transmission and persistence. The thread pool runs the data collection process and includes the following steps: a. Create a thread pool: Create a thread pool by using the thread pool component; b. Regularly collect operation data: The thread pool component regularly obtains the operation data of the thread pool, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information; c. Output data to log files: Output the collected system and thread pool operation data and other information to log files for subsequent data collection and processing; d. Log collection: Use a log collector (open source log collectors such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files. Every time a log file changes, the collection operation will be performed; e. Data transmission: The log collector sends the collected data to the message middleware (such as Kafka, RabbitMQ, etc.) for buffering; f. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage.
4. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The process of constructing the recommended thread pool configuration data set describes the entire process from adjusting the number of system CPUs to data cleaning, calculation, screening of the optimal configuration and storage; the optimal thread pool configuration finally screened out will serve as a reference data set for the recommended thread pool configuration given in the LLM model.
5. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The process of constructing the recommended thread pool configuration data set includes the following steps: a. Adjust the number of system CPUs: Adjust the number of system CPUs and set different CPU configurations, such as 4, 8, 12, 16 and other common configurations. This is to collect thread pool operation information under different CPU numbers in the future; b. Deploy business applications: Redeploy business applications that have introduced thread pool components under the specified number of CPUs, and provide business interfaces for subsequent stress testing; c. Adjust the thread pool configuration parameters: Adjust the thread pool configuration parameters, such as setting the number of core threads to 2, 3, 4, 5, etc., but not exceeding 2n+1 of the number of system CPUs. This is to generate thread pool operation data under different configurations; d. Simulate business access scenarios: Use stress testing tools (such as JMeter) to stress test the business interfaces in business applications. During the stress testing process, ensure that the CPU usage rate gradually increases from low utilization to high utilization and reaches the CPU upper limit. The stress testing time lasts for 1 hour. e. Collecting operation data: The thread pool component regularly obtains thread pool operation data, including the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, number of completed tasks, thread pool load, and other information; f. Output data to log file: Output the collected thread pool and CPU data to the log file for subsequent data collection and processing; g. Log collection and transmission: Use log collectors (such as Filebeat, LogStash, Fluent-bit, Flume, etc.) to collect information in log files and send the collected data to message middleware (such as Kafka, RabbitMQ, etc.) for buffering; h. Data persistence: The message middleware is connected to the historical information database (such as MySQL, MongoDB, etc.) and records the buffered data into the database for persistent storage; i. Data cleaning and calculation: Use Python tools to connect to the database, read the thread pool running data of the stored business application stress test, and perform data cleaning and calculation; j. Filter the optimal configuration: group according to the number of core threads in the thread pool, the number of CPUs, the average CPU usage (1 hour), and the average thread pool load (1 hour), filter according to the thread pool throughput (1 hour), and select the data records with the highest thread pool throughput in different groups; k. Store optimal configuration: Store the selected optimal configuration data records in a CSV file for subsequent use.
6. The method for dynamically tuning thread pool based on AI large model as claimed in claim 5, characterized in that: The specific steps of data cleaning and calculation include: (1) Data integrity check: discard or fill in incomplete data; (2) Data deduplication: discard duplicate data to avoid data duplication; (3) Data formatting: converting timestamps into date and time, etc. (4) Data anomaly check: processing data whose task execution time exceeds the normal time range; (5) Data calculation: (6) Thread pool throughput (1 hour): the number of tasks that the thread pool can complete per unit time; the calculation formula is: (number of tasks completed by the thread pool (current time) / number of tasks completed by the thread pool (1 hour ago)) / 60; (7) Average CPU usage (1 hour): The average CPU usage per unit time. The calculation formula is: Total CPU usage (1 hour) / 60. (8) Average thread pool load (1 hour): The average thread pool load per unit time. The calculation formula is: Total thread pool load (1 hour) / 60.
7. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The process of storing the recommended thread pool configuration into the vector database mainly describes the entire process from loading the recommended configuration data set to data conversion, generating vectors, creating vector data indexes and storing them into the vector database; the process of storing the recommended thread pool configuration into the vector database includes the following steps: a. Load the recommended configuration dataset: load the recommended thread pool configuration dataset CSV file in the local computer. b. Connect to vector database: Establish a connection with the vector database and prepare to store the recommended configuration data into the database; c. Initial embedding model: Initialize the embedding model, for example, using the sentence-transformers / all-MiniLM-L6-v2 model based on HuggingFace to convert text data into vectors; d. Data conversion: Convert the data in the loaded CSV file into strings row by row; define two fields: input_str (a string containing CPU usage and thread pool load) and recommended_threads (a recommended thread pool configuration string); e. Generate vectors: Use the embedding model to convert string data into vectors; each recommended configuration record will generate a corresponding vector representation; f. Store in vector database: Insert the generated vector data into the vector database; these vector data will be used as a reference for subsequent calls to the AI large model to improve the accuracy of generating recommended thread pool configurations.
8. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The LSTM model construction process describes the entire process from connecting to the historical information database to checking the model existence, selecting features, data preprocessing, dividing the data set, building the LSTM model, training the model, and saving the model; building the LSTM model is mainly used for subsequent prediction of the application load; the LSTM model construction process includes the following steps: a. Connect to the historical information database: connect to the database that stores the historical thread pool information of business applications and read the historical thread pool operation data set; these data sets include information such as the number of CPUs, CPU usage, number of active threads in the thread pool, number of queue tasks, number of core threads, queue size, and thread pool load; b. Check whether the model exists: Determine whether there is a trained LSTM model. If not, it means that the model has not been built yet and full training is required using the full data. If it exists, you only need to load the locally trained model, and then use the latest data for incremental training, and start a scheduled task to perform incremental training every hour. c. Select features: Select features that are closely related to thread pool load and CPU usage, such as "CPU number", "Number of active threads in thread pool", "Number of tasks in thread pool queue", "Number of core threads in thread pool", "Thread pool queue size", "CPU usage", "Thread pool load", etc. d. Data preprocessing: normalize the data and normalize all eigenvalues to the range of [0, 1] to improve the convergence and stability of model training; e. Divide the data set: Divide the data set into a training set and a test set. Usually 80% of the data is used as the training set and 20% of the data is used as the test set to train the model and evaluate the performance of the model. f. Build LSTM model; g. Training model: Use the training set data to train the LSTM model; during the training process, you can set multiple epochs and batch sizes to ensure that the model fully learns the patterns in the data; h. Save model: After training is completed, save the model to a file for subsequent use.
9. The method for dynamically tuning thread pool based on AI large model as claimed in claim 8, characterized in that: The LSTM model is constructed using the Keras framework and includes the following steps: (1) Create a sequential model: Create a sequential model to stack each neural network layer; (2) Add LSTM layer: Add two LSTM layers, the number of units in each LSTM layer is 150, and set the input shape to input_shape = (time_step, len(features)); (3) Add Dropout layer: Add a Dropout layer with a dropout rate of 0.2 to prevent overfitting; (4) Add a fully connected layer: Add a fully connected layer and output two values, corresponding to the future thread pool load and CPU usage; (5) Compile the model: Compile the model using the Adam optimizer and the mean square error loss function.
10. The method for dynamically tuning thread pool based on AI large model according to claim 1, characterized in that: The AIAgent application execution process mainly describes the entire process from providing an API interface to loading the LLM model, querying historical data, calling the LSTM model for prediction, connecting the vector database, building a prompt word template, calling the LLM model to generate a recommended configuration, and returning the recommended configuration; the AIAgent application execution process includes the following steps: a. API interface: The AIAgent application provides an API interface for calling thread pool components and querying recommended thread pool configurations; b. Load the LLM large model: Use the transformers library to load the local large language model (LLM), such as the Qwen2.5 model; this step is used for subsequent generation of the recommended thread pool configuration; c. Query historical thread pool operation data: connect to the historical information database and query the thread pool operation data of the business application in the last hour; these data include "CPU number", "number of active threads in the thread pool", "number of tasks in the thread pool queue", "number of core threads in the thread pool", "thread pool queue size", "CPU usage", "thread pool load" and other information to build a data set; d. Call the LSTM model for prediction: Call the built LSTM model, pass in the data set generated in step 3, and get the predicted average CPU usage and average thread pool load in the next hour; e. Connect to the vector database: Connect to the vector database and read the previously stored recommended thread pool configuration data sets; these data sets contain the best performing thread pool configurations under different CPU numbers and load conditions; f. Build prompt word template: Build prompt word template, splice parameters, splice CPU quantity, average CPU usage and average thread pool load values with the template, build the final prompt word, require to return the recommended thread pool configuration, and stipulate that the data format returned by the large model is JSON; g. Call the LLM big model to generate recommended configuration: Use the Langchain framework to call the loaded LLM big model, and according to the built prompt words, make the big model generate the recommended thread pool configuration; h. Return recommended configuration: Convert the generated thread pool configuration parameters into JSON format and return them to the client through the API interface.
Citation Information
Patent Citations
Deep learning-based thread pool adaptive capacity adjustment method and device
CN114741186A
Thread pool adjustment method and device, computer equipment and storage medium
CN117453356A
Method and device for expanding and shrinking capacity of thread pool
CN118467374A
Database intelligent parameter tuning system based on big language model enhancement
CN118467496A
LLM-based OpenCL program performance optimization method and system
CN118672590A