线程池

高并发的情况下,线程对性能的影响.参考文章
https://hk.saowen.com/a/04ae5d1284a0aeea206c983889fe17c39115a0d571e5452458164c754e5d089b (重点)
https://www.cnblogs.com/Charltsing/p/taskpoolthread.html
https://www.cnblogs.com/kissdodog/archive/2013/03/28/2986026.html
https://www.dotnetperls.com/threadpool-setminthreads
http://www.volatileread.com/Thread/index?id=28
http://www.infosysblogs.com/microsoft/2007/04/understanding_net_threadpool.html
http://www.voidcn.com/article/p-aaqdbcra-zn.html
https://support.microsoft.com/zh-cn/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365198(v=vs.85).aspx (IOCP)

查看.net程序中线程池的情况

用windbg的 !theadpool 命令进行查看。

操作步骤如下:

1. 运行windbg,File->Attach a Process,选择一个**.exe进程,然后点击OK。

2. 在命令窗口输入命令:

 .load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll

3. 接着输入命令:

 !threadpool

得到如下结果:

0:000> !threadpool
The version of SOS does not match the version of CLR you are debugging.  Please
load the matching version of SOS for the version of CLR you are debugging.
CLR Version: 4.6.1590.0
SOS Version: 4.7.3110.0
CPU utilization: 0%
Worker Thread: Total: 8 Running: 5 Idle: 3 MaxLimit: 32767 MinLimit: 8
Work Request in Queue: 0
--------------------------------------
Number of Timers: 1
--------------------------------------
Completion Port Thread:Total: 1 Free: 1 MaxFree: 16 CurrentLimit: 1 MaxLimit: 1000 MinLimit: 8

如何修改线程池的设置呢?两种方法:
  • 1C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config中进行设置:

  • 2 代码中写

ThreadPool.SetMinThreads(100, 100);


image.png

image.png

windbg工具使用分析此问题参考:
用windbg检查.NET线程池设置
http://www.cnblogs.com/fjicn/p/3405716.html
https://www.cnblogs.com/fang-beny/p/3582653.html

你可能感兴趣的:(线程池)