在HttpChannelListener的bufferedWriterPool成员中分配的几个16MB缓冲区(总共218 MB) [英] Several 16MB buffers that stay allocated in HttpChannelListener's bufferedWriterPool member (for a total of 218 MB)

查看:46
本文介绍了在HttpChannelListener的bufferedWriterPool成员中分配的几个16MB缓冲区(总共218 MB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在内存中分析了一个基于WCF的服务,该服务占用了太多内存,并看到HttpChannelListeners的bufferedWriterPool正在保存218 MB内存每个条目占用16MB。




我们使用以下代码配置Http绑定:

 private static BasicHttpBinding GetDefaultBinding(ServiceTransport) transport,ServiceAuthentication authentication)
{
var binding = new BasicHttpBinding();
binding.Name =" EasyFormNxGBinding" ;;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.CloseTimeout = new TimeSpan(0,1,0);
binding.OpenTimeout = new TimeSpan(0,1,0);
binding.ReceiveTimeout = new TimeSpan(0,10,0);
binding.SendTimeout = new TimeSpan(0,1,0);
binding.AllowCookies = false;
binding.BypassProxyOnLocal = false;
// System.ServiceModel.Channels.BufferManager的设置,请参阅解释http://obsessivelycurious.blogspot.be/2008/04/wcf-memory-buffer-management.html
//注意:非常大的请求将通过从堆而不是从缓冲池分配缓冲区来处理(这个内存将在垃圾收集运行中释放)
//在缓冲传输模式下,MaxBufferSize必须等于MaxReceivedMessageSize
binding.MaxBufferSize = 2147483647; // 2 GB(由缓冲区处理的请求的最大大小,将从堆中分配更大的请求)
binding.MaxBufferPoolSize = 10485760; // 10 MB(池缓冲区的总大小 - >缓冲池不会处理更大的请求)
binding.MaxReceivedMessageSize = 2147483647;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.TextEncoding = Encoding.UTF8;
binding.TransferMode = TransferMode.Buffered;
binding.UseDefaultWebProxy = true;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
...
}

代码行是否应该"binding.MaxBufferPoolSize = 10485760;"不限制最大池缓冲区大小为10 MB并从.NET堆分配更大的缓冲区?


注意:我知道将几个参数设置为2 GB不是最佳做法,但这些WCF服务托管在Intranet环境中而不是Internet。


解决方案

您好PDHCoder,


在我看来,这些数据将被写入缓冲池,而不是缓存数据。因为它还没有走出频道。并且参数度量应指向缓冲区管理器实例类。

尝试参考以下官方说明。希望它对您有用。

https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpbinding.maxbufferpoolsize?view=netframework-4.0

https://docs.microsoft.com/en-us/dotnet/ api / system.servicemodel.channels.buffermanager?view = netframework-4.0

最好的问候

亚伯拉罕


Hello,

I was memory profiling a WCF based service that takes up too much memory, and saw that 218 MB of memory is being held by HttpChannelListeners's bufferedWriterPool, in several entries each taking up 16MB.

We are configuring the Http binding using the following code:

        private static BasicHttpBinding GetDefaultBinding(ServiceTransport transport, ServiceAuthentication authentication)
        {
            var binding = new BasicHttpBinding();
            binding.Name = "EasyFormNxGBinding";
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.CloseTimeout = new TimeSpan(0, 1, 0);
            binding.OpenTimeout = new TimeSpan(0, 1, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            binding.SendTimeout = new TimeSpan(0, 1, 0);
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            // settings for the System.ServiceModel.Channels.BufferManager, see explanation http://obsessivelycurious.blogspot.be/2008/04/wcf-memory-buffer-management.html
            // note: very large requests will be handled by allocating a buffer from the heap and not from the buffer pool (this memory will be freed in a garbage collection run) 
            // in buffered transfer mode, the MaxBufferSize MUST be equal to the MaxReceivedMessageSize
            binding.MaxBufferSize = 2147483647;     // 2 GB  (max size of a request that is handled by the buffer, larger requests will be allocated from the heap)
            binding.MaxBufferPoolSize = 10485760;   // 10 MB (total size of the pool buffer --> larger requests will not be handled by the bufferpool)
            binding.MaxReceivedMessageSize = 2147483647;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.TextEncoding = Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;
            binding.ReaderQuotas.MaxDepth = 2147483647;
            binding.ReaderQuotas.MaxStringContentLength = 2147483647;
            binding.ReaderQuotas.MaxArrayLength = 2147483647;
            binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
            binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
...
}

Should the code line "binding.MaxBufferPoolSize = 10485760;" not limit the maximum pool buffer size to 10 MB and allocate larger buffers from the .NET heap?

Note: I know that setting several parameters to 2 GB isn't best practice, but these WCF services are hosted in intranet environments and not internet.

解决方案

Hi PDHCoder,

In my opinion, these data are going to be written to the buffer pool, not cached data. Because it has not yet come out of the channel. And the parameter metric should point to the buffer manager instance class.
Try to refer to the following official explanation. Wish it is useful to you.
https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpbinding.maxbufferpoolsize?view=netframework-4.0
https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.buffermanager?view=netframework-4.0
Best Regards
Abraham


这篇关于在HttpChannelListener的bufferedWriterPool成员中分配的几个16MB缓冲区(总共218 MB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆