How Does the ThreadPool’s Minimum Thread Count Work?

17 08 2011

ThreadPool threads are created only on demand, increasing the minimum thread count to x does not mean that x threads are created straight away. Rather, it instructs the pool manager to create up to x threads the instant they are required.

The base strategy of the ThreadPool manager is to create the same number of threads as there are cores, if the queue remains stationary for more than half a second the pool manager responds by creating more threads – one every half-second – up to the capacity of the ThreadPool. This helps to prevent a brief burst of short-lived activity by fully allocating threads and suddenly swelling an application’s memory footprint. Where your tasks block on something e.g. a database query to return, it can be useful to avoid this half second delay.

You can tell the pool manager not to delay in the allocation of the first x threads, by calling SetMinThreads, for instance:

ThreadPool.SetMinThreads (50, 50);

The second value indicates how many threads to assign to I/O completion ports.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: