< Go Back to Homepage

Performance Analysis: Comparing Interactive and Low Latency GC Strategies in .NET

by Andreas Grabner, Apr 13, 09

The .NET Runtime can run with different GC flavors. The following article does a good job in explaining the options: Low Latency GC in .NET 3.5 by Sasha Goldshtein.

Comparing the two modi with a sample application

I was curious about how the different modi affect the time spent by the Garbage Collector. I therefore created a sample app with two identitical methods. The methods allocate several thousand string objects. In my sample app I call each method 10000 times in a loop with the difference that I use GCLatencyMode.LowLatency for one loop and GCLatencyMode.Interactive for the other loop. Here is my sample code:

public static void DoMemoryActions()
{
  GCSettings.LatencyMode = GCLatencyMode.LowLatency;
  for (int i = 0; i < 10000; i++)
    MyBusinessMethod1();
  GCSettings.LatencyMode = GCLatencyMode.Interactive;
  for (int i = 0; i < 10000; i++)
    MyBusinessMethod1a();
}

The two methods – MyBusinessMethod1 and MyBusinessMethod1a – have an identical implementation. I created two identical methods with a different name in order to distinguish them when analyzing the GC activity.

Based on the description of how LowLatency should work I expected the GC not to kick in as frequently for the method calls in the first loop compared to the second loop where I use Interactive (which is the default mode). Analyzing the GC Suspension Time however showed just the opposite:

More GC Activations in LowLatency Mode

More GC Activations in LowLatency Mode

LowLatency mode caused the GC to run 3 times as often as in Interactive mode. The average GC time on the other side was 40% higher on average for the GC run in Interactive mode. In my example – Interactive would be the right choice as 7 seconds less are spent by the Garbage Collector.

Conclusion

Many developers probably don’t know about the option to change the GC Strategy during runtime – at least that is true for workstations. There are more settings that can be changed to change the behavior of the .NET Garbage Collector. Its good to know that they exists and how they affect the runtime behavior. I do recommend to run some tests with different settings. The right choice strongly depends on the type of application.

Share
  • Facebook
  • Reddit
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • MisterWong
  • Technorati
  • E-mail this story to a friend!
  • Google Bookmarks
  • DZone
  • FriendFeed
  • Ping.fm
  • Slashdot
  • Twitter

Related posts:

  1. Performance Analysis: How to identify “bad” methods messing up the GC Whenever the Garbage Collector kicks in to free up memory...
  2. Performance Analysis: Identify GC bottlenecks in distributed heterogeneous environments Garbage Collection can have a major impact on application performance....
  3. .NET Performance Analysis: A .NET Garbage Collection Mystery Memory Management in .NET is a broad topic with a...
  4. Performance Analysis: How to identify synchronization issues under load? Synchronization is a necessary mechanism to control access to shared...
  5. Automated Performance Analysis: What’s going on in my ASP.NET or ASP.NET MVC Application? I’ve spent some time in the last weeks playing with different...

Trackback

No comment yet

Add your comment now