Thread pool configuration change method and device, equipment and storage medium
By collecting thread pool load indicator data and historical benchmark data, identifying abnormal states and implementing configuration changes, the problem of thread pool parameter setting is solved, and thread pools can be flexible in response to complex concurrent scenarios and improve system performance.
Patent Information
- Application Number
- CN202411619087.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-13
- Publication Date
- 2025-03-18
AI Technical Summary
The existing thread pool parameter setting method is relatively solid, and it is impossible to flexibly deal with complex concurrent scenarios, resulting in system performance degradation and insufficient resource utilization.
By collecting load indicator data during thread pool operation, comparing it with the pre-acquisitioned historical benchmark data, identifying exception status, and implementing configuration changes based on this, dynamically adjusting thread pool configuration.
It effectively solves the problem of setting and solidifying thread pool parameters, allowing thread pools to flexibly cope with different concurrent scenarios and improves system stability and performance.
Smart Images

Figure CN119645626A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a thread pool configuration change method, apparatus, device and storage medium. Background Art
[0002] In modern computer systems, in order to improve system response speed and overall performance, multithreading technology has become a key means of handling concurrent tasks. By running multiple threads simultaneously, multithreading technology can fully utilize the computing power of multi-core processors, effectively shorten task processing time, and improve system throughput and user experience. In particular, multithreading technology is widely used in multithreaded servers and database management systems such as Nginx, Tomcat, and MySQL. By concurrently processing multiple user requests or database operations, high concurrent access and low-latency response are achieved.
[0003] The thread pool is a thread management tool based on the pooling concept. It allocates available thread resources to concurrently executed tasks by pre-creating and maintaining a certain number of threads. This method avoids the overhead caused by frequent creation and destruction of threads, and effectively improves the performance and scalability of the system.
[0004] At present, the common thread pool parameter setting method mainly relies on computer hardware resources, such as the number of CPU cores and memory size, and is calculated through formulas. Although this setting method can reflect the limitations of system resources to a certain extent, in actual applications, there are often multiple thread pools running at the same time. These thread pools will compete with each other for system resources, making it difficult to achieve the optimal parameter setting for a single thread pool. In addition, with the continuous development of application systems and the continuous changes in user needs, concurrent scenarios are becoming more and more complex and diverse. The formulaic thread pool parameter setting method cannot flexibly respond to these complex scenarios, which may lead to problems such as system performance degradation and insufficient resource utilization.
[0005] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0006] The main purpose of this application is to provide a thread pool configuration change method, device, equipment and storage medium, aiming to solve the technical problem that the relatively rigid parameter setting method of the thread pool cannot cope with various complex concurrent scenarios.
[0007] To achieve the above purpose, the present application provides a thread pool configuration change method, the thread pool configuration change method comprising the following steps:
[0008] Collect the load indicator data of the thread pool during operation;
[0009] Comparing the load indicator data with pre-acquired historical benchmark data to identify abnormal states of the thread pool;
[0010] Based on the abnormal state of the thread pool, a configuration change operation is implemented.
[0011] In one embodiment, the step of implementing a configuration change operation based on the abnormal state of the thread pool includes:
[0012] Using a predefined configuration adjustment rule set to match the configuration change action of the abnormal state;
[0013] Update the configuration items of the configuration center according to the configuration change action, and push the configuration update information through the configuration center, where the configuration center is the configuration storage center of the thread pool;
[0014] The configuration change information is received, and the configuration of the thread pool is dynamically adjusted according to the configuration change information.
[0015] In one embodiment, the step of implementing a configuration change operation based on the abnormal state of the thread pool further includes:
[0016] Update the configuration items of the configuration center according to the thread pool configuration information input in the client interface, and push the configuration update information through the configuration center;
[0017] The configuration change information is received, and the configuration of the thread pool is dynamically adjusted according to the configuration change information.
[0018] In one embodiment, the step of updating the configuration items of the configuration center according to the thread pool configuration information inputted through the client interface and pushing the configuration update information through the configuration center includes:
[0019] Visualize thread pool configuration information and operating indicators so that users can monitor real-time data and make configuration change decisions.
[0020] In one embodiment, the step of comparing the load indicator data with pre-acquired historical benchmark data to identify an abnormal state of the thread pool includes:
[0021] If an abnormal state of the thread pool is detected, an alarm notification is issued through the communication application.
[0022] In one embodiment, before the step of collecting the load index data of the thread pool during operation, the step includes:
[0023] Submits tasks to a pre-initialized thread pool and executes the tasks through the thread pool.
[0024] In one embodiment, the thread pool is an enhanced thread pool, and the step of submitting the task to a pre-initialized thread pool and executing the task through the thread pool includes:
[0025] Submit the task to the enhanced thread pool, and pass context parameters to the child thread through the parent thread;
[0026] When the task is rejected, the rejected task is queued for retry.
[0027] In addition, to achieve the above purpose, the present application also provides a thread pool configuration change device, the thread pool configuration change device comprising:
[0028] The data collection module is used to collect the load index data of the thread pool during operation;
[0029] An abnormality identification module, used to compare the load indicator data with pre-acquired historical benchmark data to identify abnormal states of the thread pool;
[0030] The configuration change module is used to implement a configuration change operation based on the abnormal state of the thread pool.
[0031] In addition, to achieve the above-mentioned purpose, the present application also provides a terminal device, which includes a memory, a processor, and a thread pool configuration change program stored in the memory and executable on the processor, and the thread pool configuration change program, when executed by the processor, implements the steps of the thread pool configuration change method as described above.
[0032] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a thread pool configuration change program is stored, and when the thread pool configuration change program is executed by a processor, the steps of the thread pool configuration change method as described above are implemented.
[0033] One or more technical solutions proposed in this application have at least the following technical effects:
[0034] This application can obtain real-time information about the current state of the thread pool by collecting the load index data of the thread pool during operation, and compare the collected load index data with the pre-created historical benchmark data to identify whether the thread pool is in an abnormal state. If it is identified as an abnormal state, the corresponding configuration change operation can be implemented based on this information. Through dynamic adjustment based on actual operation data, the problem of relatively rigid thread pool parameter settings is effectively solved, allowing the thread pool to respond to different concurrent scenarios more flexibly, providing a strong guarantee for the stable operation and efficient performance of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1A flowchart of a first exemplary embodiment of a method for changing thread pool configuration in this application;
[0036] Figure 2 A flowchart of a second exemplary embodiment of a method for changing thread pool configuration in this application;
[0037] Figure 3 Retry flowchart for task rejection;
[0038] Figure 4 This is a schematic diagram of the module structure of the thread pool configuration change device in the embodiment of the present application;
[0039] Figure 5 A schematic diagram of the device structure of the hardware operating environment involved in the thread pool configuration change method in the embodiment of the present application.
[0040] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0041] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0042] The main solution of the embodiment of the present application is: after receiving the task, the thread pool processes the task, and while the thread pool executes the task, monitors the running status of the thread pool to collect the load index information of the thread pool during operation, and compares the load index data with the historical benchmark data obtained in advance to identify the abnormal state of the thread pool; when it is identified that the thread pool is in an abnormal running state, a notification is issued through the communication application and / or a configuration change operation is implemented. The thread pool is an enhanced thread pool, and the task is submitted to the enhanced thread pool, and the context parameters are passed to the child thread through the parent thread; when the task is rejected, the rejected task is queued and retried.
[0043] This application actually considers that the common thread pool parameter setting method mainly depends on computer hardware resources, such as setting parameters such as the number of CPU cores and memory size through formulaic calculations. However, there are often multiple thread pools in the application system, and system resources constrain each other. This relatively solidified parameter setting method cannot cope with various complex concurrent scenarios, and because the configuration of the thread pool is initialized when the system starts, and these configuration information is static during system operation. Therefore, to change these parameters, it is necessary to restart the system to make the new configuration effective, which has a certain impact on the continuity of the business. In addition, the thread pool is a complete black box for development and operation and maintenance personnel during the operation of the system, and the operation status cannot be perceived. When an abnormal situation occurs in the thread pool, such as a sudden increase in traffic causing thread pool tasks to pile up, the downstream system responds too slowly, causing the thread pool tasks to execute too long, etc., the system cannot send an alarm notification to the development and operation and maintenance personnel for the abnormal situation of the thread pool.
[0044] Currently, some open source systems can monitor thread pool related indicators by exposing core thread count, task queue, etc. However, these open source systems often pursue universality and cannot meet specific needs or require more customized development. At the same time, they can only provide basic thread pool indicator monitoring and lack in-depth monitoring of the internal running status of the thread pool.
[0045] Based on this, the embodiment of the present application proposes a solution, in which the thread pool processes the task after receiving it, and while the thread pool executes the task, monitors the running status of the thread pool to collect the load index information of the thread pool during operation, and compares the load index data with the historical benchmark data acquired in advance to identify the abnormal state of the thread pool; when it is identified that the thread pool is in an abnormal running state, a notification is sent through the communication application and / or a configuration change operation is implemented. Through dynamic adjustment based on actual running data, the problem of relatively solidified thread pool parameter settings is effectively solved, providing a strong guarantee for the stable operation and efficient performance of the system.
[0046] Specifically, the following are the detailed steps of the first exemplary embodiment of the thread pool configuration change method of this application:
[0047] Reference Figure 1 , Figure 1 This is a flowchart of the first exemplary embodiment of the thread pool configuration change method of this application. In this embodiment, the thread pool configuration change method includes steps S10 to S40:
[0048] Step S10, collecting load index data of the thread pool during operation;
[0049] In a feasible implementation, step S10 may include steps S11 to S12:
[0050] It should be noted that before implementing step S10, a thread pool is initialized, and after the initialization is completed, the thread pool starts to run and is ready to receive and execute tasks. While the thread pool is running, the running state of the thread pool is monitored to collect load index data of the thread pool during operation.
[0051] This embodiment uses an indicator collection module and utilizes a message queue to exchange information between different modules, and sends messages to the monitoring and alarm module through the message queue.
[0052] Specifically, the indicator collection module monitors several key points in the life cycle of the thread pool: when the thread pool is initialized, the indicator collection module captures this event and constructs a PoolInit message containing thread pool initialization information, such as the number of core threads, the maximum number of threads, the work queue type, etc. The PoolInit message is sent asynchronously to the message queue so that the monitoring and alarm module can receive and record the thread pool creation event.
[0053] If the configuration parameters of the thread pool are updated at runtime, the indicator collection module detects this change and creates a PoolUpdate message containing the updated configuration parameters and sends it to the message queue.
[0054] When the thread pool is destroyed or closed, the indicator collection module generates a PoolClose message containing the thread pool closing information and sends it to the message queue so that the monitoring and alarm module can know the end of the thread pool life cycle.
[0055] Furthermore, the indicator collection module also monitors the execution status of tasks in the thread pool:
[0056] When a task is completed in the thread pool, the indicator collection module captures this event, constructs a TaskTrace message containing information related to the task execution, and sends it to the message queue. The monitoring and alarm module can use this information to analyze the efficiency of task execution and the performance of the thread pool.
[0057] If a task is rejected because the thread pool is full or for other reasons, the indicator collection module will generate a TaskReject message containing the task rejection information. This message is sent to the message queue, and the monitoring and alarm module can use it to identify potential performance problems or improper configurations.
[0058] Furthermore, the indicator collection module periodically collects thread pool parameter information:
[0059] The indicator collection module will enable a scheduled task to regularly collect the current parameter information of all thread pools. This information is encapsulated into a thread pool tracking message, namely PoolTrace message, and sent to the message queue so that the monitoring and alarm module can continue to track the status of the thread pool.
[0060] The embodiment of the present application describes the busyness or idleness of the thread pool through three thread pool-related load indicator data, namely: thread pool activity, task queue utilization, and memory usage.
[0061] Specifically, thread pool activity refers to the number of threads currently executing tasks. This indicator can be obtained by analyzing TaskTrace messages and PoolTrace messages. TaskTrace messages record the execution of tasks, including the start and end time of tasks. By counting the number of tasks completed within a certain period of time, the monitoring and alarm module can estimate the number of active threads. PoolTrace messages provide more direct data. They are sent regularly and contain real-time information on the current number of active threads. The monitoring and alarm module can calculate the activity of the thread pool through these data, thereby evaluating the utilization and performance of the thread pool.
[0062] The task queue utilization reflects the ratio of the number of tasks waiting to be executed in the thread pool to the total capacity. This indicator can be obtained by analyzing the PoolTrace message, which contains the current length of the task queue. The monitoring and alarm module can calculate the queue utilization by comparing the queue length with the maximum capacity of the queue. In addition, the frequency of TaskReject messages can also provide clues about queue utilization, because tasks are usually rejected because the queue is full.
[0063] Memory usage is usually not directly obtained through thread pool messages, because thread pool messages mainly focus on task execution and thread status. However, memory usage can be indirectly inferred by monitoring the overall performance data of the system. For example, if TaskTrace messages show an abnormal increase in task execution time, this may indicate that the system is running out of memory, resulting in frequent garbage collection or memory allocation failures. The monitoring and alarm module can combine operating system-level monitoring data, such as memory usage data obtained through the operating system's API or third-party monitoring tools, to comprehensively evaluate memory usage.
[0064] Step S20, comparing the load index data with pre-acquired historical benchmark data to identify an abnormal state of the thread pool;
[0065] It should be noted that, first, historical benchmark data is collected and organized. This data is usually recorded during the stable operation of the thread pool, including the normal range or expected values of key indicators such as thread pool activity, task queue utilization, and memory usage. For example, if the design goal of the thread pool is to maintain a certain number of active threads, then we can record this number as a benchmark value for activity. Similarly, the maximum length and average length of the task queue can also be used as benchmark data for queue utilization.
[0066] The indicator collection module obtains the current values of thread pool activity, task queue utilization, and memory usage from the message queue.
[0067] Furthermore, through the above monitoring and alarm module, the current values of thread pool activity, task queue utilization, and memory usage are compared with historical benchmark data to analyze the difference between the current data and the benchmark data. For example, if the current number of active threads exceeds the historical benchmark value, this may indicate that the thread pool is overloaded. If the task queue length continues to exceed the benchmark value, this may mean that the task processing capacity is insufficient or there is a performance bottleneck.
[0068] Finally, the monitoring and alarm module takes corresponding measures based on the comparison results.
[0069] Step S30: If it is detected that the thread pool state is abnormal, an alarm notification is issued through the communication application.
[0070] Specifically, if an abnormal state is detected, an alarm mechanism is immediately triggered, which usually includes sending a notification to the system administrator or operation and maintenance team, which can be in the form of email, SMS, instant message or automatic phone call, etc. The alarm notification will contain key information, such as the name of the thread pool, the problem detected, the current timestamp, and possible solution suggestions.
[0071] Communication applications play a vital role in the delivery of alarm notifications. These applications can be internal notification systems of enterprises or third-party messaging services. The monitoring alarm module interacts with these communication applications to ensure that the alarm information can be accurately conveyed to the intended recipients.
[0072] In addition, in order to improve the effectiveness of alarms, the monitoring alarm module can also classify and prioritize alarm information according to the severity and urgency of the problem. For example, for alarms with a higher severity level, the responsible person may be notified directly via SMS or phone, while for general-level alarms, they may be notified via email or instant messaging.
[0073] After the alarm notification is sent, the monitoring alarm module can also track the handling of the alarm. This includes recording the time when the alarm was sent, the response of the recipient, and the subsequent recovery operation. Such a tracking mechanism helps to evaluate the effectiveness of the alarm system and make adjustments and optimizations when necessary.
[0074] Step S40: Implement a configuration change operation based on the abnormal state of the thread pool.
[0075] In a feasible implementation, step S40 may include steps A1 to A3:
[0076] Step A1, using a predefined configuration adjustment rule set to match the configuration change action of the abnormal state;
[0077] It should be noted that the logic of configuration adjustment can be defined using a rule engine, which allows a series of rules to be defined, and these rules automatically adjust the system configuration based on specific conditions and actions.
[0078] It should be noted that the rule set is based on the analysis of the historical performance of the thread pool. System administrators or performance analysts will evaluate the performance of the thread pool under different loads and determine which indicators may cause performance bottlenecks or system instability when reaching critical values. For example, they may observe that when the thread pool utilization exceeds 80% and the task queue length exceeds 100, the processing capacity of the thread pool will decrease, resulting in an increase in task response time.
[0079] Based on these observations, a configuration adjustment rule is defined with the condition: if the thread pool utilization exceeds 80% and the task queue length exceeds 100, the action is: increase the number of core threads in the thread pool.
[0080] Integrate the rule engine with the monitoring system used in the embodiment of the present application to ensure that the rule engine can receive real-time monitoring data and evaluate rule conditions based on this data.
[0081] Specifically, when the monitoring alarm module detects that the thread pool utilization exceeds 80% and the task queue length exceeds 100, the rule engine triggers the corresponding operation instruction. Increasing the number of core threads in the thread pool can provide more processing power to cope with the current load.
[0082] The integration of the rule engine with the monitoring system ensures that the rule engine can receive real-time monitoring data. This integration is usually achieved through API calls or message queues, allowing data to flow between the monitoring system and the service. When the rule engine receives the data, it performs a series of logical judgments to determine whether an operation instruction needs to be executed. If the conditions are met, the rule engine generates a configuration change request through the monitoring alarm module and sends it to the configuration center.
[0083] Step A2: updating the configuration items of the configuration center according to the configuration change action, and pushing the configuration update information through the configuration center, where the configuration center is the configuration storage center of the thread pool;
[0084] It should be noted that the configuration center is the configuration storage center of the thread pool, which stores and manages all configuration information of the thread pool and ensures that these parameters can be used by various components of the thread pool.
[0085] Specifically, after receiving the configuration change request, the configuration center updates its stored configuration items according to the matching configuration change action to reflect the new configuration parameters.
[0086] Furthermore, to ensure that all relevant thread pool components can receive configuration updates, the configuration center will push these update information to various components of the thread pool. This process may involve multiple services within the thread pool, such as the task scheduler, thread pool manager, etc. After receiving the configuration update information, each component will adjust its behavior according to the new configuration parameters.
[0087] Step A3: receiving the configuration change information, and dynamically adjusting the configuration of the thread pool according to the configuration change information.
[0088] Specifically, after receiving the configuration update information, each component of the thread pool needs to parse the information and apply the new configuration parameters to the actual running environment. For example, if the number of core threads is increased, the thread pool manager needs to be responsible for creating more threads so that the thread pool can handle more tasks.
[0089] In this process, the various components of the thread pool need to maintain a high degree of collaboration to ensure that the configuration changes can be smoothly transitioned without interrupting or affecting the tasks being executed. This may involve operations such as gracefully stopping existing threads, reallocating tasks, and starting new threads.
[0090] In addition, to ensure the validity of the configuration changes, a series of checks and verifications can be performed to ensure that the new configuration parameters are within a reasonable range and that they match the existing system resources. If the new configuration parameters exceed the system's carrying capacity, the thread pool can reject these changes and feedback error information to the configuration center.
[0091] Once the configuration update information is successfully applied, the state of the thread pool will be adjusted accordingly to reflect the new configuration parameters. At this point, the dynamic adjustment of the thread pool is completed, and it will manage tasks and threads according to the new configuration parameters to optimize performance and improve resource utilization.
[0092] In another feasible implementation, step S40 may include steps B1 to B2:
[0093] Step B1, updating the configuration items of the configuration center according to the thread pool configuration information input through the client interface, and pushing the configuration update information through the configuration center;
[0094] Step B2: receiving the configuration change information, and dynamically adjusting the configuration of the thread pool according to the configuration change information.
[0095] Specifically, a system administrator or user can input new thread pool configuration information through a client interface. This interface can be a graphical user interface (GUI) that provides various configuration options, such as the number of core threads, the maximum number of threads, the capacity of the task queue, etc. The user can input new configuration values according to the actual operation of the system. For example, if the system is running under high load, the user may choose to increase the number of core threads to improve processing power.
[0096] Once new configuration information is entered, it will be sent to the configuration center. The configuration center is the storage and management center of the thread pool configuration information. It is responsible for storing all configuration parameters and pushing these updates to various components of the thread pool when an update request is received.
[0097] Furthermore, after receiving the configuration update information, the various components of the thread pool will start processing these new configuration parameters. This may involve adjusting the internal management strategies of the thread pool, such as thread creation and destruction, task scheduling and execution, etc. For example, if the number of core threads is increased, the thread pool manager will start creating new threads so that the thread pool can handle more tasks.
[0098] When applying new configuration parameters, the various components of the thread pool need to ensure a smooth transition to avoid interrupting ongoing tasks. This may involve gracefully stopping existing threads, reassigning tasks to new threads, and ensuring that all tasks are properly processed after the configuration change.
[0099] In addition, to ensure the validity of the configuration changes, the thread pool may perform a series of checks and verifications. This includes confirming whether the new configuration parameters are within a reasonable range and whether they can match the existing system resources. If the new configuration parameters exceed the system's carrying capacity, the thread pool can reject these changes and feedback error information to the configuration center.
[0100] Furthermore, before step B1: updating the configuration items of the configuration center according to the thread pool configuration information inputted in the client interface and pushing the configuration update information through the configuration center, step B0 may be included:
[0101] Step B0, visualize the thread pool configuration information and operation indicators, so that users can monitor real-time data and make configuration change decisions.
[0102] Specifically, we first need to collect the configuration information and operation index data of the thread pool, including but not limited to the key performance indicators such as the current number of threads in the thread pool, queue length, task completion rate, and response time.
[0103] Display the collected data through a visualization tool or platform. For example, you can use an open source data visualization and monitoring platform such as Grafana, which supports multiple data sources and can create customized dashboards to display the status of the thread pool.
[0104] In Grafana, users can create a dedicated dashboard that contains multiple panels, each of which displays different indicators. For example, one panel can show the trend of the number of active threads and the maximum number of threads in the thread pool, another panel can show the length of the task queue, and another panel can show the execution time and success rate of the task.
[0105] Through these visual charts, users can quickly identify performance bottlenecks and anomalies in the thread pool. For example, if the length of the task queue is found to be continuously increasing, it may mean that the processing capacity of the thread pool is insufficient to cope with the current load. At this time, users can consider increasing the size of the thread pool. If the response time increases suddenly, it may indicate insufficient system resources or other performance issues. Users can make corresponding optimizations based on this information.
[0106] Further, refer to Figure 2 , Figure 2 This is a flow chart of the second embodiment of the thread pool configuration change method of this application. Figure 1 In the embodiment shown, in this embodiment, step S10 may include step S00: submitting the task to a pre-initialized thread pool, and executing the task through the thread pool.
[0107] Specifically, when the system starts, the thread pool needs to be initialized first. The system administrator or developer needs to define the parameters of the thread pool according to the needs of the application. For example, for a high-concurrency Web service, a larger number of core threads and a larger maximum number of threads may be set to ensure that a large number of sudden requests can be handled. Use the API provided by the thread pool framework to create a thread pool instance. In Java, you can use the Executors factory class to create different types of thread pools, such as fixed-size thread pools, cacheable thread pools, etc. Tasks in the application (such as processing HTTP requests, performing background calculations, etc.) are encapsulated into task objects and submitted to the thread pool. The thread pool will decide whether to execute immediately or put it in the queue for later execution based on the usage of the current thread.
[0108] Furthermore, when a task is submitted to the thread pool and the number of active threads is lower than the number of core threads, the thread pool will create a new thread to process the task. The thread pool maintains a task queue, and the newly submitted task enters the queue first. The threads in the thread pool will poll the queue, obtain and execute the tasks in the queue.
[0109] If the task queue is full, newly submitted tasks will trigger the thread pool's saturation strategy, such as creating non-core threads or rejecting tasks. When a thread is blocked for reasons such as waiting for I / O operations while executing a task, the thread pool will manage the status of these threads. When a thread is inactive for a long time or the task is completed, the thread pool will recycle these thread resources to free up system resources.
[0110] In a feasible implementation, step S00 may include steps S01 to S02:
[0111] Step S01, submitting the task to the enhanced thread pool, and passing context parameters to the child thread through the parent thread;
[0112] It should be noted that in a multi-threaded environment, child threads usually need to access the parent thread's context information, such as user session data, request ID, etc. The enhanced thread pool supports the parent thread to pass context parameters to the child thread, so that the child thread can directly access these parameters without relying on global variables. This mechanism not only reduces the reliance on global variables, but also simplifies communication between threads, making the program more modular and easier to maintain.
[0113] In addition, this context passing mechanism is essential for functions such as link tracking, logging, and maintaining sessions. For example, in a microservice architecture, each service request needs to have a unique request ID to track the entire request processing process. By passing context parameters in the thread pool, it can be ensured that each child thread can access this request ID, thereby achieving complete link tracking.
[0114] Step S02: when the task is rejected, the rejected task is queued for retry.
[0115] It should be noted that, specifically, under high load, the thread pool may reject newly submitted tasks. For critical tasks, such as financial transactions or order processing, it is necessary to ensure that these tasks can be executed even when the thread pool is fully loaded. The enhanced thread pool supports a task rejection retry mechanism. When a task is rejected, the system will try to re-queue the task for execution instead of discarding it directly. This mechanism can minimize the task discard rate and ensure that critical tasks are processed.
[0116] like Figure 3 , Figure 3 This is the task rejection retry flowchart. After the task is submitted, a task to be executed is sent to the thread pool. The thread pool first checks whether the current number of core threads has reached the preset upper limit.
[0117] If the number of core threads has not reached the upper limit (marked as "N"), a new worker thread is created to perform this task. If the number of core threads has reached the upper limit, the process continues to the next step.
[0118] Next, the thread pool checks whether the length of the task queue has reached the preset upper limit. If the task queue has not reached the upper limit (marked as "N"), the task is added to the task queue and waits for execution. If the task queue has reached the upper limit, the process continues to the next step.
[0119] The thread pool continues to check whether the current maximum number of threads has reached the preset upper limit. If the maximum number of threads has not reached the upper limit (marked as "N"), a new worker thread is created to perform this task. If the maximum number of threads has reached the upper limit, the process continues to the next step.
[0120] In this case, the thread pool will try to re-enqueue the task. If the task can be successfully enqueued (marked as "N"), the task will wait for subsequent execution. If the task still cannot be enqueued, the process continues to the next step.
[0121] The thread pool checks whether the task has been waiting for more than the preset timeout. If the task has not timed out (marked as "N"), the task will remain in the queue waiting for execution. If the task has timed out, the process enters the last step.
[0122] If a task cannot be executed after all possible retries and has timed out, the thread pool will discard the task. Discarding a task may involve logging, sending an alert notification, etc. to notify the system administrator or developer that the task failed to execute successfully.
[0123] The task rejection retry mechanism ensures that the thread pool can handle as many tasks as possible under high load conditions, and also provides a mechanism to handle tasks that cannot be executed immediately. Through the retry and timeout mechanisms, the system can ensure the execution of critical tasks as much as possible under limited resources.
[0124] In addition, when the service process is shut down, if the thread pool is destroyed directly, tasks that have been submitted but not yet executed may be lost, or tasks that are being executed may be interrupted. The enhanced thread pool supports the graceful shutdown of the thread pool, ensuring that all tasks being executed can be completed while preventing the submission of new tasks. The enhanced thread pool will wait for all tasks being executed to complete before actually destroying the thread pool. In this way, the integrity and consistency of tasks can be ensured even when the service is shut down. For example, in an online payment system, if the service needs to be restarted, the enhanced thread pool will wait for all ongoing payment transactions to complete before shutting down the service, thereby avoiding transaction interruptions or data inconsistencies.
[0125] In addition, the present application also proposes a thread pool configuration change device, the thread pool configuration change device comprising:
[0126] The data collection module 10 is used to collect the load index data of the thread pool during operation;
[0127] An abnormality identification module 20, used to compare the load indicator data with pre-acquired historical benchmark data to identify abnormal states of the thread pool;
[0128] The configuration change module 30 is used to implement a configuration change operation based on the abnormal state of the thread pool.
[0129] The thread pool configuration change device provided by the present application adopts the thread pool configuration change method in the above embodiment, aiming to solve the technical problem that the relatively fixed parameter setting method of the thread pool cannot cope with various complex concurrent scenarios. Compared with the prior art, the beneficial effects of the thread pool configuration change device provided by the present application are the same as the beneficial effects of the thread pool configuration change method provided by the above embodiment, and the other technical features in the thread pool configuration change device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0130] The present application provides a thread pool configuration change device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the thread pool configuration change method in the above-mentioned embodiment one.
[0131] Reference below Figure 5, which shows a schematic diagram of the structure of the thread pool configuration change device used to implement the embodiment of the present application. The thread pool configuration change device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The thread pool configuration change device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0132] like Figure 5 As shown, the thread pool configuration change device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the thread pool configuration change device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. Communication device 1009 can allow thread pool configuration change device to communicate wirelessly or wired with other devices to exchange data. Although thread pool configuration change device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or less systems can be implemented or have alternatively.
[0133] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0134] The thread pool configuration change device provided by the present application adopts the thread pool configuration change method in the above embodiment, aiming to solve the technical problem that the relatively solidified parameter setting method of the thread pool cannot cope with various complex concurrent scenarios. Compared with the prior art, the beneficial effects of the thread pool configuration change device provided by the present application are the same as the beneficial effects of the thread pool configuration change method provided by the above embodiment, and the other technical features in the thread pool configuration change device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0135] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0136] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0137] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the thread pool configuration change method in the above-mentioned embodiment.
[0138] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0139] The computer-readable storage medium may be included in the thread pool configuration change device; or may exist independently without being assembled into the thread pool configuration change device.
[0140] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0141] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0142] The modules involved in the embodiments described in the present application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0143] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned thread pool configuration change method, and is intended to solve the technical problem that the relatively solidified parameter setting method of the thread pool cannot cope with various complex concurrent scenarios. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the thread pool configuration change method provided by the above-mentioned embodiment, and will not be repeated here.
[0144] The present application also provides a computer program product, including a computer program, which implements the steps of the thread pool configuration change method as described above when executed by a processor.
[0145] The computer program product provided by this application is intended to solve the technical problem that the relatively fixed parameter setting method of the thread pool cannot cope with various complex concurrent scenarios. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the thread pool configuration change method provided in the above embodiment, which will not be repeated here.
[0146] Compared with the prior art, the thread pool configuration change method, device, equipment, medium and computer product proposed in the embodiment of the present application extract the business feature information of the target business, perform data standardization processing on the business feature information, obtain standard feature data, perform hash processing on the standard feature data, obtain unique feature data, perform numerical processing and splicing processing on the unique feature data, obtain the first business feature value, accumulate the first business feature value of the target business, obtain the target business feature value, and finally compare the target business feature value with the feature value set to obtain the thread pool configuration change result. Compared with the traditional method of identifying duplicate businesses by generating a unique key value or a continuous serial number for each business, it is more efficient, flexible and reliable. Based on the solution of the present application, by subjecting the business of complex scenarios to a series of simple transformations and finally converting it into a comparison of two numbers, the comparison process is very intuitive and efficient. The system only needs to simply compare whether the two values are equal to quickly determine whether the two businesses are exactly the same.
[0147] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0148] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0149] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, a controlled terminal, or a network device, etc.) to execute the method of each embodiment of the present application.
[0150] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A thread pool configuration change method, characterized in that: The thread pool configuration change method comprises: Collect the load indicator data of the thread pool during operation; Comparing the load indicator data with pre-acquired historical benchmark data to identify abnormal states of the thread pool; Based on the abnormal state of the thread pool, a configuration change operation is implemented.
2. The thread pool configuration changing method according to claim 1, characterized in that: The step of implementing a configuration change operation based on the abnormal state of the thread pool includes: Using a predefined configuration adjustment rule set to match the configuration change action of the abnormal state; Update the configuration items of the configuration center according to the configuration change action, and push the configuration update information through the configuration center, where the configuration center is the configuration storage center of the thread pool; The configuration change information is received, and the configuration of the thread pool is dynamically adjusted according to the configuration change information.
3. The thread pool configuration change method according to claim 1, characterized in that: The step of implementing the configuration change operation based on the abnormal state of the thread pool also includes: Update the configuration items of the configuration center according to the thread pool configuration information input through the client interface, and push the configuration update information through the configuration center; The configuration change information is received, and the configuration of the thread pool is dynamically adjusted according to the configuration change information.
4. The thread pool configuration change method according to claim 3, characterized in that: The step of updating the configuration items of the configuration center according to the thread pool configuration information inputted from the client interface and pushing the configuration update information through the configuration center includes: Visualize thread pool configuration information and operating indicators so that users can monitor real-time data and make configuration change decisions.
5. The thread pool configuration changing method according to claim 1, characterized in that: The step of comparing the load indicator data with the pre-acquired historical benchmark data to identify the abnormal state of the thread pool includes: If an abnormal state of the thread pool is detected, an alarm notification is issued through the communication application.
6. The thread pool configuration changing method according to claim 1, characterized in that: The step of collecting the load index data of the thread pool during operation includes: Submits tasks to a pre-initialized thread pool and executes the tasks through the thread pool.
7. The thread pool configuration changing method according to claim 6, characterized in that: The thread pool is an enhanced thread pool, and the step of submitting the task to a pre-initialized thread pool and executing the task through the thread pool includes: Submit the task to the enhanced thread pool, and pass context parameters to the child thread through the parent thread; When the task is rejected, the rejected task is queued for retry.
8. A thread pool configuration change device, characterized in that: The device comprises: The data collection module is used to collect the load index data of the thread pool during operation; An abnormality identification module, used to compare the load indicator data with pre-acquired historical benchmark data to identify abnormal states of the thread pool; The configuration change module is used to implement a configuration change operation based on the abnormal state of the thread pool.
9. A thread pool configuration change device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the thread pool configuration change method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the thread pool configuration change method according to any one of claims 1 to 7 are implemented.