草庐IT

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

coder 2023-09-17 原文

有什么方法可以检测尝试的出站连接何时排队?

我们的 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 中的 bit top 命令,将向您显示进程的线程状态或线程等待原因。查看 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也可能有帮助,尽管事件的数量可能是压倒性的,因此请尝试相应地调整它。

关于asp.net - 检测 ASP.NET 网站的出站连接排队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22186739/

有关asp.net - 检测 ASP.NET 网站的出站连接排队的更多相关文章

  1. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  2. ruby - 如何模拟 Net::HTTP::Post? - 2

    是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou

  3. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  4. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  5. ruby - 无法在 60 秒内获得稳定的 Firefox 连接 (127.0.0.1 :7055) - 2

    我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类

  6. ruby - Ping ruby 网站? - 2

    在Ruby中可以使用哪些替代方法来ping一个ip地址?标准库“ping”库的功能似乎非常有限。我对在这里滚动我自己的代码不感兴趣。有没有好的gem?我应该接受它并忍受它吗?(我在Linux上使用Ruby1.8.6编写代码) 最佳答案 net-ping值得一看。它允许TCPping(如标准ruby​​ping),但也允许UDP、HTTP和ICMPping。ICMPping需要root权限,但其他则不需要。 关于ruby-Pingruby网站?,我们在StackOverflow上找到一个类

  7. ruby - Net::HTTP 获取源代码和状态 - 2

    我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur

  8. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  9. .net - .NET 将如何影响 Python 和 Ruby 应用程序? - 2

    我很好奇.NET将如何影响Python和Ruby应用程序。用IronPython/IronRuby编写的应用程序是否会非常特定于.NET环境,以至于它们实际上将变得特定于平台?如果他们不使用任何.NET功能,那么IronPython/IronRuby相对于非.NET同类产品的优势是什么? 最佳答案 我不能说任何关于IronRuby的东西,但是大多数Python实现(如IronPython、Jython和PyPy)都试图尽可能忠实于CPython实现。不过,IronPython正在迅速成为这方面的佼佼者之一,并且在PlanetPyth

  10. ruby - 我的 Ruby IRC 机器人没有连接到 IRC 服务器。我究竟做错了什么? - 2

    require"socket"server="irc.rizon.net"port="6667"nick="RubyIRCBot"channel="#0x40"s=TCPSocket.open(server,port)s.print("USERTesting",0)s.print("NICK#{nick}",0)s.print("JOIN#{channel}",0)这个IRC机器人没有连接到IRC服务器,我做错了什么? 最佳答案 失败并显示此消息::irc.shakeababy.net461*USER:Notenoughparame

随机推荐