Skip to content

Commit 08c47e4

Browse files
kouvelgewarren
andauthored
Add some info to ThreadPool.SetMinThreads on how increasing the minimum threads may degrade performance (#8406)
Add some info to `ThreadPool.SetMinThreads` on how increasing the minimum threads may degrade performance Co-authored-by: Genevieve Warren <[email protected]>
1 parent f46f4f3 commit 08c47e4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

xml/System.Threading/ThreadPool.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,16 @@ If a thread pool implementation may have different types of work items, the coun
12651265
12661266
If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using <xref:System.Threading.ThreadPool.GetMaxThreads%2A>), <xref:System.Threading.ThreadPool.SetMinThreads%2A> returns `false` and does not change either of the minimum values.
12671267
1268+
By default, the minimum number of threads is set to the processor count. You can use <xref:System.Threading.ThreadPool.SetMinThreads%2A> to increase the minimum number of threads, such as to temporarily work around issues where some queued work items or tasks block thread pool threads. Those blockages sometimes lead to a situation where all worker or I/O completion threads are blocked (starvation). However, increasing the minimum number of threads might degrade performance in other ways, such as:
1269+
1270+
- The thread pool may schedule more worker threads, even when the worker threads are not getting blocked. The oversubscription can cause threads that get scheduled-out to be significantly delayed as they wait in a long queue to get another time slice, delaying some work items or tasks.
1271+
- Worker threads may take more CPU time in dequeuing work items due to having to scan more threads to steal work from.
1272+
- Context switching between threads may increase CPU usage.
1273+
- Garbage collection may take more CPU time in thread stack walking.
1274+
- The process may consume more memory.
1275+
12681276
> [!CAUTION]
1269-
> By default, the minimum number of threads is set to the number of processors on a system. You can use the <xref:System.Threading.ThreadPool.SetMinThreads%2A> method to increase the minimum number of threads. However, unnecessarily increasing these values can cause performance problems. If too many tasks start at the same time, all of them might appear to be slow. In most cases, the thread pool will perform better with its own algorithm for allocating threads. Reducing the minimum to less than the number of processors can also hurt performance.
1277+
> Using the <xref:System.Threading.ThreadPool.SetMinThreads%2A> method to increase the minimum number of threads can cause performance problems as described in the preceding text. In most cases, the thread pool will perform better with its own algorithm for allocating threads. Reducing the minimum to less than the number of processors can also hurt performance.
12701278
12711279
12721280

0 commit comments

Comments
 (0)