A task scheduling system for sensor network data

Through the Poisson process and queuing theory, the adaptive thread pool is designed, and the number of threads is dynamically adjusted, which solves the problem of resource waste and scheduling performance in traditional thread pools, and improves the utilization rate of thread pools and server performance.

CN114942837BActive Publication Date: 2024-12-03CHINA UNIV OF GEOSCIENCES (WUHAN)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210539884.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-18
Publication Date
2024-12-03
Estimated Expiration
2042-05-18

AI Technical Summary

Technical Problem

In traditional thread pools, thread creation and destruction take up high resources, and the number of core threads and maximum threads are difficult to dynamically adjust, affecting network scheduling performance.

Method used

Adaptive thread pool is designed using Poisson process and queuing theory, and the number of threads is calculated and adjusted in real time through the Reactor model and task queue. The Poisson process is used to adapt the core thread number N1 and the queuing theory to adapt the maximum number of threads N2, and dynamic management is used. Thread pool.

Benefits of technology

It improves the utilization rate of thread pools in network IO, reduces the waste of idle threads, matches the number of core threads with the arrival frequency of tasks, and maximizes the maximum number of threads under server performance conditions, optimizing the use of server resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114942837B_ABST
    Figure CN114942837B_ABST
Patent Text Reader

Abstract

The present invention discloses a task scheduling system for sensor network data, comprising: a reactor model, a task queue and an adaptive thread pool; the epoll unit of the reactor model monitors network requests, and encapsulates the types of network requests into different tasks, and appends them to the task queue; the adaptive thread pool obtains the assigned tasks from the task queue and executes them, and the adapter of the adaptive thread pool analyzes the task queue state and the working time of the working thread during the execution process, and calculates and adjusts the number of threads in real time. The beneficial effects of the present invention are: improving the utilization rate of the thread pool in the network IO, enabling N1 to match the arrival frequency of the task, reducing the waste caused by idle threads, and enabling N2 to reach the maximum under the server performance conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of computer thread management, and in particular to a task scheduling system oriented to sensor network data. Background Art

[0002] In the design of software business solutions, server efficiency is of paramount importance, and the use of multi-threading technology is an important means to improve server operating efficiency. Multi-threading makes full use of the multi-core performance of the central processing unit (CPU), and divides the operation of the entire process into several time slices, and staggers multiple tasks into the time slices. From a macro perspective, multiple tasks are executed simultaneously, thereby improving the concurrency of multiple tasks.

[0003] However, the creation and destruction of threads also consume certain space and time resources. Let the time required for thread creation be t1, the time required for thread destruction be t2, and the time required for task execution be t3. If a worker thread is created when a task arrives and the thread is destroyed when the task ends, the actual time to execute a task is t1+t3+t2, and the effective time ratio is t3 / (t1+t2+t3). If (t1+t2)<<t3, this method can be used. If (t1+t2) is not negligible relative to t3, or even (t1+t2)>t3, the effective time ratio of task execution will become smaller, and server resources will be wasted on creating and destroying threads. We hope that the server will invest more resources in the execution of tasks rather than in thread creation and destruction, so we have thread pool technology.

[0004] Thread pool technology solves the problem of high resource usage of thread creation and destruction. In traditional thread pools, the thread pool pre-creates a minimum number (N1) of threads, where N1 is called the core thread number. These threads are in a sleeping state, where they give up CPU resources but still occupy memory resources. When a task arrives, the thread pool assigns the task to an idle thread, and when the task is completed, the thread returns to an idle state. When the current tasks exceed N1, the tasks are added to the task queue and wait for execution; when the task queue reaches its maximum capacity, the thread pool creates a new thread until the number of threads reaches the maximum number of threads N2; when the thread is idle for the set maximum time T1, the thread pool will destroy the thread and reclaim the resources occupied by the thread until the number of threads is reduced to N1.

[0005] In traditional thread pools, N1, N2, and T1 are all configured by developers, and are difficult to modify after the program is compiled. Generally, the configuration must be modified by republishing the program. In particular, N1 directly affects the performance of network scheduling. If N1 is too small, the program will often create and destroy threads, wasting CPU resources; if N1 is too large, many threads will be idle for a long time and cannot be destroyed, resulting in a waste of memory resources. Summary of the invention

[0006] In order to improve the utilization rate of the thread pool in the network IO, the present invention uses the theory of Poisson process and queuing theory to design a thread pool for adjusting the core thread number N1 and the maximum thread number N2 of the thread pool.

[0007] The present invention provides a task scheduling system for sensor network data, comprising: a Reactor model, a task queue and an adaptive thread pool;

[0008] The epoll unit of the Reactor model monitors network requests, encapsulates the types of network requests into different tasks, and appends them to the task queue;

[0009] The adaptive thread pool obtains the assigned tasks from the task queue and executes them, and the adapter of the adaptive thread pool analyzes the task queue status and the working time of the working threads during the execution process, and calculates and adjusts the number of threads in real time.

[0010] Furthermore, the number of threads in the adaptive thread pool is managed by the adaptive thread pool itself.

[0011] Furthermore, the adaptive thread pool has two chain containers, namely a working thread container and an idle thread container.

[0012] Furthermore, when the adaptive thread pool obtains the assigned task, there is no need to traverse the idle thread container. Only the thread at the end of the queue is taken out from the idle thread container. The time complexity of assigning the task is O(1). After the assignment, the thread at the end of the queue is added to the working thread container.

[0013] Furthermore, the number of threads calculated and adjusted by the adapter includes the number of core threads N1 and the maximum number of threads N2.

[0014] Furthermore, the number of core threads N1 is adapted using a non-homogeneous Poisson process, specifically as follows:

[0015]

[0016] The number of tasks processed by a single thread per unit time is μ, and the number of tasks arriving per unit time is λ.

[0017] The maximum number of threads N2 is adapted using queuing theory, specifically as follows:

[0018]

[0019] Where T(x) is the average time it takes for a single task to arrive at the task queue and be processed when the number of threads is x; Y is the system resource consumption of using a single thread; ω is the coefficient that non-dimensionalizes T(x) and Y.

[0020] The beneficial effects provided by the present invention are: improving the utilization rate of the thread pool in the network IO, enabling N1 to match the arrival frequency of tasks, reducing the waste caused by idle threads, and enabling N2 to reach the maximum under the server performance conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is the basic structural diagram of the system of the present invention. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solution and advantages of the present invention more clear, the embodiments of the present invention will be further described below in conjunction with the accompanying drawings.

[0023] Please refer to Figure 1 , Figure 1 It is a basic structural diagram of the system of the present invention;

[0024] The present invention provides a task scheduling system for sensor network data, comprising: a Reactor model, a task queue and an adaptive thread pool;

[0025] The epoll unit of the Reactor model monitors network requests, encapsulates the types of network requests into different tasks, and appends them to the task queue;

[0026] It should be noted that this process is divided into two steps:

[0027] 1. epoll monitors network requests

[0028] First, the reactor receives the service request from the client and demultiplexes it. The reactor puts the received request into the task queue. The reactor uses IO multiplexing epoll() to detect IO events on the socket handle.

[0029] 2. Encapsulate the network request type into different tasks and add them to the task queue

[0030] When an IO event is detected, epoll_wait() is used to return the network socket handle, and the socket handle connected to the network sensor is encapsulated into a task and stored in the TaskQueue.

[0031] The adaptive thread pool obtains the assigned tasks from the task queue and executes them, and the adapter of the adaptive thread pool analyzes the task queue status and the working time of the working threads during the execution process, and calculates and adjusts the number of threads in real time.

[0032] It should be noted that the adaptive thread pool takes the Task containing the socket handle from the task queue and assigns it to an idle thread to execute the task. Task is an abstract class that can derive different specific tasks according to different request types. The derived tasks are the calculation process for executing specific transaction processing. The monitoring is handed over to Reactor for completion. The working thread does not wait for the network connection, so there is no need to consider the problem of long-term thread blocking.

[0033] The key point of this application is to design an adapter in the management of the thread pool. The adapter uses a counter and a timer to record the number of tasks entering the task queue within a period of time, and records the execution time of each task. The two quantities are counted to obtain calculation parameters, and the appropriate number of core threads and the maximum number of threads can be calculated based on the parameters.

[0034] The following is a detailed description of the adaptive thread pool.

[0035] The number of threads in the adaptive thread pool is managed by the thread pool ThreadPool itself. There are two chain containers in the thread pool (that is, the adaptive thread pool of this application), namely the working thread container and the idle thread container.

[0036] The advantage of using a linked container is that the thread object can be created in the heap and can be changed between the working or idle state by simply changing its pointer, without the need to copy it repeatedly between the idle container and the working container.

[0037] In order to give priority to the threads in the pool, that is, the thread that finishes the work the latest will be used first next time, the idle thread container uses a queue, and only allows operations on the head and tail of the chain container. The idle thread container is referred to as the idle queue below.

[0038] When ThreadPool assigns tasks, there is no need to traverse the idle queue. It only needs to take out the thread at the end of the queue from the idle queue and assign the task. The time complexity of assigning tasks is O(1). After assignment, the thread is added to the worker thread container.

[0039] After the task is completed, the thread inserts itself into the end of the idle queue without the need for ThreadPool operation, ensuring that the idle thread taken out by ThreadPool next time is the latest to finish its work.

[0040] If the idle queue is empty, it means that all threads are currently working. At this time, the tasks distributed by Reactor are temporarily stored in the task queue, and the task queue also serves as a cache to reduce the peak. If the idle thread is empty and the task queue is full, the waiting worker thread will change from busy to idle.

[0041] Compared with the traditional thread pool, the advantages of the present invention are: the adaptive thread pool has an adapter that can automatically adjust the number of core threads N1 and the maximum number of threads N2 according to the frequency of network connection and the average time of task processing.

[0042] First, the adapter will continuously count the time intervals between task arrivals and their distribution patterns, with the parameter denoted as λ;

[0043] At the same time, the processing time of the task is counted, and its distribution parameter is denoted as μ;

[0044] Based on these two parameters, we can calculate the appropriate number of working threads.

[0045] The number of threads always creates or destroys worker threads according to N1. If there is no idle thread available for a newly arrived task, the task continues to wait in the task queue.

[0046] Compared with the traditional thread pool, this approach avoids the situation where a large number of tasks suddenly arrive and create a large number of worker threads, which are then idle for a long time. N2 is calculated through optimization methods and queuing theory methods, just to limit the server performance degradation caused by creating too many threads.

[0047] When the idle queue is not empty and some idle threads need to be destroyed, check whether the idle time T of the first thread in the idle queue exceeds the maximum idle time T1 set in advance. If T>T1, the first thread is destroyed. Because the thread that finishes work later will be inserted at the end of the queue, the first thread in the idle queue must be the thread with the longest idle time.

[0048] Each thread has a timer T. If the thread is idle, T is used to calculate the idle time so that the thread pool can destroy unnecessary threads.

[0049] If the thread is in working state, T is used to calculate the working time, which is convenient for the adapter to calculate the parameter μ. If the working time is too long, the state of the thread is considered abnormal, the task understanding ends and jumps to the idle state to prevent the thread from being suspended and cannot be reused.

[0050] N1 can be obtained by simple division operation, and the real-time performance and accuracy of N1 directly affect the performance of network scheduling, so it needs to be calculated continuously. The calculation of N2 is more complicated, and N2 is only to limit N1 from being too large, so N2 only needs to be calculated at a longer time interval using timed events.

[0051] The number of threads calculated and adjusted by the adapter includes the number of core threads N1 and the maximum number of threads N2. The following describes the calculation methods of the two numbers of threads in turn.

[0052] (1) Use a non-homogeneous Poisson process to adapt N1

[0053] It has been verified that the process of data reaching the server is a Poisson process with intensity λ, and the process of data operation ending belongs to a homogeneous Poisson process with distribution intensity μ. The task processing times are independent of each other, and their distribution conforms to the negative exponential distribution.

[0054] By counting the tasks entering the task queue, the number of tasks arriving per unit time is calculated as the distribution intensity λ. Since this process is non-homogeneous, it can be considered as segmented. r It is a homogeneous Poisson process, so every time t r The number of tasks processed per unit time by a single thread is μ, and the number of tasks arriving per unit time is λ. If the processing volume per unit time matches the number of arriving tasks, then

[0055] N1μ=λ

[0056] At the same time, N1≤N2, so we have

[0057]

[0058] (2) Using queuing theory to adapt N2

[0059] N2 is the maximum capacity of the thread pool, which is to limit the number of threads created in the thread pool to prevent memory overflow. The value of N2 is related to system performance. For tasks to be processed, the larger N2 is, the more tasks can be processed simultaneously. However, for the server, the larger N2 is, the more resources need to be consumed, which will affect the performance of the server. This application establishes an optimization model for the thread pool by analyzing the impact of three characteristics on the thread pool: throughput, task calculation time, and task blocking time. By quantifying the consumption of system resources by the thread pool as Y, the solution to N2 can be converted into an optimization problem:

[0060]

[0061] Where T(x) is the average time it takes for a single task to arrive at the task queue and complete processing when the number of threads is x; Y is the system resource consumption of using a single thread; ω is the coefficient that non-dimensionalizes T(x) and Y.

[0062] It should be understood that parts not elaborated in detail in this specification belong to the prior art.

[0063] The beneficial effects of the present invention are: enabling N1 to match the arrival frequency of tasks, reducing the waste caused by idle threads, and enabling N2 to reach a maximum under server performance conditions.

[0064] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A task scheduling system for sensor network data, characterized by: include: Reactor model, task queue and adaptive thread pool; The epoll unit of the Reactor model monitors network requests, encapsulates the types of network requests into different tasks, and appends them to the task queue; The adaptive thread pool obtains the assigned tasks from the task queue and executes them, and the adapter of the adaptive thread pool analyzes the task queue status and the working time of the working threads during the execution process, and calculates and adjusts the number of threads in real time; The number of threads calculated and adjusted by the adapter includes the number of core threads N1 and the maximum number of threads N2; The number of core threads N1 is adapted using a non-homogeneous Poisson process, specifically as follows: The number of tasks processed by a single thread per unit time is μ, and the number of tasks arriving per unit time is λ; The maximum number of threads N2 is adapted using queuing theory, specifically as follows: Where T(x) is the average time it takes for a single task to arrive at the task queue and be processed when the number of threads is x; Y is the system resource consumption of using a single thread; ω is the coefficient that non-dimensionalizes T(x) and Y.

2. A task scheduling system for sensor network data as claimed in claim 1, characterized in that: The number of threads in the adaptive thread pool is managed by the adaptive thread pool itself.

3. A task scheduling system for sensor network data as claimed in claim 1, characterized in that: The adaptive thread pool has two chain containers, namely a working thread container and an idle thread container.

4. A task scheduling system for sensor network data as claimed in claim 3, characterized in that: When the adaptive thread pool obtains the assigned task, there is no need to traverse the idle thread container. It only takes out the thread at the end of the queue from the idle thread container. The time complexity of assigning the task is O(1). After the assignment, the thread at the end of the queue is added to the working thread container.