I am writing .NET Core application (Blazor), which is hosted in Webhosting under IIS. I cannot control IIS settings (it is under control of provider) and I have Application Pool limited to 500 MBs. Once my application reaches 500 MBs, the application pool is restarted ( and my app is restarted as well ).
This is causing disconnection to all currently connected clients.
I am trying to set up the application to run Garbage collection in order to stay under 500 MBs, but I am not sure if it is best approach.
I have created file runtimeconfig.json:
{
"runtimeOptions": {
"configProperties": {
"System.GC.HeapHardLimit": 300000000
}
}
}
I am putting heap limit to 300Mbs to leave space for non-heap memory allocations.
And I have added to the project file MyProject.csproj following lines to make sure that Memory consumption is not increased by number of processors:
<PropertyGroup>
<!-- https://blog.markvincze.com/troubleshooting-high-memory-usage-with-asp-net-core-on-kubernetes/ -->
<!-- https://blog.discountasp.net/reducing-net-core-memory-usage/ -->
<ServerGarbageCollection>false</ServerGarbageCollection>
<ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>
</PropertyGroup>
My application will serve very small number of users/clients and the response time is not very critical. Simply put: application can be "reasonably slow" , but it needs to run "without outages".
Edit: The high memory allocation is caused mainly by background job started by some users, which is consuming quite significant memory (it is recursive algorithm without memory leaks). Application itself after fresh start allocates 118MBs ( 14 MBs heap size )
Rewriting application to WASM is an option, but I will still need to host Data repositories (serving data) in the server under IIS and I would till be interested how to limit "memory".
Can you share your approach, how to "limit" memory consumption and instruct garbage collection to be more aggressive when 500MBs is going to be reached ?
Thanks