What is server garbage collection in ASP.NET Core?

It seems to be the difference between Normal (Workstation) and Concurrent (Server) Garbage Collection strategies. Basically the Workstation approach runs into issues in many extreme cases. And massively Multithreaded scenarios (like ASP Webservers) are prime examples of such an extreme case:

https://social.msdn.microsoft.com/Forums/en-US/286d8c7f-87ca-46b9-9608-2b559d7dc79f/garbage-collection-pros-and-limits?forum=csharpgeneral

Note that concurrent GC has natural issues with weak references and defragmentation, but if that applies to the .NET Core implementation is beyond my knowledge. There are all kinds of improvements the .NET Core team could do to the code and this goes into the area of designing a GC memory manager.

Maybe it only defines how many concurrent threads will be used for the tagging part (with the workstation default being 1). It might also include some modified memory allocation strategies to avoid issues like defragmentation. In either case the actual collection will by nature have to run single-threaded, halt all managed threads and will be limited by memory speed, not CPU speed.


When migrating over, the ServerGarbageCollection maps from the System.GC.Server.

<PropertyGroup>
  <ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

What is server garbage collection?

Simply, it is a configuration value that instructs the .net runtime to perform server garbage collection. Historically this was managed by the project.json. It enables/disables server garbage collection.

This is the as close to an official document that you're going to find, it's an announcement about the addition of this option into the project.json.

https://github.com/aspnet/Announcements/issues/175

Likewise, additional details here:

https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/clr-configuration-knobs.md#host-configuration-knobs


msdn documentation...

https://msdn.microsoft.com/en-us/library/ms229357(v=vs.110).aspx

The common language runtime (CLR) supports two types of garbage collection: workstation garbage collection, which is available on all systems, and server garbage collection, which is available on multiprocessor systems. You use the element to control the type of garbage collection the CLR performs. Use the GCSettings.IsServerGC property to determine if server garbage collection is enabled.

For single-processor computers, the default workstation garbage collection should be the fastest option. Either workstation or server can be used for two-processor computers. Server garbage collection should be the fastest option for more than two processors.

This element can be used only in the application configuration file; it is ignored if it is in the machine configuration file.


It toggles GC between Server (more than 1 processor) or workstation (1 processor).