I am running a large .net 4.0 x86 app on Windows Server 2003 x64 (2x Xeon 4 core procs), and am running into issues where my app ~2-3 times a day freezes for 30 seconds, and then resumes functioning as normal. The application is only rebooted once a week, and consumes 400-800 mb of memory, so I am assuming these freezes are Garbage Collection. I am only seeing the freezes in the logs, not live, or I would check the Task Manager to confirm.
I am trying to figure out which .Net 4 GC is running, and how to either switch the GC to the new concurrent background gc if it isn't, or how to confirm these are in fact GCs (Procmon doesn't show .Net instruments in Win2k3 server).
I've re-posted this answer on my blog: http://dave-black.blogspot.com/2012/04/how-to-determine-which-garbage.html
You can determine which version of GC you're running via 2 methods:
You did not say what kind of app you have. If you are running a Console app, WinForm app or a Windows Service, you will get the Workstation GC. Just because you are running on a Server OS doesn't mean that you will get the Server version of GC. If your app is non-hosted on a multi-proc machine, you will get the Workstation GC - Concurrent by default. If your app is hosted on a multi-proc machine, you will get the ServerGC by default.
Any IIS or CLR self-hosted app will run in ServerGC mode by default.
The following apply to any given .NET Managed Process:
Workstation GC
Workstation GC - Concurrent
Server GC
There is only 1 Finalizer thread per managed process regardless of GC Mode. Even during a concurrent GC, managed threads are suspended (blocked) twice to do some phases of the GC.
A seldom known fact is that even if you try to set the Server mode of GC, you might not be running in Server GC; the GC ultimately determines which mode will be optimal for your app and WILL override your settings if it determines your ServerGC setting will negatively impact your application. Also, any hosted CLR app running on a uniprocessor machine will have any manual GC settings overridden - in which case the CLR will always use Workstation GC mode.
In CLR 4.0, things change only a little bit
In CLR 4.5, things change only a little bit...again
Thus, in .NET 4.5+, all applications now have background GC available to them, regardless of which GC they use.
.NET 4.7.1 GC Improvements
.NET Framework 4.7.1 brings in changes in Garbage Collection (GC) to improve the allocation performance, especially for Large Object Heap (LOH) allocations. This is due to an architectural change to split the heap’s allocation lock into 2, for Small Object Heap (SOH) and LOH. Applications that make a lot of LOH allocations, should see a reduction in allocation lock contention, and see better performance. These improvements allow LOH allocations while Background GC (BGC) is sweeping SOH. Usually the LOH allocator waits for the whole duration of the BGC sweep process before it can satisfy requests to allocate memory. This can hinder performance. You can observe this problem in PerfView’s GCStats where there is an ‘LOH allocation pause (due to background GC) > 200 msec Events’ table. The pause reason is ‘Waiting for BGC to thread free lists’. This feature should help mitigate this problem.
You are running on the server version of Windows, you'll get the server version of the garbage collector by default. Which doesn't do background collections, garbage is collected by multiple threads so occasional observable pauses are not unusual. You can force the workstation version with an app.exe.config file:
Also review the docs for the GC.RegisterForFullGCNotification() method for a way to deal with the side-effect of the pauses.
.NET version 4.5 will support background collections for the server GC.