grokky
grokky

Reputation: 9255

What is server garbage collection in ASP.NET Core?

I've upgraded a ASP.NET Core project to VS2017 and the new csproj, and there is this option:

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

What is server garbage collection? There is no proper documentation, just a migration guide which assumes you already know what it is.

(Unless there is a formal doc, in which case please let me know.)


Summary: There is no details in the docs for much of the underlying tech, unfortunately. However @PanagiotisKanavos's link has the important bit about "server gc" here.

Upvotes: 37

Views: 37639

Answers (4)

wels1200
wels1200

Reputation: 111

Microsoft Learn documentation...

https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element

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. Use the gcServer 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. Most commonly, multiprocessor server systems disable server GC and use workstation GC instead when many instances of a server app run on the same machine.

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

Upvotes: 9

Shadi Alnamrouti
Shadi Alnamrouti

Reputation: 13248

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

Upvotes: 2

David Pine
David Pine

Reputation: 24525

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

Upvotes: 6

Christopher
Christopher

Reputation: 9804

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.

Upvotes: 23

Related Questions