SwiftMQ's entire design is non-blocking. All tasks performed by other Swiftlets are dispatched to thread pools and are performed asynchronously.
All thread pools are managed by the Threadpool Swiftlet. A thread pool consists of a pool queue which is a fast ring buffer and threads to execute dispatched tasks.
If a thread pool is created, the number of threads is pre-created and will never die. One should always have "some" minimum threads per pool if that pool is often frequented, such as JMS pools. An adequate minimum thread setting will prevent that threads will die after the idle timeout and thus must be recreated if a new task instance is dispatched to the pool. One should not specify too many threads to keep the resource consumption low. The best way is to watch the "Usage" entity table of the Threadpool Swiftlet from the SwiftMQ Explorer to the average usage per pool. This is a good value for the minimum thread setting.
This setting avoids resource exhaustion and is also used to guarantee that, in some pools, only 1 thread will be executed at all. E.g. the Log Manager of the Store Swiftlet uses his own pool and there should never be more than 1 thread running within that pool. Therefore, one should never change this setting if it is specified within the default configuration.
Queue Length Threshold and Additional Threads
These two attributes specify the pool growing policy. During each dispatch of a task to a pool, it is checked whether the pool is out of threads. This is the case if no idle thread is available. Normally, if a pool is configured with a minimum size of threads, these threads handle the load. At peaks, if more tasks are dispatched, the pool's queue grows up. By specifying a queue length threshold, one can define how large the pool's queue may grow until additional threads are started. Per default, both attributes have a value of 1, that is, if no idle thread is available during a task dispatch, 1 additional thread will be started. E.g. to handle peak loads, one can specify that 5 additional threads should be started if the queue length reaches 10. If the queue length is below 10, no additional threads are started and the tasks are waiting until a thread becomes available.
The idle timeout specifies the time in milliseconds after which a thread will die in the case that it is idle. If this value is too low, threads might die too early and you will get into the re-creation problem. If it is too high, threads might be idle too long and you may consume too much threads. So it really depends on the interval in which tasks are dispatched to the pool. The default idle timeout is 120000 milliseconds and should fit most requirements.
This setting specifies the thread priority of this pool. We have never seen that this has an effect at all concerning the processing behaviour. The default is normal priority (5).
The configuration of the Threadpool Swiftlet is defined within the element
<swiftlet name="sys$threadpool" .../>
of the router's configuration file. One can use the SwiftMQ Exlorer or CLI for configuration as well. They both save into that file.
Attributes of Element "swiftlet"
|collect-interval||java.lang.Long||No||Interval for collecting the Thread Counts per Pool|
Element List "pools", Parent Element: "swiftlet"
Threadpool Definitions. This element list contains zero or more "pool" elements with this template definition:
|name||java.lang.String||Yes||Name of this Pool|
|kernel-pool||java.lang.Boolean||No||Marked as a Kernel Pool or not|
|min-threads||java.lang.Integer||No||Minimum Threads in this Pool|
|max-threads||java.lang.Integer||No||Maximum Threads in this Pool|
|queue-length-threshold||java.lang.Integer||No||Starts new Threads when the Queue Length reaches this Threshold|
|additional-threads||java.lang.Integer||No||Number Threads to Startup after reaching Threshold|
|priority||java.lang.Integer||No||Priority for Threads in this Pool|
|idle-timeout||java.lang.Long||No||Timeout for idling Threads in this Pool|
Element List "threads", Parent Element: "pool"
Thread Assignment Definitions. This element list contains zero or more "thread" elements with this template definition:
|name||java.lang.String||Yes||Name of this Thread|
Element List "usage", Parent Element: "swiftlet"
Active Threadpools. This element list contains zero or more "usage" elements with this template definition:
|name||java.lang.String||Yes||Name of this Thread Pool|
|running-threads||java.lang.Integer||No||Running Threads in this Pool|
|idling-threads||java.lang.Integer||No||Idling Threads in this Pool|