ThreadPool Component
The ThreadPool component is a pool of threads used to process jobs submitted to the pool. The jobs are queued for handling.
When the configurable number of jobs in the queue is reached, further jobs can be blocked or rejected; if the job is rejected, an error is returned.
If job priority is configured, the processing thread runs at the set priority. This implies that the POSIX FIFO policy is applied and means that the job queue must queue the jobs by priority.
If thread affinity is configured, all threads in a pool run on the specified CPU.
The thread pool can be stopped and started multiple times.
Configuration
You can configure the following:
- The number of initial threads in a pool
- The maximum number of jobs in the queue
- Priority
- Thread affinity
- Whether to wait until all scheduled jobs complete
Configuration Variables
The following table describes the configuration variables that can be used with the ThreadPool component:
Name | Type | Description | Valid Values |
---|---|---|---|
Logger | String | Name of the Logger component to use | The name of an existing Logger component |
Threads | Unsigned integer | The number of pool threads |
IoTech recommends that you calculate the size of your thread pool to make the best use of time and resources
Default value is 2 |
MaxJobs | Unsigned integer | The maximum number of queued jobs | Default value is 0 (no limit) |
Priority | Integer | The priority of the pool threads |
The range is system-dependent
For example on Linux it is usually between 1 and 100 with 1 being the lowest priority and 100 being the highest priority |
Affinity | Integer | The processor affinity of pool threads | The number of the CPU to use in the range 0 to n |
ShutdownDelay | Unsigned integer | The maximum interval in milliseconds that the pool waits for threads to complete when the pool is free | Default value is 200 |
Note
All the configuration variables are optional.
Configuration Example
The following example configures a ThreadPool component with a maximum queue of ten jobs, processed on CPU 11 with a priority of 99, and which waits for 2000ms for the threads to complete when the pool is free:
{
"Threads": 1,
"MaxJobs": 10,
"Affinity": 11,
"Priority": 99,
"Logger": "logger",
"ShutdownDelay": 2000
}