Using the Server (rather than Workstation) Garbage Collector with the .NET Framework (CLR)
We run a big .NET Application Server, often on multi-proc machines, so we care about performance and, consequently, garbage collection. I've collected a few resources around the two kinds of Garbage Collectors available in .NET, the Workstation GC and the Server GC.
From the MSDN Help:
Two different Garbage Collectors are available for the CLR: a Workstation GC and a Server GC. Console and Windows Forms applications host the Workstation GC, and ASP.NET hosts the Server GC. The Server GC is optimized for throughput and multi-processor scalability. The server GC pauses all threads running managed code for the entire duration of a collection, including both the Mark and Sweep Phases, and GC happens in parallel on all CPU's available to the process on dedicated high-priority CPU-affinitized threads. If threads are running native code during a GC then those threads are paused only when the native call returns. If you are building a server application that is going to run on multiprocessor machines then it is highly recommended that you use the Server GC. If your application in not hosted by ASP.NET, then you are going to have to write a native application that explicitly hosts the CLR.HINT: If you are building scalable server applications, host the Server GC. See Implement a Custom Common Language Runtime Host for Your Managed App.
- Hosting the CLR in a generic service and Hosting the Server GC: "To load the svr GC, we created a generic Windows service that loads the svr GC, creates an AppDomain, and runs our application."
HRESULT hr = CorBindToRuntimeEx(NULL,
//Retrieve latest version by default
//Request a Server (svr) or WorkStation (wks) build of the CLR
- Using the Server Garbage Collector:
1. Create the system environment variable COMPLUS_BUILDFLAVOR to SVR
2. SET COMPLUS_BUILDFLAVOR = SVR
3. Generate this key in the windows registry: HKLM/Software/Microsoft/COMPlus with a single string value BuildFlavor with value "svr"
SDH Note: This is fully unsupported my Microsoft.
- Improvements in .NET 1.0 SP3 and .NET 1.1 SP1 and How to enable CLR Server GC?
<gcServer enabled=“true“ />
From Chris Kinsman: Here’s a way to do it that’s not a hack – right-click on My Computer in .NET Configuration in Administrative Tools. UPDATE: In fact, this is NOT so, details on this setting at OdeToCode.com