WCF net.tcp Windows 服务 - 呼叫持续时间和未完成的呼叫随着时间的推移而增加

发布于 2024-08-27 10:55:15 字数 2128 浏览 7 评论 0原文

我有一个 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 秒的呼叫持续时间。

关于可能导致我的“未完成通话”和“通话持续时间”激增的任何提示?我哪里漏了?给我指明正确的方向吗?

I have a windows service which uses the ServiceHost class to host a WCF Service using the net.tcp binding. I have done some tweaking to the config to throttle sessions as well as number of connections, but it seems that every once in a while my "Calls outstanding" and "Call duration" shoot up and stay up in perfmon. It seems to me I have a leak somewhere, but the code I have is all fairly minimal, I'm relying on ServiceHost to handle the details.

Here's how I start my service

ServiceHost host = new ServiceHost(type);
host.Faulted+=new EventHandler(Faulted);
host.Open();

My Faulted event just does the following (more or less, logging etc removed)

if (host.State == CommunicationState.Faulted)
{
  host.Abort();
}
else
{
  host.Close();
}
host = new ServiceHost(type);
host.Faulted+=new EventHandler(Faulted);
host.Open();

Here's some snippets from my app.config to show some of the things I've tried

<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" />

There's obviously some resource getting tied up, but I thought I covered everything with my config. I'm only getting about ~150 clients so I don't think I'm coming up against my "300" limit. "Calls per second" stays constant at anywhere from 2-5 calls per second. The service will run for hours and hours with 0-2 "calls outstanding" and very low "call duration" and then eventually it will shoot up to 30 calls oustanding and 20s call duration.

Any tips on what might be causing my "calls outstanding" and "call duration" to spike? Where am I leaking? Point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新一帅帅 2024-09-03 10:55:15

调用服务时您执行的代码可能效率低下。如果没有看到这一点,就很难真正诊断。

It might be some inefficiency in the code you're executing when the service is called. Without seeing that, it's tough to really diagnose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文