简体   繁体   English

基本HTTP绑定上的SelfHosted WCF服务不支持超过1000个并发请求

[英]A SelfHosted WCF Service over Basic HTTP Binding doesn't support more than 1000 concurrent requests

I have self hosted a WCF Service over BasicHttpBinding consumed by an ASMX Client . 我自己托管了ASMX Client使用的BasicHttpBinding的WCF服务。 I'm simulating a concurrent user load of 1200 users . 我正在模拟1200个用户的并发用户负载。 The service method takes a string parameter and returns a string. service方法接受一个字符串参数并返回一个字符串。 The data exchanged is less than 10KB. 交换的数据少于10KB。 The processing time for a request is fixed at 2 seconds by having a Thread.Sleep(2000) statement. 通过Thread.Sleep(2000)语句将请求的处理时间固定为2秒。 Nothing additional. 没什么别的。 I have removed all the DB Hits / business logic. 我删除了所有数据库命中/业务逻辑。

The same piece of code runs fine for 1000 concurrent users. 同一条代码可以运行1000个并发用户。 I get the following error when I bump up the number to 1200 users. 当我将数字提升到1200个用户时,我收到以下错误。

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at WCF.Throttling.Client.Service.Function2(String param)

This exception is often reported on DataContract mismatch and large data exchange. 此异常通常报告在DataContract不匹配和大数据交换上。 But never when doing a load test. 但从来没有进行负载测试。 I have browsed enough and have tried most of the options which include, 我已经浏览了很多,并尝试了大多数选项,包括,

  1. Enabled Trace & Message log on server side. 在服务器端启用跟踪和消息日志。 But no errors logged. 但没有记录错误。
  2. To overcome Port Exhaustion MaxUserPort is set to 65535, and TcpTimedWaitDelay 30 secs. 要克服端口耗尽,MaxUserPort设置为65535,TcpTimedWaitDelay设置为30秒。
  3. MaxConcurrent Calls is set to 600, and MaxConcurrentInstances is set to 1200. MaxConcurrent Calls设置为600,MaxConcurrentInstances设置为1200。
  4. The Open, Close, Send and Receive Timeouts are set to 10 Minutes. 打开,关闭,发送和接收超时设置为10分钟。
  5. The HTTPWebRequest KeepAlive set to false. HTTPWebRequest KeepAlive设置为false。

I have not been able to nail down the issue for the past two days. 过去两天我一直未能确定这个问题。

Any help would be appreciated. 任何帮助,将不胜感激。

Thank you. 谢谢。

If there are no errors in the service-side WCF logs, I suspect you are hitting some kind of limit in the HTTP.SYS driver layer, leading to requests being turned away before the service application sees them. 如果服务端WCF日志中没有错误,我怀疑您在HTTP.SYS驱动程序层中遇到某种限制,导致请求在服务应用程序看到之前被拒绝。 I think the default limit in the request queue for a particular application may be 1000. 我认为特定应用程序的请求队列中的默认限制可能是1000。

I'm no expert on HTTP.SYS but you may get some insight by running: 我不是HTTP.SYS的专家,但你可以通过运行获得一些见解:

netsh http show servicestate

I have seen similar problems on different servers, depending on their CPUs and RAM. 我在不同的服务器上看到了类似的问题,具体取决于它们的CPU和RAM。 You did not mention the server type, how it was upgraded (XP Pro or Server 2003 upgraded to Server 2008), etc. The way I had resolved the issue was through checking the x:\\Windows\\Microsoft.NET\\Framework[version]\\config\\machine.config. 您没有提到服务器类型,它是如何升级的(XP Pro或Server 2003升级到Server 2008)等。我解决问题的方法是通过检查x:\\ Windows \\ Microsoft.NET \\ Framework [版本] \\ CONFIG \\ machine.config中。 Apparently selecting "unlimited" connection through IIS does not mean "unlimited" connections. 显然通过IIS选择“无限制”连接并不意味着“无限制”连接。 The number of connections I ran into errored out after 11 requests at the exact same millisecond. 我遇到的连接数在完全相同的毫秒之后的11个请求之后出错了。

The issue was related to the number of connections coming from the same source. 该问题与来自同一来源的连接数有关。 The performance benchmark tool resided on the same PC which has the same IP. 性能基准测试工具位于具有相同IP的同一台PC上。 The machine.config contains a constraint on the number of connections from the same source. machine.config包含对来自同一源的连接数的约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM