Hi @usha, Welcome to Microsoft Q&A.
The .NET garbage collector has two different modes:
Workstation GC: Optimized for desktops.
Server GC: The default GC for ASP.NET Core applications. Optimized for servers.
GC mode can be set explicitly in the project file or in the runtimeconfig.template.json file of the published application. The following markup shows setting ServerGarbageCollection in the project file:
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>
Changing the ServerGarbageCollection in the project file requires rebuilding the app.
Note: Server garbage collection is not available on machines with a single core. For more information, see IsServerGC.
The test results of the memory profile of workstation GC and server GC occupying the same large amount of RPS are as follows:
- Working set reduced from 500 MB to 70 MB.
2.GC generates 0 times per second (instead of recycling every two seconds).
3.GC dropped from 300 MB to 10 MB.
After disabling the GC in Server mode through
<ServerGarbageCollection>false</ServerGarbageCollection>
, the GC becomes Workstation mode, and the program will recycle memory more aggressively. Of course, after changing the server-side program to Workstation mode, the performance of the program will be affected, so unless there is a good reason, it is not recommended. After all, for the server, idle memory is a waste.
In summary, whether to use
<ServerGarbageCollection>false</ServerGarbageCollection>
depends on your specific production environment. In a typical web server environment, CPU usage is more important than memory, so server GC is better. If memory usage is high and CPU usage is relatively low, a workstation GC may provide higher performance. For example, high density hosting of several web applications with insufficient memory.
Best Regards,
Wenbin
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.