Thread control method and device, electronic equipment and storage medium
By controlling thread sleep in the storage system based on load status and event processing volume, the problem of Reactor thread resource waste is solved, and resource utilization is improved and performance stability is achieved.
Patent Information
- Application Number
- CN202510645706.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-08-19
AI Technical Summary
In related technologies, Reactor threads operate in infinite loops, causing the CPU core to run at full load, the resource utilization rate is low, and there is a problem of resource waste.
By obtaining the storage index data in the previous statistical cycle, determining the load status of the current storage system, and controlling the thread to be sleeping for a specified duration after processing the event after the event is processed, balancing the load and thread resource utilization efficiency of the storage system.
It effectively reduces CPU usage, improves resource utilization, ensures that threads can respond to bursts of high load situations in a timely manner, and avoids performance degradation caused by excessive sleep.
Smart Images

Figure CN120508370A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a thread control method, device, electronic device, and storage medium. Background Art
[0002] SPDK (Storage Performance Development Kit) is a high-performance storage software development kit that improves the performance of storage devices by optimizing the software layer of the storage system. Figure 1 As shown in the related art, in SPDK, there is a core scheduling unit, namely the Reactor thread, which is responsible for the event loop and I / O processing. At startup, the Reactor thread runs in a "while 1" loop, which is equivalent to an infinite loop. Therefore, the CPU (Central Processing Unit) core corresponding to the thread runs at nearly 100% load, that is, it enters a fully loaded state, and continuously loops to check and process received events. However, this processing method wastes resources.
[0003] Therefore, the related art has the problem of low resource utilization due to resource waste. Summary of the Invention
[0004] The present application provides a thread control method, device, electronic device, and storage medium to at least solve the problem of low resource utilization caused by resource waste in related technologies.
[0005] The present application provides a thread control method, which is applied to a storage system including a group of block devices and a group of threads, wherein a thread in the group of threads is used to process an event sent by a received block device; the method comprises:
[0006] Obtain storage indicator data in a previous statistical period, wherein the storage indicator data is used to describe performance indicators of the group of block devices; determine the load status of the storage system in a current statistical period based on the storage indicator data in the previous statistical period; determine a thread to be dormant in the group of threads based on the event processing volume of one thread in the group of threads and the load status of the storage system, and control the thread to be dormant to sleep for a specified length of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified length of time is negatively correlated with the event processing volume of the thread to be dormant.
[0007] The present application also provides a thread control device, which is applied to a storage system including a group of block devices and a group of threads, wherein a thread in the group of threads is used to process an event sent by a received block device; the device includes:
[0008] An acquisition module is used to obtain storage indicator data in a previous statistical period, wherein the storage indicator data is used to describe the performance indicators of the group of block devices; a determination module is used to determine the load status of the storage system in a current statistical period based on the storage indicator data in the previous statistical period; a sleep module is used to determine the thread to be dormant in the group of threads based on the event processing volume of one thread in the group of threads and the load status of the storage system, and control the thread to be dormant to sleep for a specified length of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified length of time is negatively correlated with the event processing volume of the thread to be dormant.
[0009] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned thread control methods when executing the computer program.
[0010] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned thread control methods are implemented.
[0011] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned thread control methods when executed by a processor.
[0012] Through this application, based on the storage indicator data in the previous statistical period, the load status of the storage system in the current statistical period is determined, and the event processing volume of one thread in a group of threads and the load status of the storage system are used to determine the dormant thread in a group of threads, so as to control the dormant thread to sleep for a specified period of time after processing the received events, effectively balancing the load of the storage system and the utilization efficiency of thread resources, and realizing the effective reduction of CPU usage and improvement of resource utilization by controlling some threads to sleep, thus solving the problem of low resource utilization caused by resource waste in related technologies. The specified duration is negatively correlated with the event processing volume of the dormant thread, which can ensure to a certain extent that the thread can respond to sudden high-load situations in a timely manner and avoid performance degradation due to excessive sleep. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0014] Figure 1 A schematic diagram of a thread control method in related art;
[0015] Figure 2 A schematic diagram of an application scenario of a thread control method provided in an embodiment of the present application;
[0016] Figure 3 This is a flow chart of an optional thread control method according to an embodiment of the present application;
[0017] Figure 4 A schematic diagram of an optional thread control method according to an embodiment of the present application;
[0018] Figure 5 A flowchart of another optional thread control method according to an embodiment of the present application;
[0019] Figure 6 This is a structural block diagram of an optional thread control device in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0021] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0022] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0023] In the related art, SPDK has a core scheduling unit, the Reactor thread, which is responsible for the event loop and I / O (Input / Output) processing. At startup, the Reactor thread runs in a "while1" loop. The while 1 mode is equivalent to an infinite loop. Therefore, the CPU core corresponding to the thread runs at nearly 100% load, that is, it enters a fully loaded state, continuously checking and processing received events. However, this processing method wastes resources. Therefore, the related art suffers from low resource utilization.
[0024] To solve the above problems, an embodiment of the present application provides a thread control method, which determines the load status of the storage system in the current statistical period based on the storage index data in the previous statistical period, and determines the dormant thread in a group of threads through the event processing volume of one thread in a group of threads and the load status of the storage system, so as to control the dormant thread to sleep for a specified period of time after processing the received events, effectively balancing the load of the storage system and the utilization efficiency of thread resources, and realizing the control of some threads to sleep, effectively reducing CPU usage, improving resource utilization, and solving the problem of low resource utilization caused by resource waste in related technologies. The specified time is negatively correlated with the event processing volume of the dormant thread, which can ensure to a certain extent that the thread can respond to sudden high-load situations in a timely manner and avoid performance degradation due to excessive sleep.
[0025] According to one aspect of the embodiment of the present application, a thread control method is provided. Optionally, in this embodiment, the thread control method can be applied to, but is not limited to, Figure 2 The hardware environment shown includes a terminal device 202 and a server 204. The server 204 can be connected to the terminal device 202 via a network and can be used to provide services (e.g., application services, etc.) for the terminal device 202 or a client installed on the terminal device 202. A database can be set on the server 204 or independently of the server 204 to provide data storage services for the server 204.
[0026] The aforementioned network may include, but is not limited to, at least one of the following: a wired network and a wireless network. The aforementioned wired network may include, but is not limited to, at least one of the following: a wide area network, a metropolitan area network, or a local area network. The aforementioned wireless network may include, but is not limited to, at least one of the following: Wi-Fi (Wireless Fidelity) and Bluetooth. Terminal device 202 may include, but is not limited to, a PC (Personal Computer), a mobile phone, a tablet computer, etc. Server 204 may include, but is not limited to, a cloud server, a server cluster, or other server types.
[0027] The thread control method of the embodiment of the present application can be executed by the server 204, or by the terminal device 202, or by both the server 204 and the terminal device 202. The thread control method of the embodiment of the present application can also be executed by the client installed on the terminal device 202.
[0028] Taking the thread control method of this embodiment executed by terminal device 202 as an example, the thread control method can be applied to a storage system, which includes a group of block devices and a group of threads. A thread in the group of threads is used to process events sent by a received block device. Figure 3 FIG. 1 is a flow chart of an optional thread control method according to an embodiment of the present application, as shown in FIG. Figure 3 As shown, the process of the method may include the following steps:
[0029] Step S302: Acquire storage index data in a previous statistical period, wherein the storage index data is used to describe performance indicators of a group of block devices.
[0030] It should be noted that the storage system can run on various types of devices, including but not limited to servers, mobile devices, and network storage devices. The storage system can include a set of block devices and a set of threads. Block devices are used to store and retrieve data in the storage system and are the key components responsible for persistent storage. Block devices can be BDEVs (Block Devices). Threads can be Reactor threads, which are responsible for event loops and I / O processing. Each Reactor can be bound to a CPU core to ensure rapid event response and processing.
[0031] In a storage system, a thread in a group of threads processes events received from block devices. Optionally, it monitors the block device's event queue in real time. When an event occurs, such as an I / O request (such as a read or write operation), a network connection establishment or disconnection, or an error report, the thread immediately responds and handles it. Based on the type and priority of the event, the thread schedules system resources (such as CPU time, memory, and network bandwidth) to complete the corresponding task. In a multithreaded environment, threads must coordinate resource allocation to avoid resource conflicts and waste, thereby improving the system's overall processing power and efficiency.
[0032] In practice, in a multi-threaded storage system, each Reactor thread is bound to a specific set of block devices. When a block device receives an I / O request or other event, it pushes the event information to the event queue of the associated Reactor thread. In SPDK, each Reactor has its own independent event queue, ensuring rapid event distribution and processing. Reactor threads poll the event queue and process the events in the queue.
[0033] It's important to note that storage metric data can be used to describe the performance of a storage system. It's obtained by regularly collecting and aggregating performance metrics recorded by a set of block devices. Specifically, storage metric data describes the performance of block devices in a storage system. Specifically, storage metric data includes, but is not limited to, IOPS (Input / Output Operations Per Second), throughput, and latency.
[0034] A statistical cycle can be a time period used to collect and process indicator data. The previous statistical cycle is the time period immediately preceding the current statistical cycle. In the previous statistical cycle, indicator data collection and processing were completed. Optionally, the storage indicator data from the previous statistical cycle is used for historical trend analysis to help predict future status or adjust current policies. For example, the statistical cycle is set to 10 milliseconds. This means that the system samples and processes performance indicators every 10 milliseconds. During the "current statistical cycle," the storage indicator data from the previous statistical cycle is used to evaluate the load status of the storage system in the current statistical cycle.
[0035] Step S304: Determine the load status of the storage system in the current statistical period based on the storage indicator data in the previous statistical period.
[0036] It should be noted that the collection and processing of indicator data has been completed in the previous statistical cycle. Optionally, the storage indicator data of the previous statistical cycle is used for historical trend analysis to help predict future status or adjust current policies. For example, the statistical cycle is set to 10 milliseconds. This means that the system samples and processes performance indicators every 10 milliseconds. During the "current statistical cycle", the storage indicator data of the previous statistical cycle is used to evaluate the load status of the storage system in the current statistical cycle. The load status can generally be divided into low load state, medium load state, or high load state.
[0037] Step S306, based on the event processing volume of a thread in a group of threads and the load status of the storage system, determine the thread to be dormant in the group of threads, and control the thread to be dormant to sleep for a specified period of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified period is negatively correlated with the event processing volume of the thread to be dormant.
[0038] It should be noted that the event processing volume can refer to the total number of events processed by a thread in a preset period, such as the number of NVMe (Non-Volatile Memory Express, non-volatile memory host controller interface specification) command completions, the number of TCP (Transmission Control Protocol) connection establishments, etc.
[0039] The duration corresponding to a statistical cycle is greater than the duration corresponding to a preset cycle. Optionally, the time period corresponding to a statistical cycle may include time periods corresponding to multiple preset cycles. The duration corresponding to a statistical cycle may be N times the duration corresponding to the preset cycle. Optionally, the lengths of the statistical cycle and the preset cycle may be determined based on empirical values.
[0040] The specified duration can be dynamically calculated based on the thread's event processing volume and the system load. Generally, the lower the event processing volume, the longer the specified sleep duration, and vice versa. In other words, the specified duration is inversely correlated with the event processing volume of the thread to be dormant. In other words, a decrease in event processing volume will result in an increase in the sleep duration.
[0041] Optionally, an event processing quantity statistics module can be set in the Reactor thread of SPDK to count the number of events received and processed by the Reactor in the past period of time (for example, 1ms, 10ms), that is, in a statistical cycle. Optionally, an event processing counter can be used to count and record the event processing volume of the thread during each preset cycle, and reset the count at the beginning of the next preset cycle. Optionally, the busyness of the thread in the current preset cycle can be determined based on the number of events processed by the thread in the previous preset cycle.
[0042] Optionally, the busyness of the current thread can be analyzed through an event processing number counter. Optionally, whether the thread is busy or idle can be determined by setting a threshold. Specifically, the busyness of the Reactor is judged based on the statistical value of the number of events processed by the Reactor. When the number of events processed is lower than the first event threshold, the Reactor is determined to be in an idle state; when the number of events processed is higher than or equal to the second event threshold, the Reactor is determined to be in a busy state. The second event threshold can be greater than or equal to the first event threshold. Optionally, when the Reactor is determined to be in an idle state, it means that the Reactor can enter the sleep control process. Of course, whether to control the Reactor to perform the sleep control process must also consider the load status of the entire system.
[0043] Optionally, when it is determined that the storage system is under high load, even if one thread is in an idle state, sleep control may not be performed, that is, the global load adjustment policy takes precedence over the sleep control policy of each thread.
[0044] Optionally, the thread to be put into sleep is determined based on the event processing volume of a thread in a group of threads and the load status of the storage system, wherein the number of threads to be put into sleep can be one or more. When the thread to be put into sleep is determined, the thread to be put into sleep can be controlled to sleep according to a preset sleep strategy. Specifically, in each loop, the thread to be put into sleep can process all the events currently received in the event queue, call the sleep method to perform sleep for a specified period of time, and then enter the next loop to continue checking events, thereby effectively reducing the CPU usage while ensuring the response speed of the Reactor to a certain extent. The length of the specified time can be determined based on the event processing volume of the thread to be put into sleep.
[0045] Through the embodiments of the present application, the load status of the storage system in the current statistical period is determined based on the storage indicator data in the previous statistical period, and the dormant thread in a group of threads is determined based on the event processing volume of one thread in a group of threads and the load status of the storage system, so as to control the dormant thread to sleep for a specified period of time after processing the received events, effectively balancing the load of the storage system and the utilization efficiency of thread resources, and realizing the effective reduction of CPU usage and improvement of resource utilization by controlling some threads to sleep, thus solving the problem of low resource utilization caused by resource waste in related technologies. The specified duration is negatively correlated with the event processing volume of the dormant thread, which can ensure to a certain extent that the thread can respond to sudden high-load situations in a timely manner and avoid performance degradation due to excessive sleep.
[0046] In an exemplary embodiment, step S302 includes: traversing a group of block devices to obtain device status statistical information of the block devices in the group of block devices in the previous statistical period, wherein the device status statistical information is used to describe the operating performance of the block devices in the previous statistical period; and calculating storage indicator data in the previous statistical period based on the device status statistical information of the block devices in the group of block devices in the previous statistical period.
[0047] In order to more accurately evaluate the load status of the storage system and provide reliable data support for subsequent thread control strategies, in this embodiment, the operating status of all block devices can be fully understood through traversal processing, thereby calculating the performance indicators of the entire storage system.
[0048] Alternatively, a traversal process refers to the process of accessing and processing a group of block devices one by one to collect state information of a group of block devices within a specific event window. In SPDK, a traversal can involve traversing all physical or virtual storage devices managed by SPDK.
[0049] The previous statistical period refers to the last time window during which performance data was collected. For example, if the statistical period is set to 10ms, the previous statistical period is the last 10ms period. The same applies to the preset period.
[0050] Device status statistics describe the operational performance of block devices. Specifically, they capture the operational performance data for each block device during the previous statistical period, including but not limited to metrics such as read and write times, data transfer volume, IOPS, and average latency. This performance information reflects the activity and performance of a block device.
[0051] Storage metrics are derived by aggregating device status statistics for a group of block devices. The storage metrics from the previous statistical period can be used to describe the performance of the storage system during that period. For example, the system's total IOPS, throughput, latency, and average block device performance can be used.
[0052] Optionally, in SPDK, when each block device performs an IO operation, the iostat information corresponding to the block device will be updated, including the number of read and write operations, the amount of data, etc.
[0053] Optionally, an IO statistics module may be provided to periodically traverse the iostat information of all BDEV devices and calculate the total IO volume or specific indicators (such as IOPS) of all BDEV devices in the entire node.
[0054] Optionally, you can call the corresponding status statistics function for each block device, such as bdev_get_iostat(), to obtain its device status statistics. This records the events processed by each block device in the previous statistical period, as well as the average latency and data transfer volume of each block device when processing events. Based on the device status statistics of all block devices, you can calculate the storage metrics of the entire system in the previous statistical period, such as total IOPS of 300 times / second, total data transfer volume of 100MB, and average latency of 1ms.
[0055] Optionally, by extending the bdev_get_iostat interface, global statistics fields are added to support I / O indicators including but not limited to iops, io bandwidth, latency, etc., so that global load statistics can be achieved.
[0056] Through this embodiment, a group of block devices is traversed and device status statistical information is summarized to determine storage index data in the previous statistical period, thereby achieving a more accurate assessment of the load status of the storage system.
[0057] In an exemplary embodiment, the storage indicator data includes indicator values corresponding to multiple indicator data, and the load state of the storage system is one of a first load state, a second load state, and a third load state, wherein the loads corresponding to the first load state, the second load state, and the third load state decrease in sequence; step S304 includes: when there is at least one indicator data in the multiple indicator data whose corresponding indicator value is greater than a first preset threshold, determining that the storage system is in the first load state in the current statistical period; when there is no at least one indicator data in the multiple indicator data whose corresponding indicator value is greater than the first preset threshold, and there is at least one indicator data whose corresponding indicator value is greater than the second preset threshold, determining that the storage system is in the second load state in the current statistical period, wherein the first preset threshold corresponding to one indicator data in the multiple indicator data is greater than the second preset threshold; when there is no indicator data whose corresponding indicator value is greater than the second preset threshold, determining that the storage system is in the third load state in the current statistical period.
[0058] It should be noted that storage metric data can include values corresponding to multiple types of metric data. Specifically, storage metric data can include a set of quantitative indicators that describe the performance of the storage system during the previous statistical period. These indicators include, but are not limited to, IOPS (input / output operations per second), throughput (data transfer rate), and read / write latency (the time required to complete a read / write operation). They comprehensively reflect the storage system's ability and efficiency in processing data requests.
[0059] Optionally, the first preset threshold and the second preset threshold may be two limit values set for a type of indicator data. For each indicator data of the plurality of indicator data, the corresponding first preset threshold and the second preset threshold are different, and for the same indicator data, the corresponding first preset threshold is greater than the second preset threshold.
[0060] The first preset threshold can be used to determine whether the storage system is in the first load state. For example, if IOPS is used as the basis, the first preset threshold may be 5000 times / second. The second preset threshold can be used to distinguish whether the storage system load state is the second load state or the third load state. The second preset threshold is another lower reference value set for the same or different indicator data, used to distinguish between medium and low load states. Compared to the first preset threshold, its value is lower, for example, for IOPS, it may be 2000 times / second.
[0061] Optionally, when the indicator value corresponding to any indicator data is greater than a first preset threshold, the storage system can be considered to be in a high-load state, i.e., a first load state, indicating that it faces higher performance requirements. When all indicator data do not exceed the first preset threshold, but the indicator value corresponding to at least one indicator data exceeds a second preset threshold, the storage system can be considered to be in a medium-load state, i.e., a second load state, indicating that the performance requirements are at a moderate level. When the values of all indicator data do not exceed the second preset threshold, the storage system is considered to be in a low-load state, with a low performance requirement.
[0062] Specifically, the sizes of the first preset threshold and the second preset threshold can be set based on actual conditions, and this application does not limit them here.
[0063] Optionally, the loads corresponding to the first load state, the second load state, and the third load state decrease in sequence, that is, the first load state may correspond to a high load state, the second load state may correspond to a medium load state, and the third load state may correspond to a low load state.
[0064] Through this embodiment, by setting different thresholds, the load status of the storage system can be divided more finely, thereby achieving more accurate thread control, avoiding excessive sleep or excessive wake-up of threads, and improving system stability and efficiency.
[0065] In an exemplary embodiment, step S306 includes: when the load state of the storage system is in the second load state, if there is a thread in a group of threads whose event processing volume is less than a first threshold, setting the thread whose event processing volume is less than the first threshold as a thread to be dormant.
[0066] It should be noted that the load state of the storage system can be divided into three types, namely, a first load state, a second load state, and a third load state. The loads corresponding to the first load state, the second load state, and the third load state decrease in sequence.
[0067] Optionally, when the storage system is under a first load state, a first preset number of threads in the storage system may be controlled not to enter a dormant state. Specifically, the first preset number may be a very large value. Of course, all threads may also be controlled not to enter a dormant state.
[0068] Optionally, when the storage system load state is in the second load state, some threads may be controlled to be sleep threads, so that the sleep threads are controlled to sleep for a specified period of time after processing received events. Specifically, a second preset number of threads may be selected as sleep threads, or the sleep threads to be put into sleep may be determined from a group of threads based directly on the amount of events processed by the threads in a previous preset period.
[0069] Optionally, when the storage system load is in a third load state, a third preset number of threads may be selected as threads to be dormant. The third preset number may be a large value, such as the number of all threads currently in the storage system. That is, when the storage system load is in the third load state, all threads in a group of threads may be directly controlled to dormant for a specified duration after processing received events.
[0070] Through the above embodiment, in the first load state (high load), all or nearly all threads (the first preset number) can be controlled to remain active, avoiding the impact of the sleep mechanism on the response speed of high I / O demands, and ensuring the efficient operation of the storage system under high load. In the second load state (medium load), only some threads (the second preset number) are controlled to enter sleep, allowing the remaining threads to continue processing events, thereby achieving reasonable allocation of CPU resources and reducing unnecessary energy consumption. In the third load state (low load), almost all (the third preset number, equivalent to the current total number of threads) Reactor threads can be controlled to enter sleep after processing existing events, significantly reducing CPU usage and achieving substantial energy savings.
[0071] Specifically, a preset threshold range can be set for the specified duration. Of course, the upper limit and lower limit of the preset range of the specified duration are generally set very small to meet the high response requirements of the thread.
[0072] In one example, if Figure 4As shown, all BDEV devices are traversed, specifically from BDEV 0 to BDEV 3, to collect device status statistics for each block device in the previous statistical cycle. Based on the device status statistics, the storage system load state (such as high load, medium load, or low load) can be determined. In the case of low load, all threads can be controlled to sleep; in the case of medium load, threads to be dormant can be selected to sleep, and in the case of high load, all threads can be controlled not to sleep. During this statistical cycle, the sleep duration of threads to be dormant in the current preset cycle is adjusted according to the event processing volume of the threads in the previous preset cycle. After the end of a statistical cycle, the next round of traversal and statistics can be carried out.
[0073] It should be noted that the size of the statistical cycle can be configured and adjusted to adapt to performance monitoring and resource requirements in different scenarios.
[0074] Through this embodiment, the thread whose event processing volume is less than the first threshold, that is, the utilization rate of the thread is relatively low, is treated as a dormant thread when the load state of the storage system is in the second load state. This can effectively reduce unnecessary resource consumption, improve resource utilization, and enhance the overall energy efficiency of the system.
[0075] In an exemplary embodiment, the above method also includes: when the number of threads whose event processing volume is less than a first threshold is less than a preset number, arranging the remaining threads in descending order according to the event processing volume, wherein the remaining threads are threads in a group of threads excluding those whose event processing volume is less than the first threshold; selecting the first specified number of threads from the sorted remaining threads as threads to be dormant, wherein the specified number is the difference between the preset number and the number of threads whose event processing volume is less than the first threshold.
[0076] It should be noted that the preset number can be a target value set when performing thread sleep control, indicating the number of threads that are expected to remain in a sleep state under the second load state. Optionally, the size of the preset number can be set according to the scale and performance requirements of the storage system, and this application does not limit this.
[0077] In the current system, the number of threads with event processing volume lower than the first threshold is small and insufficient to meet the requirements of the sleep strategy. Therefore, some threads with higher event processing volume can be further selected to sleep to achieve the purpose of resource optimization.
[0078] Optionally, threads are sorted from high to low based on the amount of events they process, to determine which threads have a relatively high load and which have a relatively low load. Sorting in descending order helps select threads that are more suitable for sleeping while maintaining a certain performance.
[0079] The remaining threads are threads in a group of threads, excluding those whose event processing volume is already less than the first threshold. Under medium load, the event processing volume of the remaining threads is usually higher than the first threshold, but some threads still need to be selected to sleep to optimize resources.
[0080] The specified number is the number of threads that need to be put to sleep, as calculated by the system. It is equal to the difference between the preset number and the number of threads whose event processing volume is less than the first threshold. For example, if the preset number is 10 and the number of threads whose event processing volume is less than the first threshold is 8, then two of the remaining threads need to be put to sleep.
[0081] Through this embodiment, when the number of threads whose event processing volume is less than the first threshold is less than a preset number, a part of the threads with higher event processing volume can be further selected to sleep, which can ensure that resource consumption is reduced as much as possible while meeting the system performance requirements, thereby improving the energy efficiency and stability of the system.
[0082] In an exemplary embodiment, the above method also includes: in a case where a target thread exists in the storage system, monitoring the event processing volume of the target thread, wherein the target thread is a thread in a dormant state; in a case where the event processing volume of the target thread is greater than a second threshold, waking up the target thread whose event processing volume is greater than the second threshold, wherein the second threshold is less than or equal to the first threshold.
[0083] It should be noted that the target thread can refer to a thread that has been marked by the system as a thread to be dormant or in a dormant state. After being marked as a thread to be dormant or in a dormant state, the target thread will be monitored. When the load status changes or the system detects that the event processing volume of some threads exceeds a preset threshold, these threads will become the objects of monitoring.
[0084] The second threshold is a parameter that can be used to determine whether the dormant thread (target thread) needs to be awakened. Typically, the second threshold is lower than or equal to the first threshold. When the target thread's event processing volume (even the cumulative number of events processed after dormancy) exceeds the second threshold, it is considered that the thread's potential work demand has increased and it needs to be resumed from dormancy to handle more incoming events in a timely manner.
[0085] The size of the second threshold can be determined based on an empirical value, and this application does not limit this.
[0086] Through this embodiment, the event processing volume of the target thread is monitored. When the event processing volume of the target thread is greater than the second threshold, the target thread whose event processing volume is greater than the second threshold is awakened. This ensures the stable operation of the storage system under different loads by dynamically monitoring and adjusting the thread status, thereby improving the response speed and processing capability of the system.
[0087] In an exemplary embodiment, the above method also includes: when it is monitored that the change trend of the load state of the storage system meets the preset change trend, obtaining storage indicator data within a preset time window, wherein the preset change trend is from a first load state to a second load state or from the second load state to a third load state, and the preset time window includes multiple consecutive statistical periods, and the multiple consecutive statistical periods include the current statistical period; when it is determined based on the storage indicator data within the preset time window that the load state of the storage system is a specified state within the preset time window, triggering the execution of the sleep strategy corresponding to the specified state, wherein, when the load state changes from the first load state to the second load state, the specified state is the second load state, and when the load state changes from the second load state to the third load state, the specified state is the third load state.
[0088] It should be noted that the preset change trend refers to the expected direction of change in the storage system's load state, specifically from a first load state (usually high load) to a second load state (medium load), or from a second load state to a third load state (low load). The load state change trend can be determined by continuously acquiring storage indicator data within a specific time window.
[0089] The preset time window can consist of a continuous time period or multiple consecutive statistical cycles. During the preset time window, storage system performance data can be collected and analyzed to determine areas of load fluctuation. Specifically, the length of the preset time window can be set as needed to reflect load trends without excessive lag that could affect system response speed.
[0090] The designated state is the target state determined based on the current storage system load change trend. For example, if the system detects a trend from high load to medium load, the designated state is the second load state (medium load); if the system detects a trend from medium load to low load, the designated state is the third load state (low load).
[0091] It should be noted that, when it is determined that the current load state of the storage system changes from low to medium, or from medium to high, a quick adjustment can be made to perform the hibernation process according to the adjusted load state.
[0092] Optionally, a sleep policy determines which threads can enter a sleep state, as well as sleep parameters (such as sleep duration) based on the current load of the storage system. For example, under low load, a more aggressive sleep policy can be implemented, allowing all threads to sleep when there are no events being processed, while under medium to high load, only some threads with low event processing volume can be put to sleep.
[0093] In one example, assuming that the storage system is currently in a first load state (high load), the system monitors storage indicator data within five consecutive statistical periods (preset time windows) indicating that IOPS and throughput are gradually decreasing, while latency is gradually increasing, which indicates that the system load is changing from high to medium (second load state). Based on the preset change trend, it is determined that the load state change trend of the storage system satisfies the transition from the first to the second state. Next, the storage indicator data within the preset time window is analyzed to confirm that the load state of the storage system is in the second load state during these periods. Based on this judgment, the execution of the sleep strategy corresponding to the second load state can be triggered, that is, the event processing volume of all threads is first counted, and those threads whose event processing volume is lower than the first threshold are selected as threads to be dormant, and the number of threads to be dormant is further controlled according to the second preset number, and then sleep control is performed.
[0094] Through this embodiment, by monitoring the load status change trend of the storage system and confirming this trend over multiple consecutive statistical periods, it is possible to more intelligently decide when and how to execute the sleep strategy, avoiding unnecessary adjustments when the load status fluctuates briefly, and improving the system's response accuracy and stability.
[0095] Figure 5 This is a flowchart of the thread control method in this optional example, such as Figure 5 As shown, the process of the thread control method may include the following steps:
[0096] Step 1, thread initialization;
[0097] Specifically, the Reactor_init function is mainly used for preparation before thread startup.
[0098] Step 2, thread start;
[0099] Step 3: The thread obtains the event and processes it, and the event processing volume of each thread is recorded;
[0100] Step 4, determining whether the preset period has been reached;
[0101] Specifically, after the duration corresponding to the preset period ends, it can be determined that the preset period has been reached, and the process jumps to step 5; if the preset period has not been reached, the process jumps to step 7.
[0102] Step 5: If it is determined that the preset period has been reached and the event processing amount is greater than the preset value, the thread may be placed in a non-sleeping stage for the next preset period; if the event processing amount is less than the preset value, the thread may be placed in a sleeping stage for the next preset period;
[0103] Step 6: Reset the event processing capacity of the thread;
[0104] Step 7: If it is determined that the preset period has not been reached, determine whether the current state is a global sleep state;
[0105] Specifically, during the statistical period, the system will decide whether to adjust the sleep policy globally based on the overall load status (for example, through the IOPS statistics of the BDEV device). If the system load is high, all sleep controls may be suspended.
[0106] Specifically, if it is determined that the global sleep state is in progress, the process proceeds to step 8; if it is determined that the global sleep state is not in progress, the process proceeds to step 3.
[0107] Step 8, determine whether the thread is currently in the dormant stage;
[0108] Specifically, if it is determined that the thread is currently in the sleep phase, the process is adjusted to step 9; if it is determined that the thread is currently not in the sleep phase, the process jumps to step 3.
[0109] Step 9: Execute the sleep operation.
[0110] Specifically, after determining that the thread can be in the sleep phase, a short sleep is performed to reduce CPU usage. The length of the sleep time can be adjusted according to the event processing volume of the thread, usually in microseconds.
[0111] This optional example determines whether to enter sleep mode based on the actual event processing volume after determining the storage system's load status. This improves the accuracy and responsiveness of the sleep strategy. Reactor threads decide to sleep based on their own circumstances, and through a global load judgment mechanism, the sleep strategies of all Reactor threads are synchronously adjusted to ensure a rapid response and maintain system stability when the overall storage system load changes. By dynamically adjusting the sleep strategy, the storage system can intelligently allocate CPU resources under high, medium, and low load conditions, ensuring system responsiveness under high load while saving energy under low load, achieving the dual goals of performance and energy conservation and emission reduction.
[0112] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0113] The embodiment of the present application further provides a thread control device, which is applied to a storage system including a group of block devices and a group of threads, wherein a thread in the group of threads is used to process an event sent by a received block device; Figure 6 As shown, the device includes:
[0114] An acquisition module 602 is configured to acquire storage index data in a previous statistical period, wherein the storage index data is used to describe performance indicators of a group of block devices;
[0115] Determination module 604, configured to determine the load status of the storage system in the current statistical period based on the storage indicator data in the previous statistical period;
[0116] The sleep module 606 is used to determine a thread to be dormant in a group of threads based on the event processing volume of one thread in the group of threads and the load status of the storage system, and control the thread to be dormant to sleep for a specified period of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified period is negatively correlated with the event processing volume of the thread to be dormant.
[0117] In an exemplary embodiment, the acquisition module 602 is further used to: traverse a group of block devices to obtain device status statistical information of the block devices in the group of block devices in the previous statistical period, wherein the device status statistical information is used to describe the operating performance of the block devices in the previous statistical period; and calculate the storage indicator data in the previous statistical period based on the device status statistical information of the block devices in the group of block devices in the previous statistical period.
[0118] In an exemplary embodiment, the storage indicator data includes indicator values corresponding to multiple indicator data, and the load state of the storage system is one of a first load state, a second load state, and a third load state, wherein the loads corresponding to the first load state, the second load state, and the third load state decrease in sequence.
[0119] The determination module 604 is also used to: determine that the storage system is in a first load state in the current statistical period when there is at least one indicator data among the multiple indicator data whose corresponding indicator value is greater than a first preset threshold; determine that the storage system is in a second load state in the current statistical period when there is no at least one indicator data among the multiple indicator data whose corresponding indicator value is greater than the first preset threshold, and there is at least one indicator data whose corresponding indicator value is greater than the second preset threshold, wherein the first preset threshold corresponding to one indicator data among the multiple indicator data is greater than the second preset threshold; and determine that the storage system is in a third load state in the current statistical period when there is no indicator data whose corresponding indicator value is greater than the second preset threshold.
[0120] In an exemplary embodiment, the hibernation module 606 is further used to: when the load state of the storage system is in a second load state, when there is a thread in a group of threads whose event processing volume is less than a first threshold, set the thread whose event processing volume is less than the first threshold as a thread to be hibernated.
[0121] In an exemplary embodiment, the sleep module 606 is also used to: when the number of threads whose event processing volume is less than the first threshold is less than a preset number, arrange the remaining threads in descending order according to the event processing volume, wherein the remaining threads are threads in a group of threads excluding those whose event processing volume is less than the first threshold; select the first specified number of threads from the sorted remaining threads as threads to be dormant, wherein the specified number is the difference between the preset number and the number of threads whose event processing volume is less than the first threshold.
[0122] In an exemplary embodiment, the above-mentioned device also includes: a wake-up module, which is used to monitor the event processing volume of the target thread when there is a target thread in the storage system, wherein the target thread is a thread in a dormant state; when the event processing volume of the target thread is greater than a second threshold, wake up the target thread whose event processing volume is greater than the second threshold, wherein the second threshold is less than or equal to the first threshold.
[0123] In an exemplary embodiment, the above-mentioned device also includes: an execution module, which is used to obtain storage indicator data in a preset time window when it is monitored that the change trend of the load state of the storage system meets the preset change trend, wherein the preset change trend is from a first load state to a second load state or from the second load state to a third load state, and the preset time window includes multiple consecutive statistical periods, and the multiple consecutive statistical periods include the current statistical period; when it is determined according to the storage indicator data in the preset time window that the load state of the storage system is a specified state in the preset time window, trigger the execution of the sleep strategy corresponding to the specified state, wherein, when the load state changes from the first load state to the second load state, the specified state is the second load state, and when the load state changes from the second load state to the third load state, the specified state is the third load state.
[0124] For the description of the features in the embodiment corresponding to the thread control device, reference can be made to the relevant description of the embodiment corresponding to the thread control method, which will not be repeated here.
[0125] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned thread control method embodiments.
[0126] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above-mentioned thread control method embodiments when running.
[0127] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0128] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned thread control method embodiments are implemented.
[0129] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned thread control method embodiments are implemented.
[0130] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0131] The above is a detailed introduction to a thread control method, device, electronic device, and storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only intended to help understand the method and core ideas of the present application. It should be pointed out that, for those skilled in the art, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A thread control method, characterized in that: The method is applied to a storage system including a group of block devices and a group of threads, wherein a thread in the group of threads is used to process an event sent by a received block device; the method includes: Acquire storage indicator data in a previous statistical period, wherein the storage indicator data is used to describe performance indicators of the group of block devices; Determining a load state of the storage system in a current statistical period based on the storage indicator data in the previous statistical period; Based on the event processing volume of one thread in the group of threads and the load status of the storage system, a thread to be dormant in the group of threads is determined, and the thread to be dormant is controlled to sleep for a specified period of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified period of time is negatively correlated with the event processing volume of the thread to be dormant.
2. The method according to claim 1, characterized in that The obtaining of storage indicator data in the previous statistical period includes: Performing traversal processing on the group of block devices to obtain device status statistical information of block devices in the group of block devices in the previous statistical period, wherein the device status statistical information is used to describe the operating performance of the block devices in the previous statistical period; The storage indicator data in the previous statistical period is calculated according to the device status statistical information of the block devices in the group of block devices in the previous statistical period.
3. The method according to claim 2, characterized in that The load state of the storage system is one of a first load state, a second load state, and a third load state, wherein the loads corresponding to the first load state, the second load state, and the third load state decrease in sequence; the storage indicator data includes indicator values corresponding to a plurality of indicator data; and determining the load state of the storage system in a current statistical period based on the storage indicator data in a previous statistical period includes: When an indicator value corresponding to at least one indicator data among the multiple indicator data is greater than a first preset threshold, determining that the storage system is in a first load state in the current statistical period; If there is no indicator value corresponding to at least one indicator data among the multiple indicator data that is greater than the first preset threshold, and there is an indicator value corresponding to at least one indicator data that is greater than the second preset threshold, determining that the storage system is in the second load state in the current statistical period, wherein the first preset threshold corresponding to one indicator data among the multiple indicator data is greater than the second preset threshold; If there is no indicator data corresponding to an indicator value greater than the second preset threshold, it is determined that the storage system is in a third load state in the current statistical period.
4. The method according to claim 1, wherein The step of determining a thread to be dormant in the group of threads according to an event processing amount of one thread in the group of threads and a load status of the storage system includes: When the load state of the storage system is in the second load state, and there is a thread in the group of threads whose event processing volume is less than a first threshold, the thread whose event processing volume is less than the first threshold is used as the thread to be dormant.
5. The method according to claim 4, characterized in that The method further comprises: When the number of threads whose event processing volume is less than the first threshold is less than a preset number, arranging the remaining threads in descending order according to the event processing volume, wherein the remaining threads are threads in the group of threads excluding the threads whose event processing volume is less than the first threshold; A specified number of threads are selected from the sorted remaining threads as the threads to be dormant, wherein the specified number is a difference between the preset number and the number of threads whose event processing volume is less than the first threshold.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: In a case where a target thread exists in the storage system, monitoring the event processing amount of the target thread, wherein the target thread is a thread in a dormant state; When the event processing amount of the target thread is greater than a second threshold, the target thread whose event processing amount is greater than the second threshold is awakened, wherein the second threshold is less than or equal to the first threshold.
7. The method according to any one of claims 1 to 5, characterized in that The method further comprises: When it is monitored that a change trend of the load state of the storage system satisfies a preset change trend, acquiring the storage indicator data within a preset time window, wherein the preset change trend is a change from a first load state to a second load state or from the second load state to a third load state, and the preset time window includes a plurality of consecutive statistical periods, and the plurality of consecutive statistical periods include the current statistical period; When it is determined based on the storage indicator data in the preset time window that the load status of the storage system in the preset time window is a specified status, a sleep strategy corresponding to the specified status is triggered for execution, wherein, when the first load status changes to the second load status, the specified status is the second load status, and when the second load status changes to the third load status, the specified status is the third load status.
8. A thread control device, characterized in that: The device is applied to a storage system including a group of block devices and a group of threads, wherein a thread in the group of threads is used to process an event sent by a received block device; the device includes: An acquisition module, configured to acquire storage indicator data in a previous statistical period, wherein the storage indicator data is used to describe performance indicators of the group of block devices; a determination module, configured to determine a load state of the storage system in a current statistical period based on the storage indicator data in the previous statistical period; A sleep module is used to determine a thread to be dormant in the group of threads based on the event processing volume of one thread in the group of threads and the load status of the storage system, and control the thread to be dormant to sleep for a specified period of time after processing the received events, wherein the event processing volume is the number of events processed by the corresponding thread in a preset period, and the specified period is negatively correlated with the event processing volume of the thread to be dormant.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the thread control method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the thread control method according to any one of claims 1 to 7.