What is server garbage collection in ASP.NET Core?

23,440

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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

Share:
23,440
grokky
Author by

grokky

Updated on August 30, 2020

Comments

  • grokky
    grokky over 3 years

    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.

  • grokky
    grokky almost 7 years
    This is what I meant in the comments above. This description doesn't actually explain what is "server garbage collection". Only that there is such a thing, that it occurs on a server, that there are other options too, and on which hardware you should use it. But what is it???
  • Luaan
    Luaan almost 7 years
    @grokky "What is it" is a meaningless question. What is missing in your model of server garbage collection that you need explained? Are you looking for the source codes of the .NET Server GC on a particular system configuration? Are you looking for a magic word to replace your confusion? What kind of information would you expect to satisfy yourself? Extensional descriptions are how communication starts; in which way would an intensional description help you? Do you have extensive knowledge of GCs in general, and are you looking how it maps to what's called "Server GC" in .NET?
  • Panagiotis Kanavos
    Panagiotis Kanavos almost 7 years
    @Luaan it's a simple confusion (I think). The OP assumed that GC is different in .NET Core so bypassed all documentation and references that didn't explicitly mention server GC in .NET Core. Given that it isn't different, there is no such documentation. Catch-22
  • grokky
    grokky almost 7 years
    @Luaan no I am looking for a rational answer to a rational question, as others have very kindly assisted with.
  • Panagiotis Kanavos
    Panagiotis Kanavos almost 7 years
    @grokky all the answers come from the Fundamentals article
  • grokky
    grokky almost 7 years
    @PanagiotisKanavos There is a section in there that explains the pros/cons, good stuff. You could have just added that an answer to begin with, and avoided all the nastiness. Nonetheless, thanks for the link.
  • Panagiotis Kanavos
    Panagiotis Kanavos almost 7 years
    I have done so, in the 3rd comment. When I was trying to understand whether you had a specific question or just didn't find the docs
  • grokky
    grokky almost 7 years
    @PanagiotisKanavos Aha, miscommunication then... Thought you were just trolling. LOL. Yes I didn't find relevant docs, so that link was helpful, thanks again.
  • wels1200
    wels1200 almost 7 years
    @grokky it actually does explain what the difference is. Server garbage collection is concurrent, workstation not...
  • grokky
    grokky almost 7 years
    @wels1200 Agreed, I think the problem is this config option is poorly named.
  • Lex Li
    Lex Li about 6 years
    Though this answer is correct (matching the typical reasoning), I just want to point out that there exists cases you need to run your apps in Workstation mode, instead of Server mode (very rare, and only when Server mode gives you miserable crashes). You should report such crashes to Microsoft support if you like so that they can improve the GC, of course.
  • Kamran Shahid
    Kamran Shahid over 4 years
    this settings make my application unresponsive and consuming GB of memory. i have to set it off in my asp.net core 3.1 application then application starts working
  • jspinella
    jspinella over 2 years
    And to be clear "processor" is really "CPU core" (CPU thread actually, I would think). So this isn't like "multi-CPU as in NUMA is a thing" but multi-CPU as in "all computers made after like 2005".