C# 请求通道在等待回复时超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11215513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The request channel timed out while waiting for a reply
提问by Kasper Wittrup
I have a small application that uses WCF to communicate with a webserver. This program is used by some 200 clients, and each client is sending in about 5-20 requests/min.
我有一个使用 WCF 与网络服务器通信的小应用程序。这个程序被大约 200 个客户端使用,每个客户端以大约 5-20 个请求/分钟的速度发送。
Looking at the error logs I often get:
查看我经常得到的错误日志:
The request channel timed out while waiting for a reply after 00:00:59.9989999
请求通道在 00:00:59.9989999 之后等待回复时超时
The requests are made as follows:
请求如下:
ClientService Client = new ClientService();
Client.Open();
Client.updateOnline(userID);
Client.Close();
This is the app.config
这是 app.config
<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v2.0.50727"/></startup><system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IClientService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="PATH TO SERVICE"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClientService"
contract="IClientService" name="WSHttpBinding_IClientService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Of the "many calls" each day about 200-800 fail. And about n-1 are ok. I am very confused what the issue can be. Looking at the server stats, it's hardly building up a sweat - each request takes <2 sec to process. The data it's sending consists of "int" or "very small strings" - so, its not due to size, if it were - there should be a consistent failure..
在每天的“许多电话”中,大约有 200-800 次失败。大约 n-1 没问题。我很困惑是什么问题。查看服务器统计信息,几乎不会出汗 - 每个请求需要 <2 秒来处理。它发送的数据由“int”或“非常小的字符串”组成——所以,它不是由于大小,如果是——应该有一个一致的失败..
Suggestions?
建议?
采纳答案by Tabish Sarwar
It seems that your requests are queuing up on server before being handled and then starts to time out. You can try couple of things here to see exactly whats going on
似乎您的请求在处理之前在服务器上排队,然后开始超时。你可以在这里尝试几件事,看看到底发生了什么
1) Try throttling in your WCF services e.g: Try increasing your concurrent sessions. Take a look WCF Throttling
1) 尝试在 WCF 服务中进行节流,例如:尝试增加并发会话。看看 WCF 节流
2) Try using PerCall rather than Using Sessions here to make sure that no session remains there. Here is what you can do on your interface to remove session
2) 尝试在此处使用 PerCall 而不是 Using Sessions 以确保没有会话保留在那里。这是您可以在界面上执行的操作以删除会话
[ServiceContract(Namespace="YOUR NAMESPACE", SessionMode=SessionMode.NotAllowed)]
and your contract classes implementing those interface
以及实现这些接口的合约类
ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
AND .... You should enable tracing to see exactly whats going on .
并且....您应该启用跟踪以准确了解发生了什么。
回答by Dmitry Harnitski
Check this performance counter - ASP.NET Requests Queued.
检查这个性能计数器 - ASP.NET Requests Queued。
One web application can host many web pages and services. IIS processes only 12 concurrent requests per CPU core by default.
一个 Web 应用程序可以托管多个网页和服务。默认情况下,IIS 每个 CPU 内核仅处理 12 个并发请求。
This means that even if your service is fast but other pages/services are slow your request has to wait in queue before they are executed.
这意味着即使您的服务很快但其他页面/服务很慢,您的请求在执行之前也必须在队列中等待。
ASP.NET Requests Queuedshould be zero or close to zero.
ASP.NET Requests Queued应为零或接近于零。
回答by NTDLS
Try adding the timeout values to both the service AND the client:
尝试将超时值添加到服务和客户端:
<binding name="BasicHttpBinding_SomeName" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

