简体   繁体   English

缓冲时来自服务器的WCF InsufficientMemoryException

[英]WCF InsufficientMemoryException from Server while buffering

I am getting this error on my server. 我在服务器上收到此错误。

System.InsufficientMemoryException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.InsufficientMemoryException,mscorlib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089

Failed to allocate a managed memory buffer of 536870912 bytes. 无法分配536870912字节的托管内存缓冲区。 The amount of available memory may be low. 可用内存量可能不足。

This happens after the last statement return myCollection . 这发生在最后一条语句返回myCollection之后 when myCollection is around 45k items. 当myCollection大约有4.5万个项目时。

Server Config: 服务器配置:

<binding name="LargeTCPBinding"
         closeTimeout="00:30:00"
         openTimeout="00:30:00"
         receiveTimeout="01:00:00"
         sendTimeout="01:00:00"
         hostNameComparisonMode="StrongWildcard"
         maxBufferPoolSize="2147483647"
         maxReceivedMessageSize="2147483647"
         maxBufferSize="2147483647">
  <readerQuotas maxDepth="2147483647"
                maxStringContentLength="2147483647"
                maxArrayLength="2147483647"
                maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647" />
  <security mode="Transport">
    <transport clientCredentialType="Windows" />
  </security>
</binding>

i did some basic memory profiling GC.GetTotalMemory(false) and the difference after getting my collection into memory is about 170 MB. 我做了一些基本的内存分析GC.GetTotalMemory(false) ,将我的收藏集放入内存后的区别约为170 MB。

The exception happens after returning the collection (so it appears to happen during buffering for send). 返回集合后会发生异常(因此似乎在缓冲发送时发生)。

If i switch my wcf connection config to Streamed , this fixes the exception, but the call goes from 25 seconds to 1:05 minutes. 如果我将wcf连接配置切换为Streamed ,则可以解决此异常,但是通话时间从25秒变为1:05分钟。

Just trying to understand what is happening here because that collection is not that big. 只是想了解这里发生了什么,因为该集合没有那么大。 This is running on WCF 4.0, 64bit cpu. 它在WCF 4.0(64位cpu)上运行。

What's important here is not the SIZE of the collection but the COMPLEXITY of the object graph. 这里重要的不是集合的大小,而是对象图的复杂度。 If your collection contains a reference type with many fields and/or properties, this is a more complex/deeper graph. 如果您的集合包含具有许多字段和/或属性的引用类型,则此图更为复杂/深入。

Before WCF can send a response to you, it must serialize the object graph into binary, send it over the wire, and the client deserializes it. 在WCF可以向您发送响应之前,它必须将对象图序列化为二进制,通过有线发送,然后客户端将其反序列化。

Buffered means the collection is serialized to a structure in memory, and then sent as one big chunk. 缓冲意味着将集合序列化为内存中的结构,然后作为一个大块发送。 Streamed means that the collection is sent as it is serialized. 流式表示收集是在序列化时发送的。

Your object may not be large, but the serialized representation of it may be quite massive, simply due to the SOAP envelope created for your data and the XML representation, etc. 您的对象可能不会很大,但是它的序列化表示可能会非常庞大​​,这仅仅是由于为您的数据创建了SOAP信封和XML表示等。

This is why Streamed solves your issue: buffered cannot represent the entire object graph in serialized form in memory at one time. 这就是为什么Streamed解决您的问题的原因:“缓冲”一次无法在内存中以序列化形式表示整个对象图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM