Asp.net Core does not collect garbage

I cannot understand why the Asp.net kernel does not collect garbage. Last week, I let the web service run for several days, and my memory usage reached 20 GB. GC does not seem to work. Therefore, to test this, I wrote a very simple web method that returns a large collection of strings. The application started with only 124 MB, but every time I called the web method, the memory usage continued to grow higher and higher until it reached 411 MB. That would be higher if I kept calling the web method. But I decided to stop testing.

enter image description here

Does anyone know why the GC is not working? As can be seen from the performance monitor, GC was called (yellow marker on the graph). But he did not collect garbage from memory. I would have thought that the Civil Code would be willing to collect everything that did not refer to it.

Any help would be GREATLY appreciated. Thank you :)

+6
source share
2 answers

The server caches the output, 100,000,000 * 4 characters ~ 411 MB.

0
source

I ran into the same problem and after a long day I found a solution in one of the github issues registered for high memory consumption.

Actually, this is the expected behavior (in a multi-core machine with a large amount of memory), which is called the β€œServer” garbage collection mode. This mode is optimized for server loading and starts the GC only when it is really necessary (when it starts to run out of memory in the machine).

The solution is to change the GC mode to Workstation mode. You can do this by adding a parameter to your .csproj

<PropertyGroup> <ServerGarbageCollection>false</ServerGarbageCollection> </PropertyGroup> 

Workstation mode is designed to use less memory, but more often it starts the GC.

This is well documented by Sebastian Ros here: https://github.com/sebastienros/memoryleak

In a typical web server environment, the CPU resource is more critical than memory, so it is better to use a server GC.

0
source

Source: https://habr.com/ru/post/1265720/


All Articles