Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 820
grokky Avatar asked May 23 '17 12:05

grokky


People also ask

What is server garbage collection?

Server garbage collection is designed for server applications and creates a separate managed heap and a corresponding garbage collection thread for each logical CPU. Threads run on highest priority making it faster but more resource intensive.

What is garbage collection in .NET core?

The garbage collector (GC) manages the allocation and release of memory. The garbage collector serves as an automatic memory manager. You do not need to know how to allocate and release memory or manage the lifetime of the objects that use that memory.

Who performs garbage collection in .NET core?

When the application calls a new operator to create an object, there might not be enough space left in the managed heap to allocate the object. In case of insufficient space, CLR performs garbage collection, which works in the generations.

What is garbage collection and why is it needed?

What is Java Garbage Collection? Java applications obtain objects in memory as needed. It is the task of garbage collection (GC) in the Java virtual machine (JVM) to automatically determine what memory is no longer being used by a Java application and to recycle this memory for other uses.


2 Answers

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.

like image 71
Christopher Avatar answered Sep 22 '22 03:09

Christopher


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.

like image 41
wels1200 Avatar answered Sep 23 '22 03:09

wels1200