2

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

8
  • "will serve very small number of users/clients" : then how do you get past the 500MB ? First thing would be to see how much data is held in a 'session', andif you can reduce it. Commented Oct 31, 2021 at 8:20
  • But these constraints would make Blazor Webassembly a better fit. Is that an option? Commented Oct 31, 2021 at 8:21
  • Web assembly is an option. I will try to investigate how porting to Web assembly would fit into. Commented Oct 31, 2021 at 15:35
  • The high memory allocation is caused mainly by background job started by each user which is consuming quite significant memory (it is recursive algorithm without memory leaks). Application itself after fresh start allocates 118MBs ( 14 Mb heap size ) Commented Oct 31, 2021 at 15:41
  • Then the solution will also have to be about that background job. Slim it down, host it elsewhere? Commented Oct 31, 2021 at 16:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.