This post originated from an RSS feed registered with .NET Buzz
by Scott Hanselman.
Original Post: Using the Server (rather than Workstation) Garbage Collector with the .NET Framework (CLR)
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
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.
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."
CComPtr
spRuntimeHost;
HRESULT hr = CorBindToRuntimeEx(NULL, //Retrieve latest version by default L"svr",
//Request a Server (svr) or WorkStation (wks) build of the CLR STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void**)&spRuntimeHost);>
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.