共用方式為


Server, Workstation and Concurrent GC

One common question I see asked is the differences between server and workstation GC, and how Concurrent GC fits in.

Server GC is only available on multi-proc machines. It creates one GC heap (and thus one GC thread) for each processor, which are collected in parallel. This GC mode maximizes throughput (number of requests per second) and shows good scalability (performance really shines with 4 or more processors).

Workstation is the default GC mode. On a single-proc machine, it’s the only option.

Concurrent GC is used in Workstation mode on a multi-proc machine. It performs full collections (generation 2) concurrently with the running program, minimizing the pause time. This mode is particularly useful for applications with graphical user interfaces or applications where responsiveness is essential.

How do I choose a GC mode?

In v1.0 and v1.1 (pre-SP1), server mode can only be used if the runtime is hosted in an unmanaged application (for example, ASP.NET hosts web applications in server mode). Concurrent mode can be specified in the machine or application’s configuration file. If neither is chosen, or if on a single-proc machine, Workstation is the default.

Note: Server mode automatically disables Concurrent GC.

To set GC mode to Concurrent:

<configuration>
  <runtime>
    <gcConcurrent enabled="true" />
  </runtime>
</configuration>

To set GC mode to Server (unmanaged C++):

HRESULT CorBindToRuntimeEx( LPWSTR pwszVersion,
  LPWSTR pwszBuildFlavor, // use “svr” for server mode,
  // “wks” or NULL for workstation
  DWORD flags,
  REFCLSID rclsid,
  REFIID riid,
  LPVOID* ppv );

One of the most popular feature requests was the ability to specify the GC mode in a non-hosted managed application. In Whidbey (v2.0) and v1.1 SP1, we added a new feature that allows you to specify the GC mode in the application’s config file:

<configuration>
  <runtime>
    <gcServer enabled="true" />
  </runtime>
</configuration>

Note: if the application is hosted, the host’s GC mode overrides the config file.

How do I tell which GC mode my app is using?

In v1.0 and v1.1 of the CLR, the GC was contained in two core DLLs: mscorwks.dll and mscorsvr.dll. If the application is running in server mode, then mscorsvr.dll is loaded, otherwise, mscorwks.dll is loaded. The only way to tell which is loaded is to look at the list of running processes.

Remember, on a single proc-machine, it’s Workstation. On a multi-proc where throughput is important, use Server. If there's user interaction, choose Concurrent.

Edit: Minor corrections.

Edit: Fixed case in XML tags. Thanks Tyler!

Comments

  • Anonymous
    September 09, 2004
    Cool. I was waiting for this setting for my Managed Win32 Service. I will be looking forward to your blog posts!
  • Anonymous
    January 30, 2005
    Hi Joseph, here's 2 more blog entries by Chris Lyon (he's a .NET GC Tester) you could take a look at that I spotted over the weekend, relating to the two GCs in .NET 1.x.
  • Anonymous
    July 05, 2005
    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;...
  • Anonymous
    July 05, 2005
    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;...
  • Anonymous
    July 12, 2005
    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;...
  • Anonymous
    August 28, 2005
    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;...
  • Anonymous
    June 14, 2006
    This post is about improving the performance of a load test when running the test on a multi-processor...
  • Anonymous
    December 15, 2006
    This post is about improving the performance of a load test when running the test on a multi-processor
  • Anonymous
    March 12, 2007
    As you may know, there are different GC modes to choose from depending on the type of application you’re
  • Anonymous
    April 15, 2007
    PingBack from http://sanal.org/?p=309
  • Anonymous
    April 16, 2007
    It was really exciting to see that so many people answered the .NET GC PopQuiz , especially seeing that
  • Anonymous
    May 13, 2007
    Hi Chris,I've a doubt on GC Server throughput. If I've 4 processors and I've an application running 4 threads, each on one processor, how does my application performance benefits from GC Server mode?chew
  • Anonymous
    May 14, 2007
    Hi ChewOn a 4-proc machine, Server GC will give you 4 GC Heaps, each with its own GC thread.  In general, this will improve throughput since you'll have 4 times the number of threads collecting garbage than one.However, depending on your application and its environment, Server GC may not be the most optimal solution for you.  See Maoni's blog entry here:http://blogs.msdn.com/maoni/archive/2006/02/28/workstation-gc-for-server-applications.aspx-Chris
  • Anonymous
    May 14, 2007
    The comment has been removed
  • Anonymous
    May 15, 2007
    The comment has been removed
  • Anonymous
    November 09, 2007
    Please check possible bug in WKS concurrent GC:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2379398&SiteID=1
  • Anonymous
    December 27, 2007
    To rephrase this post (or rant) in a nutshell: Measuring performance is not as simple as people think
  • Anonymous
    August 11, 2008
    Since the goal of Parallel Extensions is to simplify parallel programming, and the motivation behind
  • Anonymous
    August 13, 2008
    Most Common Performance Issues in Parallel Programs
  • Anonymous
    December 07, 2008
    I often hear from X++ developers, that the .Net garbage collector ( GC ) does not work correctly or that
  • Anonymous
    December 15, 2008
    I often hear from X++ developers, that the .Net garbage collector ( GC ) does not work correctly or that
  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/428834-large-object-heap-and-outofmemory
  • Anonymous
    June 15, 2009
    PingBack from http://unemploymentofficeresource.info/story.php?id=16641