Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Memory leak on SignalR #3850

Closed
OfirYemini opened this issue Jan 30, 2017 · 10 comments
Closed

Possible Memory leak on SignalR #3850

OfirYemini opened this issue Jan 30, 2017 · 10 comments

Comments

@OfirYemini
Copy link

OfirYemini commented Jan 30, 2017

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:

@OfirYemini OfirYemini changed the title possible Memory leak on SignalR Possible Memory leak on SignalR Jan 30, 2017
@moozzyk
Copy link
Contributor

moozzyk commented Jan 30, 2017

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).

@moozzyk moozzyk closed this as completed Jan 30, 2017
@OfirYemini
Copy link
Author

OfirYemini commented Jan 30, 2017

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.

@OfirYemini
Copy link
Author

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?

@moozzyk
Copy link
Contributor

moozzyk commented Jan 31, 2017

  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.

@OfirYemini
Copy link
Author

OfirYemini commented Feb 11, 2017

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...

@davidfowl
Copy link
Member

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.

@fabercs
Copy link

fabercs commented Jul 27, 2017

@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?

@moozzyk
Copy link
Contributor

moozzyk commented Aug 3, 2017

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

@romanbannikov
Copy link

hi there!

we have the same thing here

image

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

@OfirYemini
Copy link
Author

yes Roman, it helped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants