什么限制了我的 ASP.NET 应用程序可以与 Web 服务建立的并发连接数? [英] What is limiting the # of simultaneous connections my ASP.NET application can make to a web service?

查看:12
本文介绍了什么限制了我的 ASP.NET 应用程序可以与 Web 服务建立的并发连接数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET 4.0 应用程序,它在 64 位 Windows Server 2008 R2 Enterprise 机器上的 IIS 7.5 上运行,带有大量 RAM、CPU、磁盘等.

对于每个 Web 请求,ASP.NET 应用程序都会连接到在同一台机器上运行的后端 Web 服务(通过原始套接字).

问题: 似乎限制了与后端 Web 服务的同时连接数.令人怀疑的是,并发连接数达到了 16 个.

我发现这篇来自 Microsoft 的重要文章解释了如何调整 IIS 的设置以适应发出大量 Web 服务请求的 ASP.NET 应用程序:http://support.microsoft.com/?id=821268#tocHeadRef

我遵循了文章的推荐,但仍然没有运气.特别有趣的设置是 maxconnection 设置,我什至碰到了 999.

任何想法其他可能会限制连接?

注意:当我将 IIS 排除在外并让客户端直接连接到后端 Web 服务时,它会很乐意打开我需要的任意数量的连接,所以我很肯定后端不是瓶颈.它必须是 IIS/ASP.NET-land 中的东西.

这是machine.config 的相关部分,我确定应用程序正在读取它(使用appcmd.exe 验证):

<processModel autoConfig="false" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/><httpRuntime minFreeThreads="176" minLocalRequestFreeThreads="152"/><httpHandlers/><会员资格><提供者><add name="AspNetSqlMembershipProvider"type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"connectionStringName="LocalSqlServer"enablePasswordRetrieval="false"enablePasswordReset="true"requiresQuestionAndAnswer="true"应用名称=/"requiresUniqueEmail="false"密码格式=哈希"maxInvalidPasswordAttempts="5"minRequiredPasswordLength="7"minRequiredNonalphanumericCharacters="1"passwordAttemptWindow="10"passwordStrengthRegularExpression=""/></提供者></会员资格><个人资料><提供者><add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/"type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></提供者></个人资料><角色管理器><提供者><add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/"type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add name="AspNetWindowsTokenRoleProvider" applicationName="/"type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></提供者></roleManager></system.web><system.net><连接管理><add address="*" maxconnection="999"/></连接管理></system.net>

解决方案

此处提供的大多数答案都针对传入请求到后端网络服务的数量,而不是传出请求的数量 你可以从你的 ASP.net 应用程序到你的后端服务.

在这里限制您的请求率的不是您的后端网络服务,而是您的调用应用程序愿意建立到同一端点(同一 URL)的打开连接数.

您可以通过将以下配置部分添加到您的 machine.config 文件来消除此限制:

<预><代码><配置><system.net><连接管理><add address="*" maxconnection="65535"/></连接管理></system.net></配置>

如果您想要 50 或 100 个并发连接,您当然可以选择更合理的数字.但以上将打开它最大.您还可以为上面的开放限制规则指定一个特定的地址,而不是表示所有地址的*".

System.Net.connectionManagement 的 MSDN 文档

了解 .NET 中的 ConnectManagement 的另一个重要资源

希望这能解决您的问题!

糟糕,我确实看到您在上面的代码中提到了连接管理.我会留下我的上述信息,因为它与未来遇到同样问题的询问者有关.但是,请注意目前在大多数最新服务器上有 4 个不同的 machine.config 文件!

.NET Framework v2 可以在 32 位和 64 位下运行,.NET Framework v4 也可以在 32 位和 64 位下运行.根据您为应用程序池选择的设置,您可以使用这 4 个不同的 machine.config 文件中的任何一个!请检查通常位于此处的所有 4 个 machine.config 文件:

  • C:WindowsMicrosoft.NETFrameworkv2.0.50727CONFIG
  • C:WindowsMicrosoft.NETFramework64v2.0.50727CONFIG
  • C:WindowsMicrosoft.NETFrameworkv4.0.30319Config
  • C:WindowsMicrosoft.NETFramework64v4.0.30319Config

I have an ASP.NET 4.0 application running atop IIS 7.5 on a 64-bit Windows Server 2008 R2 Enterprise machine with gobs of RAM, CPU, disk, etc.

With every web request, the ASP.NET application makes a connection to a backend web service (via raw sockets), which is running on the same machine.

Problem: There appears to be something limiting the # of simultaneous connections to the backend web service. Suspiciously, the number of concurrent connections is topping out at 16.

I found this key article from Microsoft explaining how to tweak IIS' settings to accomodate ASP.NET apps that make lots of web service requests: http://support.microsoft.com/?id=821268#tocHeadRef

I followed the article's recommendatinos, but still no luck. The setting that is particularly interesting is the maxconnection setting, which I even bumped to 999.

Any ideas what else could be throttling connections?

Note: When I cut IIS out of the mix and have the clients connect directly to the backend web service, it will happily open as many connections as I need, so I'm positive the backend is not the bottleneck. It must be something in IIS/ASP.NET-land.

Here's the relevant section of the machine.config which I'm sure is being read by the application (verified with appcmd.exe):

<system.web>
    <processModel autoConfig="false" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" />
    <httpRuntime minFreeThreads="176" minLocalRequestFreeThreads="152"/>

    <httpHandlers />

    <membership>
        <providers>
            <add name="AspNetSqlMembershipProvider"
                type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                connectionStringName="LocalSqlServer"
                enablePasswordRetrieval="false"
                enablePasswordReset="true"
                requiresQuestionAndAnswer="true"
                applicationName="/"
                requiresUniqueEmail="false"
                passwordFormat="Hashed"
                maxInvalidPasswordAttempts="5"
                minRequiredPasswordLength="7"
                minRequiredNonalphanumericCharacters="1"
                passwordAttemptWindow="10"
                passwordStrengthRegularExpression="" />
        </providers>
    </membership>

    <profile>
        <providers>
            <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/"
                type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
    </profile>

    <roleManager>
        <providers>
            <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/"
                type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add name="AspNetWindowsTokenRoleProvider" applicationName="/"
                type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
    </roleManager>
</system.web>
<system.net>
    <connectionManagement>
        <add address="*" maxconnection="999"/>
    </connectionManagement>
</system.net>

解决方案

Most of the answers provided here address the number of incoming requests to your backend webservice, not the number of outgoing requests you can make from your ASP.net application to your backend service.

It's not your backend webservice that is throttling your request rate here, it is the number of open connections your calling application is willing to establish to the same endpoint (same URL).

You can remove this limitation by adding the following configuration section to your machine.config file:

<configuration>
  <system.net>
    <connectionManagement>
      <add address="*" maxconnection="65535"/>
    </connectionManagement>
  </system.net>
</configuration>

You could of course pick a more reasonable number if you'd like such as 50 or 100 concurrent connections. But the above will open it right up to max. You can also specify a specific address for the open limit rule above rather than the '*' which indicates all addresses.

MSDN Documentation for System.Net.connectionManagement

Another Great Resource for understanding ConnectManagement in .NET

Hope this solves your problem!

EDIT: Oops, I do see you have the connection management mentioned in your code above. I will leave my above info as it is relevant for future enquirers with the same problem. However, please note there are currently 4 different machine.config files on most up to date servers!

There is .NET Framework v2 running under both 32-bit and 64-bit as well as .NET Framework v4 also running under both 32-bit and 64-bit. Depending on your chosen settings for your application pool you could be using any one of these 4 different machine.config files! Please check all 4 machine.config files typically located here:

  • C:WindowsMicrosoft.NETFrameworkv2.0.50727CONFIG
  • C:WindowsMicrosoft.NETFramework64v2.0.50727CONFIG
  • C:WindowsMicrosoft.NETFrameworkv4.0.30319Config
  • C:WindowsMicrosoft.NETFramework64v4.0.30319Config

这篇关于什么限制了我的 ASP.NET 应用程序可以与 Web 服务建立的并发连接数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆