Reduce memory usage of .NET services on a single machine
Reduce memory usage of .NET services on a single machine
Use case
You see the memory consumption of multiple services growing and it doesn't decrease over time. After profiling the service you notice the memory of the service is released (there's no memory leak), but the unmanaged memory keeps on growing.
The Solution
When multiple containerized .NET API's are published on one machine, it might be more performant to disable the server garbage collection. This might lead to more CPU usage (in our case this wasn't the case, or it was very minimal), but it will help to reduce the memory usage.
See the docs for more details.
Project.Api.csproj<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>net5.0</TargetFramework><ServerGarbageCollection>false</ServerGarbageCollection></PropertyGroup></Project>
Feel free to update this blog post on GitHub, thanks in advance!
Enjoying the blog?
Support my work
If you enjoyed this post and found it useful, consider supporting my work. It helps me keep creating and sharing content like this. Thank you!