WCF 单向回调超时?
这怎么可能?我认为呼叫的一种方式是“一劳永逸”。该方法被标记为单向。回调并发模式设置为 Multiple,回调类的 UseSychronizationContext 设置为 false。发送的数据不超过 1KB,但每次我同时发送大约 30-40 个小消息时,调用开始阻塞,最终其中一些超时。我对客户端->服务器调用进行了基准测试,速度约为 16000/秒。当我尝试回拨给客户端时,我每秒只能召集大约 2 个,而且这是在 OneWay 呼叫上!
我的服务器绑定配置如下所示:
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="netNamedPipeBinding1" receiveTimeout="23:00:00" maxReceivedMessageSize="1048576" maxBufferPoolSize="1048576" maxConnections="500">
<readerQuotas maxStringContentLength="99999999" maxArrayLength="9999999" maxBytesPerRead="999999"/>
<security mode="None"/>
</binding>
</netNamedPipeBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="highThroughPut">
<serviceThrottling maxConcurrentCalls="3000" maxConcurrentInstances="3000" maxConcurrentSessions="3000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="OLII.Apps.Services.Data.DataServices.DataService" behaviorConfiguration="highThroughPut">
<endpoint bindingConfiguration="netNamedPipeBinding1" address="net.pipe://localhost/DataListener" binding="netNamedPipeBinding" contract="OLLI.Apps.Services.ProxyClients.DataServerProxyClient.IDataListenerService"/>
</service>
</services>
</system.serviceModel>
我的回调合约如下所示:
public interface IDataCallbackClient
{
[OperationContract(IsOneWay = true)]
void GetData(string file, int id);
}
我的客户端回调类如下所示:
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class DataCallback : IDataCallbackClient
{
public void GetData(string file, int id)
{
//If I put Thread.Sleep(5000); When the server calls this method, the first few go through, and subsequent calls block. If I do a return statement here, all the calls go through really fast on the server side.
//Does some processing with file and id. It then goes back to server with data.
}
}
How is this possible? I thought one way calls were fire and forget. The method is marked as one-way. The callback concurrency mode is set to Multiple and the UseSychronizationContext of the callback class is set to false. The data being sent is not more than 1KB yet every time I send about 30-40 small messages concurrently, the calls start to block and eventually some of them timeout. I've benchmarked my client->server calls at about 16000/sec. When I try to call back to client, I can only muster about 2 per second, and this on a OneWay call!
My binding configuration for the server looks like so:
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="netNamedPipeBinding1" receiveTimeout="23:00:00" maxReceivedMessageSize="1048576" maxBufferPoolSize="1048576" maxConnections="500">
<readerQuotas maxStringContentLength="99999999" maxArrayLength="9999999" maxBytesPerRead="999999"/>
<security mode="None"/>
</binding>
</netNamedPipeBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="highThroughPut">
<serviceThrottling maxConcurrentCalls="3000" maxConcurrentInstances="3000" maxConcurrentSessions="3000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="OLII.Apps.Services.Data.DataServices.DataService" behaviorConfiguration="highThroughPut">
<endpoint bindingConfiguration="netNamedPipeBinding1" address="net.pipe://localhost/DataListener" binding="netNamedPipeBinding" contract="OLLI.Apps.Services.ProxyClients.DataServerProxyClient.IDataListenerService"/>
</service>
</services>
</system.serviceModel>
My callback contract looks like so:
public interface IDataCallbackClient
{
[OperationContract(IsOneWay = true)]
void GetData(string file, int id);
}
My client callback class looks like so:
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class DataCallback : IDataCallbackClient
{
public void GetData(string file, int id)
{
//If I put Thread.Sleep(5000); When the server calls this method, the first few go through, and subsequent calls block. If I do a return statement here, all the calls go through really fast on the server side.
//Does some processing with file and id. It then goes back to server with data.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。我对我的服务的调用在进程中阻塞并导致线程池饥饿。我还从 wcf 服务内部调用线程池,这是一种不好的做法,因为这些方法是在线程池本身上调用的。看起来当您进行单向调用并且线程池匮乏时,单向调用将超时,因为它没有可以执行的线程。
谢谢
I figured it out. I had calls to my service that were blocking and starving the thread pool in the process. I was also invoking calls on the thread pool from inside my wcf service, which is a bad practice since those methods are invoked on the thread pool themselves. Looks like when you make a one way call, and the thread pool is starved, the one way call will timeout since it doesn't have a thread to execute on.
Thanks