如何maxmise内存的最大连续块在大对象堆 [英] How to maxmise the largest contiguous block of memory in the Large Object Heap

查看:422
本文介绍了如何maxmise内存的最大连续块在大对象堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的情况是,我想提出一个WCF调用它返回一个XML文档作为一个字符串远程服务器。

The situation is that I am making a WCF call to a remote server which is returns an XML document as a string.

这其中大部分返回值是几K,有时候几十K,很偶然几百K,但很少它可能是几兆字节(第一时间问题是,有没有办法,我就知道了)。

Most of the time this return value is a few K, sometimes a few dozen K, very occasionally a few hundred K, but very rarely it could be several megabytes (first problem is that there is no way for me to know).

这是被造成的悲痛这些罕见的场合。我得到启动堆栈跟踪:

It's these rare occasions that are causing grief. I get a stack trace that starts:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Xml.BufferBuilder.AddBuffer()
   at System.Xml.BufferBuilder.AppendHelper(Char* pSource, Int32 count)
   at System.Xml.BufferBuilder.Append(Char[] value, Int32 start, Int32 count)
   at System.Xml.XmlTextReaderImpl.ParseText()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Xml.XmlReader.ReadElementString()
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMDRQuery.Read2_getMarketDataResponse()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer2.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

我读过周围,这是因为大对象堆是刚开过于分散,所以连电话与一个快速检查,以StringBuilder.EnsureCapacity前刚会导致先前抛出OutOfMemoryException异常(因为我在什么需要猜测,它可能实际上并不需要这么多所以我的检查是造成更多的问题比它解决)。一些意见是没有多少我可以做些什么。

I've read around and it is because the Large Object Heap is just getting too fragmented, so even preceding the call with a quick check to StringBuilder.EnsureCapacity just causes the OutOfMemoryException to be thrown earlier (and because I'm guessing at what's needed, it might not actually need that much so my check is causing more problems than it is solving). Some opinions are that there's not much I can do about it.

一些我问自己的问题:


  • 使用较少的内存? - 你检查泄漏是。内存使用率上升和下降,但有,保证做到这一点没有根本的增长。有些失败的时代,它在这个阶段成功之前。

  • 传输少量不是一种选择,这是一个第三方Web服务在这我管不着(或至少它需要很长的时间来解决,在此期间,我仍然有一个问题)

  • 你能做些什么来蕙,使其不太可能失败? ...现在这是最当然硕果累累。这是一个32位进程(它必须是各种政治,技术和枯燥的原因),但通常有数百兆欧免费(对此我们已经看到了失败的最大金额的倍数)的。

  • 我们可以监视蕙?使用性能监视器,我可以跟踪堆的大小,但我不认为有一种方法来监视最大可用连续的内存块。

  • Use less memory - have you checked for leaks? Yes. The memory usage goes up and down, but there's no fundamental growth that guarantees this to happen. Some of the times it fails, it succeeded at that stage previously.
  • Transfer smaller amounts Not an option, this is a third party web service over which I have no control (or at least it would take a long time to resolve, in the meantime I still have a problem)
  • Can you do something to the LOH to make it less likely to fail? ... now this is most fruitful course. It's a 32-bit process (it has to be for various political, technical and boring reasons) but there's normally hundreds of meg free (multiples of the largest amount for which we've seen failures).
  • Can we monitor the LOH? Using perfmon I can track the size of the heaps, but I don't think there's a way to monitor the largest available contiguous block of memory.

问题是:事情的任何意见或建议试试?

Question is: any advice or suggestions for things to try?

推荐答案

您可以查看 TransferMode 您的结合,看看您是否符合要求把属性它的缓冲它的默认值,以 StreamedResponse

You might review the TransferMode property of your binding to see if you meet the requirements to change it from its default value of "Buffered", to "Streamed" or "StreamedResponse".

此外,审查的 maxBufferPoolSize值 MAXBUFFERSIZE 。增加使用可与内存利用率帮助,尤其是在处理大消息的内部缓冲区的大小。

Also, review the values for maxBufferPoolSize and maxBufferSize. Increasing the size of the internal buffers used can help with memory utilization, especially with processing large messages.

maxReceivedMessageSize 也有可能已经设置,如果你的接收大的消息,但我会审查价值。

maxReceivedMessageSize is also likely already set if your receiving large messages, but I would review that value as well.

我见过上述值之一,如果你超过阈值,失败,一个不起眼的,存储相关的消息。最初的异常实际上是由被浮出水面我的应用程序消息隐藏。启用的 WCF跟踪帮助诊断问题并看到真正的错误 - 我需要增加一个或多个,这个绑定属性的值

I've seen one of the values above, if your exceeding the threshold, fail with an obscure, memory related message. The original exception was actually hidden by the message that was surfaced to my application. Enabling WCF Tracing helped diagnose the problem and see the real error - I needed to increase the value of one, or more, of the binding properties above.

我没有得到的感觉从您的文章您使用绑定,但我相信,这些设置在整个主要的是常见的。查看MSDN文档上 basicHttpBinding的例如

I didn't get the feel for the binding your using from your post, but I believe that these settings are common across major ones. Check out MSDN documentation on basicHttpBinding for example.

如果它是真正的LOH碎片没有任何事情一旦调整工作要做已用尽。滚动应用程序的回收可能需要减少它(我恨,建议),但如果你已经用尽其他方面的努力,你可能会留下的。

If it is truly LOH fragmentation there isn't anything to be done about it once tuning efforts have been exhausted. Rolling recycle of the application might be required to mitigate it (I hate recommending that) but if you've exhausted other efforts you might be left with that.

这篇关于如何maxmise内存的最大连续块在大对象堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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