Jac*_*cob 4 asp.net performance tcp iis-7.5 threadpool
有没有办法检测何时尝试出站连接排队?
我们的ASP.NET应用程序向其他Web服务发出大量的出站请求.最近我们遇到了主要的性能问题,其中对特定端点的调用需要很长时间才能完成或超时.该服务的所有者在他们看来没有看到任何性能问题.当我们分析网络流量时,我们确实看到了HTTP请求确实及时完成.那时我们发现我们漫长的等待时间和超时是由于连接排队造成的.
我们解决此问题的第一种方法是简单地增加到该端点的允许出站连接数,因此:
<system.net>
<connectionManagement>
<add address="http://some.endpoint.com" maxconnection="96" />
</connectionManagement>
</system.net>
Run Code Online (Sandbox Code Playgroud)
这确实使我们对端点的调用大大减少了.但是,我们注意到这导致我们的整体入站请求需要更长时间才能完成.那时我们遇到了Microsoft KB 821268.遵循"经验法则"指南,我们提出了以下额外更改:
<processModel maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>
<httpRuntime minFreeThreads="704" minLocalRequestFreeThreads="608"/>
Run Code Online (Sandbox Code Playgroud)
这似乎解决了一切.我们的呼叫some.endpoint.com仍然很快,我们的响应时间也下降了.
但是,几天后,我们注意到我们的网站性能不佳,我们看到了一些SQL Server超时.我们的DBA没有看到服务器性能有任何不妥,所以这看起来像是类似的事情再次发生; 我们想知道增加的连接some.endpoint.com是否导致其他出站调用队列,可能是由于线程不足.
最糟糕的是,我们还没有找到一种好的技术来明确地知道是否正在进行出站连接排队.我们所能做的就是观察我们提出请求和在申请中收到回复之间的时间.很难知道超时和长响应时间是否是由于特定排队造成的.
是否有任何有效的工具来测量和调整出站请求限制?任何其他性能调优技巧也一定会受到赞赏.
您所描述的问题涉及许多诊断领域,我认为没有一个简单的工具可以让您说出您是否遭受过争用.从您的描述中看起来就像耗尽了连接或线程池.这通常涉及线程锁定.除了HttpWebRequest Average Queue Time@Simon Mourier指出的性能计数器(记得performancecounters="enabled"在你的配置文件中设置),还有更多要监控的.我将开始与自定义性能计数器,将监视线程池的使用在ASP.NET应用程序-遗憾的是他们没有纳入框架柜台,但他们实现如图相当简单的在这里.另外,我编写了一个简单的PowerShell脚本,它将为您的应用程序中的线程状态分组.你可以从这里得到它.它类似于Linux中的顶级命令,它将向您显示进程的线程状态或线程等待原因.看看2个应用程序(都命名为Program.exe)截图:
一个人争论不休
> .\ThreadsTop.ps1 -ThreadStates -ProcMask Program
Threads states / process
Process Name Initialized Ready Running Standby Terminated Waiting Transition Unknown
------------ ----------- ----- ------- ------- ---------- ------- ---------- -------
Program 0 0 0 0 0 22 0 0
Run Code Online (Sandbox Code Playgroud)
并且等待线程的数量不断增长
> .\ThreadsTop.ps1 -ThreadWaitReasons -ProcMask Program
Legend:
0 - Waiting for a component of the Windows NT Executive| 1 - Waiting for a page to be freed
2 - Waiting for a page to be mapped or copied | 3 - Waiting for space to be allocated in the paged or nonpag
ed pool
4 - Waiting for an Execution Delay to be resolved | 5 - Suspended
6 - Waiting for a user request | 7 - Waiting for a component of the Windows NT Executive
8 - Waiting for a page to be freed | 9 - Waiting for a page to be mapped or copied
10 - Waiting for space to be allocated in the paged or nonpaged pool| 11 - Waiting for an Execution Delay to be resolve
d
12 - Suspended | 13 - Waiting for a user request
14 - Waiting for an event pair high | 15 - Waiting for an event pair low
16 - Waiting for an LPC Receive notice | 17 - Waiting for an LPC Reply notice
18 - Waiting for virtual memory to be allocated | 19 - Waiting for a page to be written to disk
Process Name 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
------------ - - - - - - - - - - -- -- -- -- -- -- -- -- -- --
Program 1 0 0 0 0 0 34 0 0 0 0 0 0 0 0 3 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
和其他正常运行:
> .\ThreadsTop.ps1 -ThreadStates -ProcMask Program
Threads states / process
Process Name Initialized Ready Running Standby Terminated Waiting Transition Unknown
------------ ----------- ----- ------- ------- ---------- ------- ---------- -------
Program 0 1 6 0 0 20 0 0
Run Code Online (Sandbox Code Playgroud)
等待线程的数量不会超过24.
> .\ThreadsTop.ps1 -ThreadWaitReasons -ProcMask Program
Legend:
0 - Waiting for a component of the Windows NT Executive| 1 - Waiting for a page to be freed
2 - Waiting for a page to be mapped or copied | 3 - Waiting for space to be allocated in the paged or nonpag
ed pool
4 - Waiting for an Execution Delay to be resolved | 5 - Suspended
6 - Waiting for a user request | 7 - Waiting for a component of the Windows NT Executive
8 - Waiting for a page to be freed | 9 - Waiting for a page to be mapped or copied
10 - Waiting for space to be allocated in the paged or nonpaged pool| 11 - Waiting for an Execution Delay to be resolve
d
12 - Suspended | 13 - Waiting for a user request
14 - Waiting for an event pair high | 15 - Waiting for an event pair low
16 - Waiting for an LPC Receive notice | 17 - Waiting for an LPC Reply notice
18 - Waiting for virtual memory to be allocated | 19 - Waiting for a page to be written to disk
Process Name 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
------------ - - - - - - - - - - -- -- -- -- -- -- -- -- -- --
Program 1 0 0 0 0 0 18 0 0 0 0 0 0 0 0 6 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
当然,在你的情况下,线程的数量会更高,但你应该能够在"平静时间"观察线程行为的一些趋势,并在遇到争用时等待队列峰值.
您可以随意修改我的脚本,以便将此数据转储到除控制台之外的其他位置(如数据库).最后,我建议运行Concurrency Visualizer等分析器,它可以让您更深入地了解应用程序中的线程行为.启用system.net跟踪源也可能有所帮助,尽管事件的数量可能非常大,因此请尝试相应地调整它.