加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

检测ASP.NET网站的出站连接排队

发布时间:2020-12-16 06:49:57 所属栏目:asp.Net 来源:网络整理
导读:有没有办法检测何时尝试出站连接排队? 我们的ASP.NET应用程序向其他Web服务发出大量的出站请求.最近我们遇到了主要的性能问题,其中对特定端点的调用需要很长时间才能完成或超时.该服务的所有者未发现任何性能问题.当我们分析网络流量时,我们确实看到了HTTP
有没有办法检测何时尝试出站连接排队?

我们的ASP.NET应用程序向其他Web服务发出大量的出站请求.最近我们遇到了主要的性能问题,其中对特定端点的调用需要很长时间才能完成或超时.该服务的所有者未发现任何性能问题.当我们分析网络流量时,我们确实看到了HTTP请求确实及时完成.那时我们发现我们漫长的等待时间和超时是由于连接排队造成的.

我们解决此问题的第一种方法是简单地增加到该端点的允许出站连接数,因此:

<system.net>
  <connectionManagement>
    <add address="http://some.endpoint.com" maxconnection="96" />
  </connectionManagement>
</system.net>

这确实使我们对端点的调用大大减少了.但是,我们注意到这导致我们的整体入站请求需要更长时间才能完成.那是我们遇到Microsoft KB 821268的时候.遵循“经验法则”指南,我们提出了以下额外更改:

<processModel maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>
<httpRuntime minFreeThreads="704" minLocalRequestFreeThreads="608"/>

这似乎解决了一切.我们对some.endpoint.com的调用仍然很快,我们的响应时间也下降了.

但是,几天后,我们注意到我们的网站性能不佳,我们看到了一些SQL Server超时.我们的DBA没有看到服务器性能有任何不妥,所以这看起来像是类似的事情再次发生;我们想知道增加到some.endpoint.com的连接是否导致其他出站呼叫排队,可能是由于线程不足.

最糟糕的是,我们还没有找到一种好的技术来明确地知道是否正在进行出站连接排队.我们所能做的就是观察我们提出请求和在申请中收到回复之间的时间.很难知道超时和长响应时间是否是由于特定排队造成的.

是否有任何有效的工具来测量和调整出站请求限制?任何其他性能调优技巧也一定会受到赞赏.

解决方法

您所描述的问题涉及许多诊断领域,我认为没有一个简单的工具可以让您说出您是否遭受过争用.从您的描述中看起来就像耗尽了连接或线程池.这通常涉及线程锁定.除了@Simon Mourier指出的HttpWebRequest Average Queue Time性能计数器(记得在 config file中设置performancecounters =“enabled”),还有更多要监控的.我将从自定义性能计数器开始,它将监视ASP.NET应用程序中的线程池使用情况 – 遗憾的是它们不包含在框架计数器中,但它们实现起来非常简单,如 here所示.另外,我写了一个简单的PowerShell脚本,它将分组为你在应用程序中处理状态.您可以从 here获得它.它类似于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

并且等待线程的数量不断增长

> .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

和其他正常运行:

> .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

等待线程的数量不会超过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

当然,在你的情况下线程的数量会更高,但你应该能够在“平静时间”观察线程行为的一些趋势,并在遇到争用时等待队列峰值.

您可以随意修改我的脚本,以便将此数据转储到除控制台之外的其他位置(如数据库).最后,我建议运行诸如Concurrency Visualizer之类的分析器,它可以让您更深入地了解应用程序中的线程行为.启用system.net trace sources也可能有所帮助,尽管事件的数量可能非常大,因此请尝试相应地调整它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读