Method and device for improving use efficiency of data acquisition resources
Through the dynamic sensing and adaptive resource allocation mechanism, it distinguishes task types and manages thread pools, solving the problem of low resource utilization in large-scale data collection scenarios, and achieving efficient resource management and performance improvement.
Patent Information
- Application Number
- CN202410311008.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-19
- Publication Date
- 2024-08-23
AI Technical Summary
In large-scale data collection scenarios, low-consumption tasks occupy thread resources for a long time, resulting in waste, while high-consumption tasks occupy resources for a long execution time, causing other tasks to lag in execution. Traditional execution methods are difficult to efficiently map different types of tasks to appropriate execution mechanisms. As a result, resources cannot be used rationally.
Adopting a dynamic sensing and adaptive resource allocation mechanism, through real-time monitoring of Task execution time, resource occupation and number of failures, it dynamically distinguishes Task types, assigns low-consuming Tasks to the thread pool shared mode, and uses high-consuming Tasks to use the exclusive mode, through the TaskEvaluator and ThreadAllocationStrategy class to implement dynamic management of thread pool.
It improves the utilization rate of data collection resources, avoids resource waste and inefficient scheduling, improves system performance and concurrency efficiency, and adapts to different workloads and optimization goals.
Smart Images

Figure CN118535319A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of large-scale data collection, and in particular to a method and device for improving the utilization efficiency of data collection resources. Background Art
[0002] In large-scale data collection scenarios, there are often a large number of low-consumption tasks or high-consumption tasks with long execution times. These tasks usually have different levels of resource consumption, but the tasks themselves cannot actively perceive their own execution time and resource usage. Therefore, there is a common problem: low-consumption tasks occupy thread resources for a long time, resulting in waste, while high-consumption tasks occupy resources for a long execution time, causing other tasks to lag seriously. Due to the unclear characteristics of tasks, traditional execution methods find it difficult to efficiently map different types of tasks to appropriate execution mechanisms, resulting in unreasonable resource utilization. Summary of the invention
[0003] In order to solve the above problems existing in the traditional execution mode, the present invention provides a method and device for improving the efficiency of data acquisition resource utilization. Through a dynamic perception and adaptive resource allocation mechanism, the actual execution of each Task is monitored in real time, including indicators such as execution time, resource occupancy, and number of failures, and the resource consumption type of Task is dynamically distinguished according to these indicators. According to the resource consumption type of Task, low-consumption Tasks can be allocated to the thread pool sharing mode, and high-consumption Tasks can use the exclusive mode, thereby improving the utilization rate of data acquisition resources.
[0004] To achieve the above object, the present invention adopts the following technical solutions:
[0005] In one embodiment of the present invention, a method for improving the utilization efficiency of data acquisition resources is proposed, the method comprising:
[0006] Define a TaskGroup class to represent the collection task group; define a Task class to represent the specific collection task, and the collection task provides the execution logic method;
[0007] Define a TaskGroupManager class and a TaskManager class to create a preliminary collection task group and collection task queue, and define a ThreadPoolManager thread pool class to create an independent thread pool to provide execution resources for collection tasks;
[0008] In the thread where the Task is executed, the execution time of the Task is checked at regular intervals to determine whether it has timed out. At the same time, the exception information that caused the Task to time out and the end time of the Task are recorded.
[0009] Monitor the CPU utilization, memory consumption, and I / O statistics of each executing task in real time to dynamically evaluate its resource consumption type;
[0010] Define a ThreadAllocationStrategy class to allocate threads, including two thread pools: SharedThreadPool and ExclusiveThreadPool.
[0011] Furthermore, the process of determining whether a Task has timed out is as follows:
[0012] When a task starts executing, the current timestamp is obtained as the start time of the task. In the thread where the task is executed, the current execution time of the task is checked at regular intervals. The current execution time of the task is subtracted from the start time of the task to calculate the running time of the task from the start to now.
[0013] Check whether the running time of the Task from the start to now exceeds the timeout threshold. If it exceeds the timeout threshold, the Task is considered to have timed out and the number of timeouts for the Task is increased by 1. If the number of timeouts exceeds the threshold, the Task is removed from the collection task queue and the exception information that caused the execution timeout is recorded.
[0014] Furthermore, the CPU utilization, memory consumption, and I / O statistics of each monitored Task are regularly saved to a central database; a TaskEvaluator class is defined to comprehensively evaluate the CPU utilization, memory consumption, and I / O statistics of each Task and give its resource consumption type.
[0015] Furthermore, the process of allocating threads is as follows:
[0016] When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation;
[0017] TaskEvaluator collects the CPU usage, memory consumption, and I / O statistics of the Task in the previous executions, makes a comprehensive judgment on its resource consumption type, and determines whether the Task is a heavy task or a light task;
[0018] TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy; if the Task is a lightweight task, ThreadAllocationStrategy queries the current thread status of SharedThreadPool. If there is an idle thread, the thread is used to execute the Task; if the current threads of SharedThreadPool are all in use, the Task is added to the waiting task queue;
[0019] If the Task is a heavy task, ThreadAllocationStrategy determines whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads; if it does not exceed the limit, directly obtain a thread from ExclusiveThreadPool to execute the Task; if the number of threads has reached the upper limit, ThreadAllocationStrategy creates a new thread to join ExclusiveThreadPool to execute the Task;
[0020] After the task is executed, the thread executing the task is put back into the corresponding thread pool; for SharedThreadPool, the thread is directly put into the thread pool after being recycled; for ExclusiveThreadPool, it is determined whether the thread has actually executed a heavy task. If the resource consumption type has been downgraded, the thread is released back to the ExclusiveThreadPool, otherwise the thread object is directly destroyed;
[0021] During the execution of the Task, ThreadAllocationStrategy periodically checks whether the resource consumption type has changed; if a heavy task is reduced to a light task, its thread is transferred from the ExclusiveThreadPool to the SharedThreadPool; if a light task is increased to a heavy task, its thread is adjusted accordingly from the SharedThreadPool to the ExclusiveThreadPool.
[0022] In one embodiment of the present invention, a device for improving the utilization efficiency of data acquisition resources is also proposed, the device comprising:
[0023] The collection task definition module is used to define a TaskGroup class to represent the collection task group; define a Task class to represent a specific collection task, and the collection task provides a method for executing logic;
[0024] The collection task initial creation module is used to define a TaskGroupManager class and a TaskManager class to create a preliminary collection task group and collection task queue, and to define a ThreadPoolManager thread pool class to create an independent thread pool to provide execution resources for the collection task;
[0025] The task execution information collection module is used to detect the execution time of the task at regular intervals in the thread of task execution to determine whether it has timed out, and to record the exception information that caused the task execution timeout and the end time of the task;
[0026] Task indicator information evaluation module, which is used to monitor the CPU utilization, memory consumption, and I / O statistics of each executing task in real time, so as to dynamically evaluate its resource consumption type;
[0027] The thread allocation module is used to define a ThreadAllocationStrategy class to allocate threads, including two thread pools: SharedThreadPool and ExclusiveThreadPool.
[0028] Furthermore, the process of determining whether a Task has timed out is as follows:
[0029] When a task starts executing, the current timestamp is obtained as the start time of the task. In the thread where the task is executed, the current execution time of the task is checked at regular intervals. The current execution time of the task is subtracted from the start time of the task to calculate the running time of the task from the start to now.
[0030] Check whether the running time of the Task from the start to now exceeds the timeout threshold. If it exceeds the timeout threshold, the Task is considered to have timed out and the number of timeouts for the Task is increased by 1. If the number of timeouts exceeds the threshold, the Task is removed from the collection task queue and the exception information that caused the execution timeout is recorded.
[0031] Furthermore, the CPU utilization, memory consumption, and I / O statistics of each monitored Task are regularly saved to a central database; a TaskEvaluator class is defined to comprehensively evaluate the CPU utilization, memory consumption, and I / O statistics of each Task and give its resource consumption type.
[0032] Furthermore, the process of allocating threads is as follows:
[0033] When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation;
[0034] TaskEvaluator collects the CPU usage, memory consumption, and I / O statistics of the Task in the previous executions, makes a comprehensive judgment on its resource consumption type, and determines whether the Task is a heavy task or a light task;
[0035] TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy; if the Task is a lightweight task, ThreadAllocationStrategy queries the current thread status of SharedThreadPool. If there is an idle thread, the thread is used to execute the Task; if the current threads of SharedThreadPool are all in use, the Task is added to the waiting task queue;
[0036] If the Task is a heavy task, ThreadAllocationStrategy determines whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads; if it does not exceed the limit, directly obtain a thread from ExclusiveThreadPool to execute the Task; if the number of threads has reached the upper limit, ThreadAllocationStrategy creates a new thread to join ExclusiveThreadPool to execute the Task;
[0037] After the task is executed, the thread executing the task is put back into the corresponding thread pool; for SharedThreadPool, the thread is directly put into the thread pool after being recycled; for ExclusiveThreadPool, it is determined whether the thread has actually executed a heavy task. If the resource consumption type has been downgraded, the thread is released back to the ExclusiveThreadPool, otherwise the thread object is directly destroyed;
[0038] During the execution of the Task, ThreadAllocationStrategy periodically checks whether the resource consumption type has changed; if a heavy task is reduced to a light task, its thread is transferred from the ExclusiveThreadPool to the SharedThreadPool; if a light task is increased to a heavy task, its thread is adjusted accordingly from the SharedThreadPool to the ExclusiveThreadPool.
[0039] In one embodiment of the present invention, a computer device is also proposed, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the method for improving the utilization efficiency of the aforementioned data acquisition resources is implemented when the processor executes the computer program.
[0040] In one embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium stores a computer program for executing the method for improving the utilization efficiency of data acquisition resources.
[0041] Beneficial effects:
[0042] 1. The present invention can better match task requirements and improve task execution efficiency by dynamically evaluating resource consumption types and selecting exclusive or shared threads according to actual consumption conditions, thereby avoiding waste of resources and inefficient thread scheduling, thereby improving the performance of the overall system.
[0043] 2. The present invention processes low-consumption tasks through fair scheduling and the use of shared threads, thereby avoiding the situation where independent resources are occupied for a long time, thus making full use of resources, reducing resource waste, and improving system resource utilization.
[0044] 3. For high-consumption tasks, the present invention uses exclusive threads to avoid their impact on other tasks and improve concurrency performance; at the same time, for low-consumption tasks, the fair sharing principle can be adopted to enable them to be properly executed under limited resources, thereby improving the concurrency capability of the overall system.
[0045] 4. The present invention supports dynamic addition and modification of tasks and configuration of indicator thresholds, and can be flexibly adjusted according to changes in tasks and the needs of different scenarios, so as to better adapt to different workloads and optimization goals and improve the adaptability and flexibility of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a flow chart of a method for improving the utilization efficiency of data acquisition resources of the present invention;
[0047] Figure 2 It is a flow chart of defining TaskGroup and Task in the present invention;
[0048] Figure 3 It is a schematic diagram of the structure of TaskManager and ThreadPoolManager defined in the present invention;
[0049] Figure 4 It is a flowchart of thread allocation of the present invention;
[0050] Figure 5 is a schematic diagram of implementation step 1 of an embodiment of the present invention;
[0051] Figure 6 is a schematic diagram of implementation step 2 of an embodiment of the present invention;
[0052] Figure 7 is a schematic diagram of implementation step three of an embodiment of the present invention;
[0053] Figure 8 is a schematic diagram of implementation step 4 of an embodiment of the present invention;
[0054] Fig. 9 is a schematic diagram of implementation step five of an embodiment of the present invention;
[0055] Fig.10 It is a schematic diagram of the structure of a device for improving the utilization efficiency of data acquisition resources of the present invention;
[0056] Fig.11 It is a schematic diagram of the computer device structure of the present invention. DETAILED DESCRIPTION
[0057] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0058] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0059] According to the implementation of the present invention, a method for improving the efficiency of data acquisition resource utilization is proposed. Through a dynamic perception and adaptive resource allocation mechanism, the actual execution of each Task is monitored in real time, including indicators such as execution time, resource occupancy, and number of failures, and the resource consumption type of Task is dynamically distinguished according to these indicators. According to the resource consumption type of Task, low-consumption Tasks can be allocated to the thread pool sharing mode, and high-consumption Tasks can use the exclusive mode, thereby improving the utilization rate of data acquisition resources.
[0060] The principle and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.
[0061] Figure 1 Schematic diagram of the method for improving the efficiency of data acquisition resource utilization of the present invention. Figure 1As shown, the method includes:
[0062] S1. Define TaskGroup and Task
[0063] like Figure 2 As shown, first, define a TaskGroup class to represent the collection task group. The TaskGroup object needs to define the properties related to the collection task group, such as the name of the collection task group, the corresponding collection scene or target, etc. Then, define a Task class to represent the specific collection task. The Task object needs to define the properties and methods related to the collection task, such as the name of the collection task, the content of the collection task, the start time of execution, the execution status, etc. The collection task needs to provide the execution logic method call() for the executor to call to execute the collection task. The most important method of Task is the call() method. The executor drives the operation of Task by calling the call() method of Task. The call() method will have a return value ProgressState. The executor can use ProgressState to determine whether the Task has ended and whether it needs to continue calling the call() method.
[0064] S2. Define TaskGroupManager (collection task group manager), TaskManager (collection task manager) and ThreadPoolManager (thread pool manager)
[0065] Define a ThreadPoolManager thread pool class to manage and schedule the execution threads of the collection tasks, such as Figure 3 As shown, the specific method is as follows:
[0066] (1) createThreadPool(int size): Create a fixed-length thread pool based on the number of threads.
[0067] (2)allocateThread(): Takes an idle thread from the thread pool, and returns null if there is none.
[0068] (3)recycleThread(Thread thread): puts the thread back into the queue of available threads in the thread pool.
[0069] (4)getPoolSize(): Get the current number of threads in the thread pool.
[0070] (5) resizePool(int newSize): Dynamically increase or decrease the thread pool size based on the passed value.
[0071] (6) shutdown(): Shut down the thread pool, that is, no longer accept new collection tasks, and close all threads after all collection tasks are completed.
[0072] Define a TaskGroupManager class to manage different TaskGroup objects. The specific methods are as follows:
[0073] (1)addTaskGroup(TaskGroup group): Adds a TaskGroup object to the management list.
[0074] (2)removeTaskGroup(String groupName): Delete the collection task group from the list based on its name.
[0075] (3) getTaskGroupList(): Returns a list of all collection task group objects.
[0076] Define a TaskManager to manage the task queue, such as Figure 3 As shown, the specific method is as follows:
[0077] (1)addTask(Task task): Add a Task object to the waiting queue.
[0078] (2)executeTask(Task task): Take the Task from the waiting queue and hand it over to the ThreadPool for execution.
[0079] (3)removeTask(Task task): delete the collection task from the waiting queue.
[0080] (4)getTaskQueueSize(): Get the waiting queue size.
[0081] The main process needs to use TaskGroupManager and TaskManager to create a preliminary collection task group and collection task queue, and use ThreadPoolManager to create an independent thread pool to provide execution resources for the collection task, thus completing the preliminary creation of the collection task group and thread resources.
[0082] S3. Collect Task execution information
[0083] When a Task starts executing, the NanoTime() function is called to obtain the current timestamp as the start execution time of the Task, startExecutionTime. The accuracy of this timestamp can be down to the nanosecond level. In the thread where the Task is executed, the current execution time of the Task is detected every 100 milliseconds. By calling NanoTime() to obtain the current execution time and subtracting it from the start execution time of the Task, the executedTime of the Task from the start to now can be calculated. Among them, Nanotime is a method for obtaining the current system time. Compared with other methods for obtaining time, Nanotime has higher accuracy and can be used in scenarios that require high-precision timing.
[0084] Then it will check whether executedTime exceeds the timeout threshold of the Task. The timeout threshold can be set differently according to different types of Tasks with different resource consumption, such as 1 minute for low-consumption Tasks and 10 minutes for high-consumption Tasks. If executedTime exceeds the timeout threshold, the Task is considered to have timed out. In addition to the execution time, each Task can set other indicators to determine the timeout, such as the number of loops, the number of log entries, etc. These indicators also need to be checked regularly, and if the threshold is reached, the execution is considered to have timed out. After the Task execution times out, the timeout count of the Task will be increased by 1 through the timeout count incrementTimeoutCount method. If the timeout count exceeds the threshold, which is 10 times by default, the Task will be removed from the Task queue, and the exception information that caused the execution timeout will also be recorded for troubleshooting and optimization. When the Task ends normally, the end time will also be obtained through NanoTime() and recorded in the end time endExecutionTime property of the Task object. Then the actual execution time of the Task can be calculated based on the start and end time. These indicator data of all Tasks can be counted for subsequent tuning reference.
[0085] The above design checks the execution status of the Task at regular intervals, and can determine whether it has timed out in real time, avoiding the previous situation where the judgment can only be made after the Task is completed. At the same time, by recording detailed execution information, it is conducive to the optimization and improvement of subsequent Tasks.
[0086] S4. Evaluation Task Indicator Information
[0087] In order to correctly judge the resource consumption type of a Task, it is necessary to monitor the execution indicators of each Task in real time, so as to dynamically evaluate its resource consumption. Specifically, the CPU utilization of each executing Task will be monitored in real time. This can be done by calling the API provided by the system. For example, the getrusage function can be called in the Linux system to obtain the user and system CPU time of the task. Among them, getrusage is a commonly used system call that can obtain the resource usage of the current process and is built into the Linux kernel. By calculating the percentage of CPU time to the total time of the Task, the current CPU utilization of the Task can be obtained. At the same time, the memory size occupied by the Task will also be monitored in real time. The Task object can retain its currently allocated memory and check whether the memory has increased at regular intervals (such as 100 milliseconds). If so, the increment will be recorded. The memory usage at different time points during the execution of the Task can also be monitored to determine its memory consumption level. For those Tasks that require a large number of I / O operations, the I / O statistics during their execution will also be specifically monitored, including the number of I / Os and the amount of data generated when reading and writing files and network communications. These I / O information will also be accumulated and recorded in the Task object in real time. In addition to the above general resource indicators, the concurrency relationship between tasks is also examined. If a task needs to be executed independently without being affected by other tasks, it indicates that it has high requirements for concurrency.
[0088] All the resource indicator data collected will be regularly saved to a central database. Design a TaskEvaluator class to summarize and evaluate the indicator data of each Task after a certain period of execution, and give its resource consumption type. TaskEvaluator will make a comprehensive judgment by calling the task CPU utilization, memory consumption, I / O statistics, etc. collected by various monitoring classes. If the CPU occupancy of the Task exceeds 50% or the memory consumption is greater than a certain threshold, it is judged as a heavy task, otherwise it is a light task, which will provide a basis for subsequent thread allocation.
[0089] S5. Allocate threads
[0090] In order to reasonably allocate threads according to different resource indicators of Task, a ThreadAllocationStrategy class is designed to be responsible for thread allocation. It contains two thread pools:
[0091] SharedThreadPool (fixed 10 threads): used to execute lightweight tasks in shared mode.
[0092] ExclusiveThreadPool (dynamic expansion): used to perform heavy tasks in exclusive mode.
[0093] like Figure 4 The specific workflow is as follows:
[0094] When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation. TaskEvaluator collects indicators such as CPU usage, memory consumption, I / O statistics, etc. of the task in the previous executions, makes a comprehensive judgment on its resource consumption type, and gives whether the task is a heavy task or a light task.
[0095] TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy (which is responsible for thread allocation). If the Task is a lightweight task, ThreadAllocationStrategy will first query the current thread status of SharedThreadPool. If there is an idle thread, it will use the thread to execute the task; if the current threads of SharedThreadPool are all in use, the Task will be added to the waiting queue.
[0096] If TaskEvaluator determines that the Task is a heavy task, ThreadAllocationStrategy will first determine whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads. If it does not exceed the limit, a thread is directly obtained from ExclusiveThreadPool to execute the Task; if the number of threads has reached the upper limit, ThreadAllocationStrategy will create a new thread to join ExclusiveThreadPool to execute the Task.
[0097] After the task is completed, the thread executing the task will be put back into the corresponding thread pool. For SharedThreadPool, the thread is directly put into the thread pool after recycling; for ExclusiveThreadPool, it will determine whether the thread has actually executed heavy tasks. If the resource consumption type has been downgraded, the thread will be released back to the ExclusiveThreadPool, otherwise the thread object will be directly destroyed.
[0098] During the execution of a Task, ThreadAllocationStrategy will periodically check whether the resource consumption type has changed. If the heavy task indicator drops to light, its thread will be transferred from ExclusiveThreadPool to SharedThreadPool; if the light task indicator increases to heavy, its thread will also be adjusted from SharedThreadPool to ExclusiveThreadPool accordingly.
[0099] It should be noted that, although the operations of the method of the present invention are described in a specific order in the above embodiments and the accompanying drawings, this does not require or imply that the operations must be performed in the specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0100] In order to explain the above method for improving the efficiency of data acquisition resource utilization more clearly, a specific embodiment is described below. However, it should be noted that this embodiment is only for better illustrating the present invention and does not constitute an improper limitation to the present invention.
[0101] Example:
[0102] 1. If Figure 5 As shown, TaskManager adds Task-1 to the task queue TaskQueue and starts executing Task-1. ThreadPoolManager calls allocateThread() method (method for allocating threads) to obtain an idle thread from ThreadPool, executes the execution logic of Task-1, and records the execution time of the task.
[0103] 2. If Figure 6 As shown in the figure, if the execution time of Task-1 exceeds the set threshold of 10 minutes, ThreadPoolManager obtains another thread from ThreadPool and starts executing Task-2 to ensure that other Tasks are not affected by Task-1.
[0104] 3. If Figure 7As shown in the figure, if Task-2 is executed normally, it is put back to the end of the task queue TaskQueue, waiting for the next execution, and the recycleThread(thread) method of the ThreadPoolManager class (a method for recycling idle threads) is called to put the thread back into the thread pool. At the same time, a new Task is obtained from the task queue and assigned to the idle thread for execution.
[0105] 4. If Figure 8 As shown, if Task-1 is completed, it is put back to the end of the task queue TaskQueue and the thread is put back into the thread pool ThreadPool.
[0106] 5. If Fig. 9 As shown, if Task-1 is executed multiple times and exceeds the threshold of 10 times, it will be removed from the task queue TaskQueue, and thread Thread-2 will be assigned to Task-3 for exclusive use.
[0107] Based on the same inventive concept, the present invention also proposes a device for improving the efficiency of data acquisition resource utilization. The implementation of the device can refer to the implementation of the above method, and the repeated parts will not be repeated. The term "module" used below can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0108] Fig.10 Schematic diagram of the structure of the device for improving the efficiency of data acquisition resource utilization of the present invention. Fig.10 As shown, the device comprises:
[0109] The collection task definition module 101 is used to define a TaskGroup class to represent a collection task group; define a Task class to represent a specific collection task, and the collection task provides a method for executing logic.
[0110] The collection task preliminary creation module 102 is used to define a TaskGroupManager class and a TaskManager class to create a preliminary collection task group and a collection task queue, and to define a ThreadPoolManager thread pool class to create an independent thread pool to provide execution resources for the collection task.
[0111] The task execution information collection module 103 is used to detect the execution time of the task at regular intervals in the thread of task execution to determine whether it has timed out, and to record the abnormal information that caused the task execution timeout and the end time of the task;
[0112] The process of determining whether a Task has timed out is as follows:
[0113] When a task starts executing, the current timestamp is obtained as the start time of the task. In the thread where the task is executed, the current execution time of the task is checked at regular intervals. The current execution time of the task is subtracted from the start time of the task to calculate the running time of the task from the start to now.
[0114] Check whether the running time of the Task from the start to now exceeds the timeout threshold. If it exceeds the timeout threshold, the Task is considered to have timed out and the number of timeouts for the Task is increased by 1. If the number of timeouts exceeds the threshold, the Task is removed from the collection task queue and the exception information that caused the execution timeout is recorded.
[0115] The task indicator information evaluation module 104 is used to monitor the CPU utilization, memory consumption and I / O statistics of each executing task in real time, so as to dynamically evaluate its resource consumption type;
[0116] The CPU utilization, memory consumption, and I / O statistics of each monitored Task are regularly saved to a central database; a TaskEvaluator class is defined to comprehensively evaluate the CPU utilization, memory consumption, and I / O statistics of each Task and give its resource consumption type.
[0117] The thread allocation module 105 is used to define a ThreadAllocationStrategy class to allocate threads, including two thread pools: SharedThreadPool and ExclusiveThreadPool;
[0118] The process of allocating threads is as follows:
[0119] When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation;
[0120] TaskEvaluator collects the CPU usage, memory consumption, and I / O statistics of the Task in the previous executions, makes a comprehensive judgment on its resource consumption type, and determines whether the Task is a heavy task or a light task;
[0121] TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy; if the Task is a lightweight task, ThreadAllocationStrategy queries the current thread status of SharedThreadPool. If there is an idle thread, the thread is used to execute the Task; if the current threads of SharedThreadPool are all in use, the Task is added to the waiting task queue;
[0122] If the Task is a heavy task, ThreadAllocationStrategy determines whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads; if it does not exceed the limit, directly obtain a thread from ExclusiveThreadPool to execute the Task; if the number of threads has reached the upper limit, ThreadAllocationStrategy creates a new thread to join ExclusiveThreadPool to execute the Task;
[0123] After the task is executed, the thread executing the task is put back into the corresponding thread pool; for SharedThreadPool, the thread is directly put into the thread pool after being recycled; for ExclusiveThreadPool, it is determined whether the thread has actually executed a heavy task. If the resource consumption type has been downgraded, the thread is released back to the ExclusiveThreadPool, otherwise the thread object is directly destroyed;
[0124] During the execution of the Task, ThreadAllocationStrategy periodically checks whether the resource consumption type has changed; if a heavy task is reduced to a light task, its thread is transferred from the ExclusiveThreadPool to the SharedThreadPool; if a light task is increased to a heavy task, its thread is adjusted accordingly from the SharedThreadPool to the ExclusiveThreadPool.
[0125] It should be noted that although several modules of the device for improving the efficiency of data acquisition resource utilization are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules described above can be concretized in one module. Conversely, the features and functions of one module described above can be further divided into multiple modules for concretization.
[0126] Based on the above invention concept, Fig.11As shown, the present invention also proposes a computer device 200, including a memory 210, a processor 220, and a computer program 230 stored in the memory 210 and executable on the processor 220, and the method for improving the utilization efficiency of the aforementioned data acquisition resources is implemented when the processor 220 executes the computer program 230.
[0127] Based on the aforementioned inventive concept, the present invention further proposes a computer-readable storage medium, which stores a computer program for executing the aforementioned method for improving the utilization efficiency of data acquisition resources.
[0128] The method and device for improving the efficiency of data collection resource utilization proposed in the present invention have the following highlights:
[0129] 1. By dynamically evaluating resource consumption types and selecting exclusive or shared threads based on actual consumption, we can better match task requirements and improve task execution efficiency. This can avoid waste of resources and inefficient thread scheduling, thereby improving the performance of the overall system.
[0130] 2. By using fair scheduling and shared threads to handle low-consumption tasks, it is possible to avoid long-term occupation of independent resources. This can make full use of resources, reduce resource waste, and improve system resource utilization.
[0131] 3. For high-consumption tasks, using exclusive threads can avoid their impact on other tasks and improve concurrency performance. At the same time, for low-consumption tasks, the fair sharing principle can ensure that they are properly executed under limited resources, thereby improving the concurrency capability of the overall system.
[0132] 4. By supporting dynamic addition and modification of tasks and configuration of indicator thresholds, flexible adjustments can be made according to changes in tasks and the needs of different scenarios. This can better adapt to different workloads and optimization goals, and improve the adaptability and flexibility of the system.
[0133] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements contained in the spirit and scope of the attached claims.
[0134] Regarding the limitation of the protection scope of the present invention, those skilled in the art should understand that, based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative work are still within the protection scope of the present invention.
Claims
1. A method for improving the efficiency of data collection resource utilization, characterized in that: The method includes: Define a TaskGroup class to represent the collection task group; define a Task class to represent the specific collection task, and the collection task provides the execution logic method; Define a TaskGroupManager class and a TaskManager class to create a preliminary collection task group and collection task queue, and define a ThreadPoolManager thread pool class to create an independent thread pool to provide execution resources for collection tasks; In the thread where the Task is executed, the execution time of the Task is checked at regular intervals to determine whether it has timed out. At the same time, the exception information that caused the Task to time out and the end time of the Task are recorded. Monitor the CPU utilization, memory consumption, and I / O statistics of each executing task in real time to dynamically evaluate its resource consumption type; Define a ThreadAllocationStrategy class to allocate threads, including two thread pools: SharedThreadPool and ExclusiveThreadPool.
2. The method for improving the utilization efficiency of data acquisition resources according to claim 1, characterized in that: The process of determining whether a Task has timed out is as follows: When a task starts executing, the current timestamp is obtained as the start time of the task execution. In the thread where the task is executed, the current execution time of the task is checked at regular intervals. Subtract the current execution time of the Task from the start execution time of the Task to calculate the running time of the Task from the start to now; Check whether the running time of the Task from the start to now exceeds the timeout threshold. If it exceeds the timeout threshold, the Task is considered to have timed out and the number of timeouts for the Task is increased by 1. If the number of timeouts exceeds the threshold, the Task is removed from the collection task queue and the exception information that caused the execution timeout is recorded.
3. The method for improving the utilization efficiency of data acquisition resources according to claim 1, characterized in that: The CPU utilization, memory consumption, and I / O statistics of each monitored Task are regularly saved to a central database; a TaskEvaluator class is defined to comprehensively evaluate the CPU utilization, memory consumption, and I / O statistics of each Task and give its resource consumption type.
4. The method for improving the utilization efficiency of data acquisition resources according to claim 1, characterized in that: The process of allocating threads is as follows: When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation; TaskEvaluator collects the CPU usage, memory consumption, and I / O statistics of the Task in the previous executions, makes a comprehensive judgment on its resource consumption type, and determines whether the Task is a heavy task or a light task; TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy; if the Task is a light task, ThreadAllocationStrategy queries the current thread status of SharedThreadPool, and uses the thread to execute the Task if there is an idle thread; If the current threads of SharedThreadPool are all in use, add the Task to the waiting task queue; If the Task is a heavy task, ThreadAllocationStrategy determines whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads; if it does not exceed the limit, a thread is directly obtained from ExclusiveThreadPool to execute the Task; If the number of threads has reached the upper limit, ThreadAllocationStrategy creates a new thread to join the ExclusiveThreadPool to execute the Task; After the task is executed, the thread executing the task is put back into the corresponding thread pool; for SharedThreadPool, the thread is directly put into the thread pool after being recycled; for ExclusiveThreadPool, it is determined whether the thread has actually executed a heavy task. If the resource consumption type has been downgraded, the thread is released back to the ExclusiveThreadPool, otherwise the thread object is directly destroyed; During the execution of the Task, ThreadAllocationStrategy periodically checks whether the resource consumption type has changed; if a heavy task is reduced to a light task, its thread is transferred from the ExclusiveThreadPool to the SharedThreadPool; if a light task is increased to a heavy task, its thread is adjusted accordingly from the SharedThreadPool to the ExclusiveThreadPool.
5. A device for improving the efficiency of data collection resource utilization, characterized in that: The device includes: The collection task definition module is used to define a TaskGroup class to represent the collection task group; define a Task class to represent a specific collection task, and the collection task provides a method for executing logic; The collection task initial creation module is used to define a TaskGroupManager class and a TaskManager class to create a preliminary collection task group and collection task queue, and to define a ThreadPoolManager thread pool class to create an independent thread pool to provide execution resources for the collection task; The task execution information collection module is used to detect the execution time of the task at regular intervals in the thread of task execution to determine whether it has timed out, and to record the exception information that caused the task execution timeout and the end time of the task; Task indicator information evaluation module, which is used to monitor the CPU utilization, memory consumption, and I / O statistics of each executing task in real time, so as to dynamically evaluate its resource consumption type; The thread allocation module is used to define a ThreadAllocationStrategy class to allocate threads, including two thread pools: SharedThreadPool and ExclusiveThreadPool.
6. The device for improving the utilization efficiency of data acquisition resources according to claim 5, characterized in that: The process of determining whether a Task has timed out is as follows: When a task starts executing, the current timestamp is obtained as the start time of the task execution. In the thread where the task is executed, the current execution time of the task is checked at regular intervals. Subtract the current execution time of the Task from the start execution time of the Task to calculate the running time of the Task from the start to now; Check whether the running time of the Task from the start to now exceeds the timeout threshold. If it exceeds the timeout threshold, the Task is considered to have timed out and the number of timeouts for the Task is increased by 1. If the number of timeouts exceeds the threshold, the Task is removed from the collection task queue and the exception information that caused the execution timeout is recorded.
7. The device for improving the utilization efficiency of data acquisition resources according to claim 5, characterized in that: The CPU utilization, memory consumption, and I / O statistics of each monitored Task are regularly saved to a central database; a TaskEvaluator class is defined to comprehensively evaluate the CPU utilization, memory consumption, and I / O statistics of each Task and give its resource consumption type.
8. The device for improving the utilization efficiency of data acquisition resources according to claim 5, characterized in that: The process of allocating threads is as follows: When TaskManager obtains a new task to be executed, it submits the task to TaskEvaluator for resource evaluation; TaskEvaluator collects the CPU usage, memory consumption, and I / O statistics of the Task in the previous executions, makes a comprehensive judgment on its resource consumption type, and determines whether the Task is a heavy task or a light task; TaskEvaluator returns the resource consumption type judgment result to ThreadAllocationStrategy; if the Task is a light task, ThreadAllocationStrategy queries the current thread status of SharedThreadPool, and uses the thread to execute the Task if there is an idle thread; If the current threads of SharedThreadPool are all in use, add the Task to the waiting task queue; If the Task is a heavy task, ThreadAllocationStrategy determines whether the current number of threads in ExclusiveThreadPool exceeds the configured maximum number of threads; if it does not exceed the limit, a thread is directly obtained from ExclusiveThreadPool to execute the Task; If the number of threads has reached the upper limit, ThreadAllocationStrategy creates a new thread to join the ExclusiveThreadPool to execute the Task; After the task is executed, the thread executing the task is put back into the corresponding thread pool; for SharedThreadPool, the thread is directly put into the thread pool after being recycled; for ExclusiveThreadPool, it is determined whether the thread has actually executed a heavy task. If the resource consumption type has been downgraded, the thread is released back to the ExclusiveThreadPool, otherwise the thread object is directly destroyed; During the execution of the Task, ThreadAllocationStrategy periodically checks whether the resource consumption type has changed; if a heavy task is reduced to a light task, its thread is transferred from the ExclusiveThreadPool to the SharedThreadPool; if a light task is increased to a heavy task, its thread is adjusted accordingly from the SharedThreadPool to the ExclusiveThreadPool.
9. A computer 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 computer program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 4.
Citation Information
Cited By
Memory application method and device, electronic equipment and storage medium
CN120909780A
