我有一个 Windows 服务,它使用 ServiceHost 类使用 net.tcp 绑定来托管 WCF 服务。我对配置进行了一些调整以限制会话和连接数,但似乎每隔一段时间我的“未完成呼叫”和“呼叫持续时间”就会上升并保持在 perfmon 中。在我看来,我在某处有泄漏,但我拥有的代码都相当少,我依靠 ServiceHost 来处理细节。
这是我开始服务的方式
ServiceHost host = new ServiceHost(type);
host.Faulted+=new EventHandler(Faulted);
host.Open();
我的错误事件只是执行以下操作(或多或少,删除了日志记录等)
if (host.State == CommunicationState.Faulted)
{
host.Abort();
}
else
{
host.Close();
}
host = new ServiceHost(type);
host.Faulted+=new EventHandler(Faulted);
host.Open();
这是我的 app.config 中的一些片段,以显示我尝试过的一些事情
<runtime>
<gcConcurrent enabled="true" />
<generatePublisherEvidence enabled="false" />
</runtime>
.........
<behaviors>
<serviceBehaviors>
<behavior name="Throttled">
<serviceThrottling
maxConcurrentCalls="300"
maxConcurrentSessions="300"
maxConcurrentInstances="300"
/>
..........
<services>
<service name="MyService" behaviorConfiguration="Throttled">
<endpoint address="net.tcp://localhost:49001/MyService"
binding="netTcpBinding"
bindingConfiguration="Tcp"
contract="IMyService">
</endpoint>
</service>
</services>
..........
<netTcpBinding>
<binding name="Tcp" openTimeout="00:00:10" closeTimeout="00:00:10" portSharingEnabled="true"
receiveTimeout="00:5:00" sendTimeout="00:5:00" hostNameComparisonMode="WeakWildcard"
listenBacklog="1000"
maxConnections="1000">
<reliableSession enabled="false"/>
<security mode="None"/>
</binding>
</netTcpBinding>
..........
<!--for my diagnostics-->
<diagnostics performanceCounters="ServiceOnly" wmiProviderEnabled="true" />
显然有一些资源被占用了,但我认为我的配置涵盖了所有内容。我只获得了大约 150 个客户,所以我认为我不会达到我的“300”限制。“每秒调用次数”在每秒 2-5 次调用之间保持不变。该服务将运行数小时和数小时,其中 0-2 个“未完成呼叫”和非常低的“呼叫持续时间”,然后最终它将达到 30 个未完成呼叫和 20 秒的呼叫持续时间。
关于什么可能导致我的“未完成呼叫”和“呼叫持续时间”飙升的任何提示?我在哪里泄漏?指出我正确的方向?