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

Limit memory pool size #61063

Closed
JanEggers opened this issue Mar 21, 2025 · 4 comments
Closed

Limit memory pool size #61063

JanEggers opened this issue Mar 21, 2025 · 4 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@JanEggers
Copy link
Contributor

Hello we run our app inside a container that is limited to 20 GB. we recently hit this limit so I pulled a dump at 5 GB to see where memory is going.

to me it looks like most of the memory goes to byte arrays allocated by kestrel. is there any way to limit the amount of memory that is allocated / pooled by the shared pool?

Image

Image

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Mar 21, 2025
@martincostello
Copy link
Member

Looks related to (or even a duplicate of) #55490.

@BrennanConroy
Copy link
Member

Yep, duplicate of the issue Martin linked. While we are planning on releasing pooled memory from the pool starting in .NET 10, the real issue is your app is taking on too much load and/or is writing responses inefficiently.

e.g. if you did something like httpContext.Body.WriteAsync(new byte[10_000_000]) that would be much worse than if you wrote it in smaller chunks.

For the too much load part, you would want to look at rate limiting or distributing the load between multiple servers.

@BrennanConroy BrennanConroy added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Mar 21, 2025
@JanEggers
Copy link
Contributor Author

we just return sometimes large json but we never write responses directly that is all handled by asp.net / system.text.json.

unfortunatly we use inmemory state so we have to do a little cleanup before we are able to scale out.

are there any apis I can tap into to figure out which code is allocating the large chunks?

@BrennanConroy
Copy link
Member

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace#dotnet-trace-collect
dotnet trace collect --profile gc-verbose -p <process id>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants