Performance: Garbage collection modes.
There are allots of improvements that can be done within application’s configuration file the only catch with it – you have to know that it’s exists. In this post I will show how to improve garbage collection performance according to application’s type.
There are 3 modes of garbage collection that can be defined in a configuration file:
- Workstation mode with enabled Concurrent flag
- Workstation mode with disabled Concurrent flag
- Server mode
Workstation mode with enabled Concurrent flag
This mode is designed to get a better responsiveness of an application’s UI and the price for the responsiveness is more CPU and memory usage.
By default this mode is enabled in Windows Forms applications, Console Applications and Windows Services .
Workstation mode with disabled Concurrent flag
This mode is optimized for height throughput applications running on single CPU computers although it is stops current thread when GC is active. Therefore it is not a best choice for an applications with UI present.
To configure this mode following must be inserted at configuration file:
<configuration>
<runtime>
<gcConcurrent enabled="false"/>
</runtime>
</configuration>
Server mode
In the Server GC mode, GC heap and GC thread are created for each CPU available, making application’s throughput and scalability higher. This mode is available only on multiprocessors systems and it is default at ASP.NET applications.
To configure this mode following must be inserted at configuration file:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
Summary
In the age of parallel processing when most computers are already have at least two CPUs might be a good idea to test application’s performance with GC mode set to Server mode. Good example for such applications is WCF services host, which in many cases is Console application or Windows Service. In a upcoming Parallel Extensions Library the Server GC mode is a recommended mode by Microsoft for a better performance.
For a dipper exploration of GC principles and modes please refer to a Maoni’s posts.