Thread pool configuration method and device, equipment and storage medium
Patent Information
- Application Number
- CN202211048236.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-30
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2042-08-30
AI Technical Summary
[0003]本公开提供一种线程池配置方法、装置、设备及存储介质,用以解决现有技术中线程池运行参数配置困难的问题
[0014] The thread pool configuration method, apparatus, device, and storage medium disclosed herein determine the current configuration mode of the target thread pool, obtain the thread pool's running information and current configuration information under the current configuration mode, and then adjust the target thread pool's running parameters based on the running information and current configuration information. This process achieves automated configuration of the target thread pool through the thread pool's running information and current configuration information, eliminating reliance on the developer's personal experience and simplifying the configuration of the target thread pool's running parameters. Furthermore, since the configuration of the target thread pool is based on the thread pool's running information, the adjustment of running parameters is more adapted to the target thread pool's running state, making the configuration of the target thread pool's running parameters more reasonable and flexible. The setting of preset configuration modes further increases the flexibility of configuration.
Smart Images

Figure CN117667371B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a thread pool configuration method, apparatus, device, and storage medium. Background Technology
[0002] In existing application systems, thread pools are a common approach used by developers to quickly respond to user requests, rapidly process task requests in batches, and maximize the utilization of multi-core processor performance. However, the core challenge of using thread pools lies in configuring their parameters. Current technologies, due to the complexity of thread pool mechanisms, require developers to have extensive experience and knowledge to configure them effectively. Furthermore, the performance of thread pools is highly dependent on the task type; interface-intensive and processor-intensive tasks behave very differently, further increasing the configuration difficulty. Summary of the Invention
[0003] This disclosure provides a thread pool configuration method, apparatus, device, and storage medium to solve the problem of difficulty in configuring thread pool operating parameters in the prior art.
[0004] This disclosure provides a thread pool configuration method, comprising: determining the current configuration mode of a target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; obtaining thread pool running information of the target thread pool under the current configuration mode, and obtaining current configuration information of the target thread pool under the current mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; and adjusting the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0005] According to a thread pool configuration method provided in this disclosure, determining the current configuration mode of the target thread pool includes: determining the current configuration mode of the target thread pool as a first preset mode; obtaining the thread pool operation information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current mode, includes: in the first preset mode, obtaining the current service cycle of the target thread pool, wherein the current service cycle is determined according to the system load of the target thread pool; in the first preset mode, obtaining the current configuration information of the target thread pool corresponding to the current service cycle; adjusting the operation parameters of the target thread pool based on the thread pool operation information and the current configuration information includes: adjusting the operation parameters of the target thread pool in the current service cycle based on the current service cycle and the current configuration information.
[0006] According to a thread pool configuration method provided in this disclosure, determining the current configuration mode of the target thread pool includes: determining that the current configuration mode of the target thread pool is a second preset mode; obtaining the thread pool operation information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current mode, includes: obtaining the current active thread count of the target thread pool under the second preset mode; obtaining the maximum thread count currently configured in the target thread pool under the second preset mode; adjusting the operation parameters of the target thread pool based on the thread pool operation information and the current configuration information includes: calculating the ratio of the current active thread count to the maximum thread count; obtaining the deviation value between the ratio and a preset ratio threshold; and adjusting the operation parameters of the target thread pool after determining that the deviation value is greater than the preset deviation threshold.
[0007] According to a thread pool configuration method provided in this disclosure, after determining that the deviation value is greater than a preset deviation threshold, adjusting the operating parameters of the target thread pool includes: recalculating the maximum number of threads based on the ratio; and updating the currently configured maximum number of threads of the target thread pool based on the recalculated maximum number of threads.
[0008] According to a thread pool configuration method provided in this disclosure, before obtaining the current active thread count of the target thread pool in the second preset mode, the method further includes: obtaining a preset automatic adjustment duration; obtaining the current active thread count of the target thread pool in the second preset mode includes: obtaining the current active thread count of the target thread pool in the second preset mode with the automatic adjustment duration as the period.
[0009] According to a thread pool configuration method provided in this disclosure, the current service cycle is one of a high service cycle and a low service cycle; wherein, the system load corresponding to the high service cycle is greater than the load threshold, and the system load corresponding to the low service cycle is less than or equal to the load threshold.
[0010] According to a thread pool configuration method provided in this disclosure, before obtaining the current configuration information of the target thread pool in the current mode, the method further includes: receiving a configuration instruction for the target thread pool in the current mode; and adjusting the current configuration information of the target thread pool parameters in the current mode according to the configuration instruction.
[0011] This disclosure also provides a thread pool configuration device, comprising: a mode determination module, configured to determine the current configuration mode of a target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; an information acquisition module, configured to acquire thread pool operation information of the target thread pool under the current configuration mode, and acquire current configuration information of the target thread pool under the current mode, wherein the thread pool operation information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; and a parameter adjustment module, configured to adjust the operation parameters of the target thread pool based on the thread pool operation information and the current configuration information.
[0012] This disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the thread pool configuration method as described above.
[0013] This disclosure also provides a non-transitory computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the thread pool configuration method as described above.
[0014] The thread pool configuration method, apparatus, device, and storage medium disclosed herein determine the current configuration mode of the target thread pool, obtain the thread pool's running information and current configuration information under the current configuration mode, and then adjust the target thread pool's running parameters based on the running information and current configuration information. This process achieves automated configuration of the target thread pool through the thread pool's running information and current configuration information, eliminating reliance on the developer's personal experience and simplifying the configuration of the target thread pool's running parameters. Furthermore, since the configuration of the target thread pool is based on the thread pool's running information, the adjustment of running parameters is more adapted to the target thread pool's running state, making the configuration of the target thread pool's running parameters more reasonable and flexible. The setting of preset configuration modes further increases the flexibility of configuration. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart illustrating the thread pool configuration method provided in this publication;
[0017] Figure 2This is a schematic diagram illustrating the periodic change of system load over time provided in this disclosure;
[0018] Figure 3 This is a schematic diagram of the structure of the thread pool configuration system provided in this publication;
[0019] Figure 4 This is a schematic diagram illustrating the functionality of the configuration center module provided in this publication;
[0020] Figure 5 This is a schematic diagram illustrating the functional implementation of the monitoring center module provided in this public disclosure;
[0021] Figure 6 This is a schematic diagram illustrating the implementation of the automated periodic parameter tuning mode provided in this publication;
[0022] Figure 7 This is a schematic diagram of the stress adaptive mode implementation provided in this publication;
[0023] Figure 8 The figure shows a comparison of the thread pool parameter configurations between the old and new processes provided in this public document.
[0024] Figure 9 This is a schematic diagram of the thread pool configuration device structure provided in this publication;
[0025] Figure 10 This is a schematic diagram of the structure of the electronic device provided in this disclosure. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the embodiments of this disclosure.
[0027] The following is combined with Figures 1-9 This disclosure describes a thread pool configuration method according to an embodiment of the present disclosure.
[0028] In one embodiment, such as Figure 1 As shown, the process steps for implementing the thread pool configuration method are as follows:
[0029] Step 101: Determine the current configuration mode of the target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool.
[0030] In this embodiment, a thread pool is a form of multi-threaded processing. During processing, tasks are added to a queue, and then these tasks are automatically started after threads are created. All threads in the thread pool are background threads. The target thread pool refers to a thread pool that requires configuration.
[0031] In this embodiment, at least one configuration mode is pre-set for the target thread pool. Each preset configuration mode can configure at least one running parameter of the target thread pool, but the specific implementation of each preset configuration mode is different. Users can choose any preset configuration mode as the current configuration mode of the target thread pool according to actual conditions and needs. It should be noted that the names of each preset configuration mode can be set as needed, for example, first preset mode, second preset mode, etc. The protection scope of this application is not limited by the specific names of the preset configuration modes.
[0032] Step 102: Obtain the thread pool running information of the target thread pool under the current configuration model, and obtain the current configuration information of the target thread pool under the current mode. The thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters.
[0033] In this embodiment, during the operation of the target thread pool, thread pool operation information can be obtained through a preset method. For example, if a thread pool is used when developing a computer program using other development tools such as OpenJDK, then the thread pool operation information can be obtained in real time using the Execute method in the thread pool usage method provided by the JDK. The thread pool operation information is the parameter information of the target thread pool currently running. Specifically, the operation parameters of the target thread pool include thread name (threadPoolName), core thread count (corePoolSize), maximum thread count (maximumPoolSize), keepAliveSeconds, queue length (queueCapacity), rejection policy name (rejectPolicyName), queue type name (queueTypeName), current thread count (poolSize), active thread count (activeCount), current queued thread count (queueSize), queue remaining length (queueRemainingCapacity), completed task count (completedTaskCount), historical maximum thread count (largestPoolSize), and other parameters related to the target thread pool.
[0034] In this embodiment, the current configuration information refers to the configuration information of the target thread pool's running parameters, and this configuration information is only the latest configuration. It is used to update the configuration information according to actual conditions and needs. The current configuration information mainly consists of specific settings for running parameters, such as the specific configured number of maximum threads.
[0035] In this embodiment, after determining the current configuration mode of the target thread pool, the thread pool running information and current configuration information required to implement parameter configuration under the current configuration mode are obtained to complete the configuration of the target thread pool running parameters.
[0036] In one embodiment, before obtaining the current configuration information of the target thread pool in the current mode, a configuration instruction for the target thread pool in the current mode is received; and the current configuration information of the target thread pool parameters in the current mode is adjusted according to the configuration instruction.
[0037] In this embodiment, through configuration instructions, users can adjust the current configuration information of the target thread pool under each preset configuration mode according to actual conditions and needs. Specifically, users can generate the required configuration instructions through clients on various devices such as smart mobile devices and computers to configure the running parameters of the target thread pool. The client can provide any of the following methods to generate configuration instructions: function buttons, text, graphics, code, etc. The scope of protection of this disclosure is not limited by the method of generating configuration instructions.
[0038] Step 103: Adjust the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0039] In this embodiment, after obtaining the thread pool running information and the current configuration information, the running parameters of the target thread pool are adjusted according to the specific running state of the target thread pool as represented by the thread pool running information and the current configuration information.
[0040] In one embodiment, the current configuration mode is a first preset mode, and more specifically, the first preset mode is an automated periodic parameter tuning mode based on the service cycle.
[0041] Specifically, the current configuration mode of the target thread pool is determined as follows: The current configuration mode of the target thread pool is determined to be the first preset mode. The thread pool operation information of the target thread pool under the current configuration mode, and the current configuration information of the target thread pool under the current mode, are obtained as follows: Under the first preset mode, the current service cycle of the target thread pool is obtained, where the current service cycle is determined based on the system load of the target thread pool; under the first preset mode, the current configuration information of the target thread pool corresponding to the current service cycle is obtained. Based on the thread pool operation information and the current configuration information, the operation parameters of the target thread pool are adjusted as follows: Based on the current service cycle and the current configuration information, the operation parameters of the target thread pool in the current service cycle are adjusted.
[0042] In this embodiment, when the target thread pool is implemented in a system such as Java, the operating state of the target thread pool remains the same regardless of the system load. The higher the system load, the greater the demand for the thread pool capacity. For systems with periodic characteristics, service cycles can be pre-set, and corresponding operating parameter values can be configured within different service cycles. In this case, the operating parameters that the target thread pool needs to adjust mainly refer to the thread pool capacity.
[0043] For example, a system's load may exhibit periodicity throughout the day. Between 9 AM and 9 PM, the system load is higher, requiring more thread pool capacity; between 9 PM and 9 AM the following day, the system load is lower, requiring less thread pool capacity. As another example, an e-commerce system may have two promotional periods within a year, during which the system load is higher, requiring even more thread pool capacity.
[0044] In one embodiment, the current service period is either a high service period or a low service period; wherein, the system load corresponding to the high service period is greater than the load threshold, and the system load corresponding to the low service period is less than or equal to the load threshold.
[0045] like Figure 2As shown, the system load corresponding to the target thread pool exhibits a periodic variation between high and low service periods. When configuring the target thread pool, corresponding configuration information is set for different service periods. Specifically, when the target thread pool is in a high service period, the system load increases, so the thread pool capacity configured in the configuration information is larger; when the target thread pool is in a low service period, the system load decreases, so the thread pool capacity configured in the configuration information is smaller. Specifically, the system time can be used to determine whether a high service period has begun. When the target thread pool enters a high service period, the configuration information corresponding to that high service period is automatically retrieved and used as the current configuration information to adjust the target thread pool's operating parameters; when the target thread pool enters a low service period, the configuration information corresponding to that low service period is automatically retrieved and used as the current configuration information to adjust the target thread pool's operating parameters.
[0046] In this embodiment, the load threshold is set based on empirical data and / or specific requirements, and the scope of protection of this disclosure is not limited to the specific value of the load threshold.
[0047] In the above embodiments, the current service period can also be divided in other forms according to actual conditions and needs. For example, the current service period can be any of the pre-set high service period, medium service period, and low service period. In summary, for a target thread pool where the system load changes periodically over time, as long as the configuration information corresponding to each stage within a period is set, a periodic thread pool automatic tuning strategy can be formed, avoiding the phenomenon of thread pool resource waste or resource shortage.
[0048] In one embodiment, the current configuration mode is a second preset mode, and more specifically, the second preset mode is a pressure adaptive mode implemented through a deviation correction strategy.
[0049] Specifically, the current configuration mode of the target thread pool is determined as follows: The current configuration mode of the target thread pool is determined to be the second preset mode. The thread pool operation information of the target thread pool under the current configuration mode, and the current configuration information of the target thread pool under the current mode, are obtained as follows: Under the second preset mode, the current active thread count of the target thread pool is obtained; under the second preset mode, the maximum number of threads currently configured in the target thread pool is obtained. Based on the thread pool operation information and the current configuration information, the operation parameters of the target thread pool are adjusted as follows: The ratio of the current active thread count to the maximum thread count is calculated; the deviation value between the ratio and the preset ratio threshold is obtained; after determining that the deviation value is greater than the preset deviation threshold, the operation parameters of the target thread pool are adjusted.
[0050] In this embodiment, if the target thread pool is operating under a system with high resource utilization requirements, more precise adaptive pressure adjustment is achieved by using the current active thread count and the maximum thread count. Specifically, based on empirical data, a system achieves its highest resource utilization when the ratio of the current active thread count to the configured maximum thread count is 80%. The current active thread count and the maximum thread count of the target thread pool are obtained, and the ratio of the current active thread count to the maximum thread count is calculated. If the deviation of this ratio from a preset ratio threshold (e.g., 80%) is too large, the operating parameters of the target thread pool need to be adjusted. For example, the allowable deviation of the preset ratio threshold is 5%, meaning the ratio of the current active thread count to the maximum thread count can fluctuate between 75% and 85%. When the ratio exceeds 5%, the operating parameters of the target thread pool are adjusted.
[0051] In one embodiment, after determining that the deviation value is greater than a preset deviation threshold, the running parameters of the target thread pool are adjusted. The specific implementation process is as follows: recalculate the maximum number of threads based on the ratio; update the current configured maximum number of threads of the target thread pool based on the recalculated maximum number of threads.
[0052] In this embodiment, if the ratio of the current active thread count to the maximum thread count exceeds a preset ratio threshold, there are two scenarios: one is that the configured maximum thread count is large, while the current active thread count is small, resulting in many idle threads and wasted resources. In this case, the maximum thread count can be recalculated based on the preset ratio threshold and the current active threshold, and then the configuration of the target thread pool can be updated. The other scenario is that the configured maximum thread count is small, while the current active thread count is large, resulting in insufficient thread reserves and resource scarcity. In this case, the maximum thread count can be recalculated based on the preset ratio threshold and the current active threshold, and then the configuration of the target thread pool can be updated.
[0053] In one embodiment, before obtaining the current active thread count of the target thread pool in the second preset mode, a preset automatic adjustment duration is obtained. The specific implementation process for obtaining the current active thread count of the target thread pool in the second preset mode is as follows: In the second preset mode, the current active thread count of the target thread pool is obtained periodically with the automatic adjustment duration as the period.
[0054] In this embodiment, the current number of active threads in the target thread pool is periodically acquired by setting a preset automatic adjustment period. Then, the ratio of the current number of active threads to the maximum number of threads is periodically calculated and compared with a preset ratio threshold. In other words, the target thread pool is periodically monitored to better adjust the maximum number of threads in the target thread pool.
[0055] In this embodiment, the automatic adjustment duration can be set according to actual conditions and needs. For example, the automatic adjustment duration can be any one of 1 minute, 5 minutes, 10 minutes, 30 minutes, 2 hours, 6 hours, or 24 hours. The scope of protection of this disclosure is not limited by the specific value of the automatic adjustment duration.
[0056] In this embodiment, a pressure adaptive mode is enabled. Based on the automatic adjustment duration, the system periodically reads thread pool monitoring information from the monitoring center and dynamically adjusts the thread pool configuration using a deviation correction strategy based on thread pool usage and capacity. This helps to automatically adjust thread pool resource usage and improve resource utilization when system resource utilization requirements are high or resources are insufficient.
[0057] In the above embodiments, the automated periodic parameter tuning mode modifies or updates the target thread pool's operating parameters less frequently, resulting in lower system resource consumption. In contrast, the pressure adaptive mode updates or modifies the target thread pool's operating parameters more closely to the real-time active thread count, placing higher demands on system resources but offering more precise parameter control. Users can choose either mode to configure the target thread pool according to their actual needs. Furthermore, more preset configuration modes can be configured for the target thread pool as needed.
[0058] In one embodiment, the thread pool configuration method described above is implemented based on a thread pool configuration system. This thread pool configuration system implements its various functions in a modular manner. For example... Figure 3 As shown, the thread pool configuration system includes: a configuration center module 301, a monitoring center module 302, a scheduled task module 303, a thread pool tool module 304, and an intelligent control module 305.
[0059] The client configures the corresponding configuration center service. When using it, it is not limited to its source configuration center service; it only needs to assemble configuration center module 301 to complete the configuration of the thread pool's operating parameters. The client is not limited to the source system monitoring center service; it only needs to assemble monitoring center module 302 to complete the required thread pool monitoring information. The scheduled task module 303 actively pulls the configurations from configuration center module 301 and monitoring center module 302 according to the scheduled time configuration, periodically updates the corresponding thread pool in thread pool tool module 304, periodically collects thread pool operating information, and reports custom monitoring data (such as the current number of active threads) to monitoring center module 302. The intelligent control module 305 empowers the scheduled task module 303 with an automated periodic parameter tuning mode or a pressure adaptive mode, intelligently optimizing the configuration and automatically adjusting the thread pool.
[0060] In this embodiment, the configuration center module 301 provides external configuration, supporting dynamic configuration of target thread pool runtime parameters such as threadPoolName, corePoolSize, maximumPoolSize, keepAliveSeconds, queueCapacity, rejectPolicyName, and queueTypeName. It supports isolating and creating multiple thread pools by thread pool name, with each thread pool being processed independently as a target thread pool. Simultaneously, the configuration center module 301 supports configuring startup parameters for the scheduled task module 303, such as initialization startup delay time and minimum interval between executions.
[0061] In this embodiment, as Figure 4 As shown, the configuration center module 301 supports multiple configuration centers. Clients can use their own configuration center service, client A can use its own distributed configuration center service A, and client B can use its own distributed configuration center service B. Thread pool configuration parameters are registered in the configuration center module 301, and the scheduled task module 303 reads the configuration information from this module. This supports any configuration center service for the client, such as Apollo and DUCC. Apollo refers to an open-source distributed configuration center, and DUCC refers to another distributed configuration center. In other words, different clients (A, B, etc.) can configure the same target thread pool, achieving configuration diversification and improving configuration convenience.
[0062] In this embodiment, the monitoring center module 302 provides external configuration, supporting the configuration of thread pool operation information to be monitored and reported, such as corePoolSize, maximumPoolSize, poolSize, activeCount, queueCapacity, queueSize, queueRemainingCapacity, completedTaskCount, and largestPoolSize. It also supports configuring custom information reporting and alarm rules. Figure 5As shown, the monitoring center module 302 supports multiple monitoring centers. Clients use their own monitoring center service; client A uses its own monitoring service A, and client B uses its own monitoring service B. The monitoring center module 302 registers the thread pool runtime information to be monitored and reported. The scheduled task module 303 reads the monitoring center configuration and reports the monitoring data. This supports monitoring center services from any application performance management (APM) tool on the client, such as Spring Boot Actuator, Zabbix, Zipkin, CAT, and UMP. Spring Boot Actuator is an open-source monitoring service, Zabbix is an enterprise-level open-source monitoring service, Zipkin is an open-source distributed cascading call monitoring system, CAT is an open-source application real-time monitoring platform, and UMP is an intelligent monitoring platform. In other words, the target thread pool is configured based on the monitoring data (i.e., thread pool runtime information) obtained through different services.
[0063] The scheduled task module 303 is the main scheduling module. It is mainly responsible for receiving the thread pool parameter configuration and scheduled task parameter configuration from the configuration center, updating the corresponding thread pool on a regular basis, and collecting thread pool running information and reporting monitoring data according to the monitoring parameters configured by the monitoring center.
[0064] The thread pool utility module 304 integrates the basic configuration of the thread module, including the thread pool configuration parameter model, configuration parameter constants, and rewritten variable-length blocking queues.
[0065] The intelligent control module 305 empowers the timed task module 303. This module supports automated periodic parameter adjustment mode and pressure adaptive mode, intelligent configuration optimization, and automated adjustment of the thread pool, which helps to reduce the system resources occupied by the thread pool and improve resource utilization.
[0066] In one embodiment, based on the thread pool configuration system, the intelligent control module 305 implements an automated periodic parameter tuning mode.
[0067] like Figure 6As shown, an automated periodic parameter tuning mode is enabled, allowing for custom configuration of the periodic timeframe and thread pool parameters for different periods. Specifically, the current service period can be any one of service period A, service period B, and service period C. Service period A corresponds to a pre-set thread pool configuration A, service period B corresponds to a pre-set thread pool configuration B, and service period C corresponds to a pre-set thread pool configuration C. The intelligent control module 305 analyzes and selects the thread pool configuration for the current time period, overriding the configuration of the current configuration center module 301, forming a periodic automatic thread pool tuning strategy. This mode increases the thread pool capacity during high service periods and decreases the thread pool capacity during low service periods, significantly optimizing system services with periodic characteristics.
[0068] In one embodiment, the pressure adaptive mode is implemented by the intelligent control module 305 based on the thread pool configuration system.
[0069] like Figure 7 As shown, when the pressure adaptive mode is enabled, the intelligent control module 305 periodically reads the thread pool operation information from the monitoring center module 302 based on the automatic adjustment duration. According to the thread pool usage and capacity, it dynamically adjusts the current configuration information using a deviation correction strategy. The automatic adjustment duration can be any one of 1 minute, 5 minutes, 10 minutes, 30 minutes, 2 hours, 6 hours, or 24 hours, and the thread pool configuration is automatically adjusted at intervals equal to this duration. The deviation correction strategy (based on the 80% theory derived from empirical data) maintains the ratio of the current active thread count to the configured maximum thread count at 80%. If the deviation exceeds 5% (75%–85%), the maximum thread count is recalculated. Specifically, with the automatic adjustment period as the cycle, the current number of active threads is read through the monitoring center module 302, and the maximum number of threads is read through the configuration center module 301. By comparing the number of active threads and the maximum number of threads, it is determined whether the ratio of the current number of active threads to the configured maximum number of threads exceeds the deviation range. If so, the maximum number of threads is re-estimated and the thread pool configuration is modified; otherwise, the thread pool configuration does not need to be modified and the process ends directly.
[0070] This mode is suitable for systems with high resource utilization requirements or when resources are insufficient. It helps to automatically adjust the resource usage of the thread pool and improve resource utilization.
[0071] Based on the thread pool configuration methods provided in the above embodiments, such as Figure 8As shown in the figure, the comparison of thread pool parameter configuration changes between the old and new processes is illustrated. The old process in the existing technology uses hard-coding, requiring parameter adjustments, code submission, and then recompilation, deployment, and verification, which is time-consuming. The new process provided in this disclosure has the ability to dynamically configure parameters, allowing for immediate modification and effectiveness. This simplifies the deployment process, significantly reduces the time spent by R&D teams optimizing thread pool parameters, lowers development costs, improves development efficiency, and enhances the system's ability to adapt to complex scenarios.
[0072] The thread pool configuration method disclosed herein obtains the thread pool runtime information and the current configuration information of the target thread pool, and then adjusts the runtime parameters of the target thread pool based on the runtime information and the current configuration information. This process achieves automated configuration of the target thread pool by using the thread pool runtime information and the current configuration information, eliminating reliance on the developer's personal experience and making the configuration of the target thread pool runtime parameters simpler; furthermore, the configuration of the target thread pool is based on the thread pool runtime information, making the adjustment of runtime parameters more adaptable to the runtime state of the target thread pool, and making the configuration of the target thread pool runtime parameters more reasonable and flexible.
[0073] Furthermore, the automated periodic parameter tuning mode and stress adaptive mode provided by this method allow for simpler, more reasonable, and dynamic configuration of thread pool parameters, easier integration with diverse configuration centers, and more flexible adaptation to diverse monitoring centers. It has low integration difficulty, is easy to learn, and has minimal invasiveness to the original system. It supports thread pool isolation to distinguish between different task types.
[0074] The thread pool configuration apparatus provided in the embodiments of this disclosure is described below. The thread pool configuration apparatus described below can be referred to in correspondence with the thread pool configuration method described above. Figure 9 As shown, the thread pool configuration device includes:
[0075] The mode determination module 901 is used to determine the current configuration mode of the target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool;
[0076] The information acquisition module 902 is used to acquire the thread pool running information of the target thread pool under the current configuration model, and to acquire the current configuration information of the target thread pool under the current mode. The thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters.
[0077] The parameter adjustment module 903 is used to adjust the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0078] Figure 10 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 10As shown, the electronic device may include: a processor 1001, a communication interface 1002, a memory 1003, and a communication bus 1004, wherein the processor 1001, the communication interface 1002, and the memory 1003 communicate with each other through the communication bus 1004. The processor 1001 can call logical instructions in the memory 1003 to execute a thread pool configuration method, which includes: determining the current configuration mode of the target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; obtaining the thread pool running information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; and adjusting the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0079] Furthermore, the logical instructions in the aforementioned memory 1003 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this disclosure, essentially, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0080] On the other hand, this disclosure also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the thread pool configuration method provided by the above methods. The method includes: determining the current configuration mode of a target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; obtaining thread pool running information of the target thread pool under the current configuration mode, and obtaining current configuration information of the target thread pool under the current mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; and adjusting the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0081] In another aspect, this disclosure also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform the thread pool configuration methods provided above. The method includes: determining the current configuration mode of a target thread pool, wherein the current configuration mode is one of the target thread pool's preset configuration modes; obtaining thread pool running information of the target thread pool under the current configuration mode, and obtaining current configuration information of the target thread pool under the current mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information on the current configuration of the target thread pool parameters; and adjusting the running parameters of the target thread pool based on the thread pool running information and the current configuration information.
[0082] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0083] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0084] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure.
Claims
1. A thread pool configuration method, characterized by, include: Determine the current configuration mode of the target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; Obtain the thread pool running information of the target thread pool under the current configuration mode, and obtain the current configuration information of the target thread pool under the current configuration mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; Based on the thread pool's running information and the current configuration information, adjust the running parameters of the target thread pool; Determining the current configuration mode of the target thread pool includes: The current configuration mode of the target thread pool is determined to be the first preset mode; The step of obtaining the thread pool running information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current configuration mode, includes: In the first preset mode, the current service cycle of the target thread pool is obtained, wherein the current service cycle is determined according to the system load of the target thread pool; In the first preset mode, the current configuration information of the target thread pool corresponding to the current service cycle is obtained; The step of adjusting the operating parameters of the target thread pool based on the thread pool operating information and the current configuration information includes: Based on the current service cycle and the current configuration information, adjust the running parameters of the target thread pool in the current service cycle; Determine the current configuration mode of the target thread pool, including: The current configuration mode of the target thread pool is determined to be the second preset mode; The step of obtaining the thread pool running information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current configuration mode, includes: In the second preset mode, obtain the current number of active threads in the target thread pool; In the second preset mode, obtain the maximum number of threads currently configured in the target thread pool; The step of adjusting the operating parameters of the target thread pool based on the thread pool operating information and the current configuration information includes: Calculate the ratio of the current number of active threads to the maximum number of threads; Obtain the deviation value between the ratio and the preset ratio threshold; Once the deviation value is determined to be greater than a preset deviation threshold, the operating parameters of the target thread pool are adjusted.
2. The thread pool configuration method of claim 1, wherein, After determining that the deviation value is greater than a preset deviation threshold, adjusting the operating parameters of the target thread pool includes: Based on the ratio, the maximum number of threads is recalculated; Based on the recalculated maximum number of threads, update the currently configured maximum number of threads for the target thread pool.
3. The thread pool configuration method of claim 1, wherein, Before obtaining the current active thread count of the target thread pool in the second preset mode, the method further includes: Get the preset automatic adjustment duration; In the second preset mode, obtaining the current active thread count of the target thread pool includes: In the second preset mode, the number of currently active threads in the target thread pool is obtained with the automatic adjustment duration as the period.
4. The thread pool configuration method according to claim 1, characterized in that, The current service cycle is either a high service cycle or a low service cycle; Wherein, the system load corresponding to the high service cycle is greater than the load threshold, and the system load corresponding to the low service cycle is less than or equal to the load threshold.
5. The thread pool configuration method according to claim 1, characterized in that, Before obtaining the current configuration information of the target thread pool under the current configuration mode, the method further includes: Receive configuration instructions for the target thread pool under the current configuration mode; According to the configuration instructions, adjust the current configuration information of the target thread pool parameters in the current configuration mode.
6. A thread pool configuration device, characterized in that, include: The mode determination module is used to determine the current configuration mode of the target thread pool, wherein the current configuration mode is one of the preset configuration modes of the target thread pool; The information acquisition module is used to acquire the thread pool running information of the target thread pool under the current configuration mode, and to acquire the current configuration information of the target thread pool under the current configuration mode, wherein the thread pool running information is the parameter information of the target thread pool currently running, and the current configuration information is the information of the current configuration of the target thread pool parameters; The parameter adjustment module is used to adjust the running parameters of the target thread pool based on the thread pool running information and the current configuration information. Determining the current configuration mode of the target thread pool includes: The current configuration mode of the target thread pool is determined to be the first preset mode; The step of obtaining the thread pool running information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current configuration mode, includes: In the first preset mode, the current service cycle of the target thread pool is obtained, wherein the current service cycle is determined according to the system load of the target thread pool; In the first preset mode, the current configuration information of the target thread pool corresponding to the current service cycle is obtained; The step of adjusting the operating parameters of the target thread pool based on the thread pool operating information and the current configuration information includes: Based on the current service cycle and the current configuration information, adjust the running parameters of the target thread pool in the current service cycle; Determine the current configuration mode of the target thread pool, including: The current configuration mode of the target thread pool is determined to be the second preset mode; The step of obtaining the thread pool running information of the target thread pool under the current configuration mode, and obtaining the current configuration information of the target thread pool under the current configuration mode, includes: In the second preset mode, obtain the current number of active threads in the target thread pool; In the second preset mode, obtain the maximum number of threads currently configured in the target thread pool; The step of adjusting the operating parameters of the target thread pool based on the thread pool operating information and the current configuration information includes: Calculate the ratio of the current number of active threads to the maximum number of threads; Obtain the deviation value between the ratio and the preset ratio threshold; Once the deviation value is determined to be greater than a preset deviation threshold, the operating parameters of the target thread pool are adjusted.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the thread pool configuration method as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the thread pool configuration method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Thread pool management method and system
CN101599027A
Thread pool adjustment method and device thereof, storage medium and electronic equipment
CN113157410A