Search code examples
wcfmemory-leaks.net-4.8

High consumption of memory in WCF and .NET Framework 4.8


I'm struggling with problem of memory consumption I used a dotMemory and result looks like on the first screen.

Memory consumption

The most amount of memory take System, Castle (3.3.0) and NHibernate (v. 4.1.0) When I expand information about system I see that the problem is with String, Collection. In Castle is Default Kernel has the biggest memory and LifecycledComponentsReleasePolicy. I'm looking solution for Castle but I don't know how to resolve issue with System and NHiberante Do you have any expirenced and anyone could give me some tips because I see that GC work

memory chart

Currently I'm looking any solutions and testing my ideas what I found at Google


Solution

  • Generally speaking, the way to control resources in WCF is through quotas and controllers.

    First of all, you can set a timeout, which can save a lot of resources. For example:

    ChannelInitializationTimeout : The maximum amount of time to wait for the connection to send a preamble during the initial read.

    CloseTimeout : The maximum amount of time to wait for a connection to close before a transfer throws an exception.

    IdleTimeout : The maximum amount of time that a pooled connection can remain idle before being shut down.

    LeaseTimeout : The maximum lifetime of an active connection that has been pooled. After the specified time has elapsed, the connection is closed as soon as the current request is served.

    OpenTimeout : The maximum amount of time to wait for a connection to be established before a transfer throws an exception.

    ReceiveTimeout : The maximum amount of time to wait for a read operation to complete before the transfer throws an exception.

    SendTimeout : The maximum amount of time to wait for a write operation to complete before a transfer throws an exception.

    Secondly, you can also limit the transfer size:

    ConnectionBufferSize : The size of the transmit and receive buffers (in bytes) of the underlying transmission. Increasing the buffer size can increase throughput when sending larger messages.

    ListenBacklog : The maximum number of connections that a listener can have that haven't been serviced before other connections to that endpoint are denied.

    MaxBufferPoolSize : The maximum memory, in bytes, used to form a pool of reusable message buffers is transferred. When the pool is unable to provide a message buffer, the system allocates a new buffer for temporary use.

    MaxBufferSize : The maximum size (in bytes) of the buffer used to stream the data.

    MaxOutboundConnectionsPerEndpoint : The maximum number of outgoing connections that can be associated with a specific endpoint.

    MaxReceivedMessageSize : The maximum size (in bytes) of the received message, including the header; Beyond this size, the transfer will throw an exception.

    As for the controller, ServiceThrottle.MaxConcurrentSessions is an application-level controller that limits the number of concurrent session channel connections to no more than 10 by default. These controls are designed to provide out-of-the-box mitigation against certain types of attacks, or to improve performance metrics such as memory requirements, boot time, and more.