A thread pool is a collection of threads that the Ice run time draws upon to perform specific tasks.
On this page:
Each communicator creates two thread pools:
By default, these two thread pools are shared by all of the communicator's object adapters. If necessary, you can configure individual object adapters to use a private thread pool instead.
If a thread pool is exhausted because all threads are currently dispatching a request, additional incoming requests are transparently delayed until a request completes and relinquishes its thread; that thread is then used to dispatch the next pending request. Ice minimizes thread context switches in a thread pool by using a leader-follower implementation [1].
Each thread pool has a unique name that serves as the prefix for its configuration properties:
name.Size
name.SizeMax
name.Size
, this property is adjusted to be equal to name.Size
.name.SizeWarn
name.SizeMax
. The default value is zero, which disables the warning.name.StackSize
name.Serialize
name.ThreadIdleTime
For configuration purposes, the names of the client and server thread pools are Ice.ThreadPool.Client
and Ice.ThreadPool.Server
, respectively. As an example, the following properties establish the initial and maximum sizes for these thread pools:
{zcode} Ice.ThreadPool.Client.Size=1 Ice.ThreadPool.Client.SizeMax=10 Ice.ThreadPool.Server.Size=1 Ice.ThreadPool.Server.SizeMax=10 {zcode} |
To monitor the thread pool activities of the Ice run time, you can enable the Ice.Trace.ThreadPool
property. Setting this property to a non-zero value causes the Ice run time to log a message when it creates a thread pool, as well as each time the size of a thread pool increases or decreases.
A dynamic thread pool can grow and shrink when necessary in response to changes in an application's work load. All thread pools have at least one thread, but a dynamic thread pool can grow as the demand for threads increases, up to the pool's maximum size. Threads may also be terminated automatically when they have been idle for some time.
The dynamic nature of a thread pool is determined by the configuration properties name.Size
, name.SizeMax
, and name.ThreadIdleTime
. A thread pool is not dynamic in its default configuration because name.Size
and name.SizeMax
are both set to one, meaning the pool can never grow to contain more than a single thread. To configure a dynamic thread pool, you must set at least one of name.Size
or name.SizeMax
to a value greater than one. We can use several configuration scenarios to explore the semantics of dynamic thread pools in greater detail:
name.SizeMax=5
name.Size
has a default value of one, and Ice can grow the pool up to the maximum of five threads. During periods of inactivity, idle threads terminate after 60 seconds (the default value for name.ThreadIdleTime
) until the pool contains just one thread again.name.Size=3
name.SizeMax=5
name.Size=3
name.ThreadIdleTime=10
name.SizeMax
defaults to the value of name.Size
).name.SizeMax=5
name.ThreadIdleTime=0
name.ThreadIdleTime
is set to zero.name.Size=5
name.ThreadIdleTime=0
To summarize, the value of name.ThreadIdleTime
determines whether (and how quickly) a thread pool can shrink to a size of one. A thread pool that shrinks can also grow to its maximum size. Finally, setting name.SizeMax
to a value larger than name.Size
allows a thread pool to grow beyond its initial capacity.