Signalr: Possible Memory leak on SignalR

Created on 30 Jan 2017  ·  10Comments  ·  Source: SignalR/SignalR

Hi all,

Issue could be related to #3589
We have a signalR version 2.2.0 hosted as a window service, the service is pushing trading rates on a high frequency intervals to a hundreds of browser clients. So we have a lot of connections come and go. after a while, the service starts to leak.
I've captured the dump and compared it to base dump that was taken a few minutes after the service was started. below are the results:

capture

As you can see, SignalR classes are at the top.

link to the second dump is here:

Most helpful comment

But I think you guys seriously needs to consider this as a design issue...

Definitely something we're addressing with SignalR for ASP.NET Core.

All 10 comments

SignalR has a per-connection ring buffer where it stores messages. This default size of the buffer is 1000 messages (per connection). What you are probably seeing is that buffers are filling up and messages will be freed up (actually be replaced by new messages) once the buffers are full. You can configure the size of the buffer using IConfigurationManager.DefaultMessageBufferSize configuration property. The minimum size of the buffer is 32 (enforced by SignalR). Note that decreasing the size of the buffer increases the likelihood of missing messages (e.g. during reconnects).

thanks mate, I've read about that ring buffer, I would try to decrease the buffer size to the minimum allowed by SignalR (32) as I have no need of this buffer, my client keeps track of all his current subscriptions, if a reconnect occurs it subscribes again to the relevant groups & events.

I do have a few questions regarding the ring buffer:

  1. if client X register to group A, a new ring buffer of 1000 messages is allocated to the A group, when this client is disconnected, do you guys release that ring buffer? (assuming no other clients subscribed to that A group)
  2. if a connection stays active for a long period of time, let's say a few hours. is it fair to assume that all 1000 messages that exists on the buffer will move up the chain to Gen2 by the GC?

1) There is a background thread that is deleting unused topics (which contains the ring buffer) - https://github.com/SignalR/SignalR/blob/dev/src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBus.cs#L324
2) I guess it depends on the rate the messages are being sent but I would say it is likely that many of these messages will be promoted to Gen 2.

Thanks for your answers moozzyk!

After a week on Production with the new configuration I can confirm we have no more memory leakage.

But I think you guys seriously needs to consider this as a design issue...

But I think you guys seriously needs to consider this as a design issue...

Definitely something we're addressing with SignalR for ASP.NET Core.

@moozzyk @OfirYemini What was your configuration on server hub? Is there anything out of changing GlobalHost.Configuration.DefaultMessageBufferSize to 32 ? If there is, is it possible give insight by sharing some code?

Changing the DefaultMessageBufferSize is the only thing required to make the buffers smaller.

hi there!

we have the same thing here

image

so the question is DefaultMessageBufferSize = 32 will help us in this case?

yes Roman, it helped

Was this page helpful?
0 / 5 - 0 ratings