gpt4 book ai didi

wcf - 我的 ServiceHost 中的内存和处理泄漏

转载 作者:行者123 更新时间:2023-12-04 23:53:05 27 4
gpt4 key购买 nike

我在服务应用程序中有一个 ServiceHost,它每 60 秒与 1700 个客户端通信。当我启动该服务时,它几乎立即攀升到大约 1500 个打开的句柄,然后在大约 5 分钟后继续增加另外 300 个(此后继续继续。)

我查看了 ProcessExplorer,在 Split View中,它显示了数百个名为“Device\Afd”的文件类型的句柄 - 这是用于通信的 TCP 套接字的代表(我相信)。

我只是假设我的句柄泄漏与 ServiceHost 有关,因为它代表了从 Process Explorer 观察到的最大句柄数。我想知道的是为什么服务不关闭这些?我是否需要设置某种超时或我是否需要在某个地方主动关闭它们?

这是我的 ServiceHost 的创建方式:

wcfObject = new WcfObject();
host = new ServiceHost(wcfObject, baseWcfAddress);

ServiceBehaviorAttribute attribute = (ServiceBehaviorAttribute)host.Description.Behaviors[typeof(ServiceBehaviorAttribute)];
attribute.ConcurrencyMode = ConcurrencyMode.Multiple;
attribute.InstanceContextMode = InstanceContextMode.Single;

在我的 app.config 中:

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfObject" behaviorConfiguration="DefaultBehavior">
<host>
<baseAddresses >
<!-- Defined in code -->
</baseAddresses>
</host>
<endpoint name="NetTcpEndPoint" address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="IWcfObject"/>
<endpoint name="NetTcpMetadataPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding" maxReceivedMessageSize="9655360" maxBufferSize="9655360" maxBufferPoolSize="524288">
<readerQuotas maxArrayLength = "932000" maxStringContentLength="900000" maxDepth="32"/>
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior" >
<serviceMetadata httpGetEnabled="False" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="True"/>
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="100" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

最佳答案

我认为您的具体问题描述为here .

When the channel is created and the operation context exists, then each new channel instance is appended in the list of WmiChannels (see property InstanceContext.WmiChannels in code below). This list causes the leak. However if the InstanceContext is recreated on each invoke of operation (that is when InstanceContextMode is set on PerCall), the list will be recreated and no leak will be caused.

有关解决方法,请参阅同一篇文章。请将您的发现告知我们。

关于wcf - 我的 ServiceHost 中的内存和处理泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7613752/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com