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

Kestrel memory pool does not reliably decrease with load #24958

Closed
GREsau opened this issue Aug 17, 2020 · 6 comments
Closed

Kestrel memory pool does not reliably decrease with load #24958

GREsau opened this issue Aug 17, 2020 · 6 comments
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel severity-nice-to-have This label is used by an internal tool

Comments

@GREsau
Copy link

GREsau commented Aug 17, 2020

Describe the bug

While load testing a new service using SignalR, we noticed that memory usage does not always decrease after connections drop off. Sometimes it decreases a minute or two after the connections end, but sometimes it just never recovers. This causes us two problems:

  1. When an instance nears its memory limit, it will reject new connections (achieved using custom middleware that responds with a 503) in order to protect its existing connections. But since memory usage does not decrease, the instance will never accept new connections, even after most of its existing connections end
  2. Our service autoscales on memory, but because memory usage stays high our service will rarely scale-down when under low load. This is less of a problem, it just costs a bit to run with extra capacity

This shows memory usage increasing with number of connections (tracked using the OnConnectedAsync/OnDisconnectedAsync methods of our Hub), but not reliably decreasing afterwards:

image

The service is running in an Alpine 3.12 docker container, but we notice similar behaviour when running locally in Windows 10. We initially assumed this was a simple memory leak, but when making a large number of connections over time while keeping the number of concurrent connections low, memory usage does not increase.

When taking a heap dump, we see memory fairly dominated by Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets!Buffers.MemoryPoolBlock:

image

To Reproduce

  1. Make a large number of concurrent connections to a SignalR Core service
  2. End connections
  3. Monitor memory - it should decrease, but usually does not

Further technical details

  • ASP.NET Core version 3.1.6, using docker image based on mcr.microsoft.com/dotnet/core/aspnet:3.1.6-alpine3.12
  • Built with SDK 3.1.302, using docker image based on mcr.microsoft.com/dotnet/core/sdk:3.1.302-alpine3.12
  • Reproduced locally on Windows 10 using ASP.NET Core 3.1.6, SDK 3.1.202
@javiercn javiercn added the area-signalr Includes: SignalR clients and servers label Aug 17, 2020
@BrennanConroy BrennanConroy added area-servers and removed area-signalr Includes: SignalR clients and servers labels Aug 17, 2020
@BrennanConroy
Copy link
Member

Kestrel will pool internal buffer up to a limit and will not let them go. We should consider having a settable limit or release strategy for the pool.

cc @halter73

@BrennanConroy BrennanConroy added this to the Backlog milestone Aug 17, 2020
@ghost
Copy link

ghost commented Aug 17, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@halter73
Copy link
Member

@jkotalik jkotalik added affected-very-few This issue impacts very few customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-nice-to-have This label is used by an internal tool labels Nov 13, 2020 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Dec 11, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@BrennanConroy BrennanConroy changed the title SignalR Core memory does not reliably decrease with load Kestrel memory pool does not reliably decrease with load Feb 10, 2021
@ghost
Copy link

ghost commented Feb 10, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@adityamandaleeka
Copy link
Member

Closing this as a duplicate of #27394

@ghost ghost locked as resolved and limited conversation to collaborators Mar 17, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel severity-nice-to-have This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

9 participants