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 (29)

  1. Anonymous says:

    Cool. I was waiting for this setting for my Managed Win32 Service. I will be looking forward to your blog posts!

  2. Anonymous says:

    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.

  3. Anonymous says:

    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;…

  4. Anonymous says:

    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;…

  5. Anonymous says:

    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;…

  6. Anonymous says:

    Question: How many threads does a typical managed process have when it just starts to run?&amp;nbsp;&amp;nbsp;…

  7. Anonymous says:

    This post is about improving the performance of a load test when running the test on a multi-processor…

  8. Anonymous says:

    This post is about improving the performance of a load test when running the test on a multi-processor

  9. Anonymous says:

    As you may know, there are different GC modes to choose from depending on the type of application you’re

  10. Anonymous says:

    It was really exciting to see that so many people answered the .NET GC PopQuiz , especially seeing that

  11. chew says:

    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

  12. clyon says:

    Hi Chew

    On 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

  13. chew says:

    Hi Chris,

    I’ve posted the same question at maoni’s blog. I thought I’ll post it here again. Hope you don’t mind. Do you think the used of GC in .Net has robbed its suitability in high performance computing applications, considering the fact that GC will suspend all managed threads and perform compacting of memory?

    chew

  14. clyon says:

    Hi Chew

    I don’t think .NET is unsuitable for all high performance applications, although as you pointed out, managed memory environments are not always suitable for applications with hard real-time requirements.  We on the GC team are always working hard to enhance performance and reliablity of the GC and improve the user experience.  

    We have added new features in Orcas that reduce GC intrusiveness for blocks of performance-sensitive code (see http://blogs.msdn.com/clyon/archive/2007/03/12/new-in-orcas-part-3-gc-latency-modes.aspx).  Rest assured, performance is one of the GC team’s top priority.

  15. Anonymous says:

    To rephrase this post (or rant) in a nutshell: Measuring performance is not as simple as people think

  16. Anonymous says:

    Since the goal of Parallel Extensions is to simplify parallel programming, and the motivation behind

  17. Anonymous says:

    Most Common Performance Issues in Parallel Programs

  18. Anonymous says:

    I often hear from X++ developers, that the .Net garbage collector ( GC ) does not work correctly or that

  19. Anonymous says:

    I often hear from X++ developers, that the .Net garbage collector ( GC ) does not work correctly or that