35

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
  • 8,537
  • 20
  • 62
  • 96
  • Have you tried googling? There is a *lot* of documentation, going back several years. This isn't new to .NET Core, even if the property has a new name – Panagiotis Kanavos May 23 '17 at 12:16
  • 1
    Might be same as [this](https://msdn.microsoft.com/en-us/library/ms229357(v=vs.110).aspx)? – Mats391 May 23 '17 at 12:16
  • 1
    Then you saw that the very first result is [Fundamentals of Garbage Collection](https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110).aspx), which explains the difference between workstation and server garbage collection. This hasn't changed with .NET Core – Panagiotis Kanavos May 23 '17 at 12:17

4 Answers4

21

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.

Brandon Clapp
  • 66,931
  • 6
  • 20
  • 24
Christopher
  • 9,634
  • 2
  • 17
  • 31
  • 1
    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. – Lex Li Mar 20 '18 at 01:39
  • The question literally asks what is ASP.NET Garbage Collection strategy. The answer should then be: Server GC. The framework does that here https://github.com/dotnet/sdk/blob/be3ef1ebb2a627978f5fb613977feac3535a221c/src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.props#L20 – Serge Pavlov Apr 26 '23 at 16:51
  • @SergePavlov Actually it is .NET Core. Also what you linked is just a config file with the option highlighted and no explanation what it does. The exact implementation details will depend on the Framework that is running your MSIL anyway - so I gave the most general level overview to make him understand what the choice (likely) meant. – Christopher Apr 26 '23 at 22:22
  • @Christopher ASP.NET Core: yes. I can not give an explanation because there is none. The framework does what it does: defaults to the Server GC. Your answer is good and educational. – Serge Pavlov Apr 28 '23 at 13:40
9

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.

Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
wels1200
  • 111
  • 2
  • 2
    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??? – grokky May 23 '17 at 12:24
  • @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? – Luaan May 23 '17 at 12:46
  • @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 – Panagiotis Kanavos May 23 '17 at 12:48
  • @Luaan no I am looking for a rational answer to a rational question, as others have very kindly assisted with. – grokky May 23 '17 at 13:54
  • @grokky all the answers come from the `Fundamentals` article – Panagiotis Kanavos May 23 '17 at 13:55
  • 2
    @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. – grokky May 23 '17 at 14:09
  • 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 – Panagiotis Kanavos May 23 '17 at 14:10
  • @PanagiotisKanavos Aha, miscommunication then... Thought you were just trolling. LOL. Yes I didn't find relevant docs, so that link was helpful, thanks again. – grokky May 23 '17 at 14:13
  • @grokky it actually does explain what the difference is. Server garbage collection is concurrent, workstation not... – wels1200 May 23 '17 at 14:51
  • @wels1200 Agreed, I think the problem is this config option is poorly named. – grokky May 23 '17 at 14:57
6

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

Henrik
  • 9,714
  • 5
  • 53
  • 87
David Pine
  • 23,787
  • 10
  • 79
  • 107
  • 2
    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 – Kamran Shahid Dec 18 '19 at 10:09
2

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

Shadi Alnamrouti
  • 11,796
  • 4
  • 56
  • 54
  • 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". – jspinella Jan 11 '22 at 21:58