Thursday, 15 March 2012

.Net GC update

Time ago I wrote about the .Net GC. When I stumpled upon this news piece in InfoQ talking about GC's latency mode, it sounded like new to me, so I had to read through that old post again to refresh my mind and try to complement it.

So, the thing is that in .Net we have 2 GC modes:

  • Server GC. Under Server GC there's not Background (previously Concurrent) GC. When a GC runs we have a stop the world approach, this should be OK for some server apps where a pause in the application could be attributed to Network latency itself. Under Server GC the latency mode is always GCLatencyMode.Batch
  • Workstation GC. Under Workstation GC we can use the Background (Concurrent) GC or not. By default, the value for GCSettings.LatencyMode should be Interactive, which means that the Concurrent GC is enabled.

    Interactive Enables garbage collection concurrency and reclaims objects while the application is running. This is the default mode for garbage collection on a workstation and is less intrusive. It balances responsiveness with throughput. This mode is equivalent to garbage collection on a workstation that is concurrent. It is not available on the server garbage collector.

    We could dynamically set it to GCLatencyMode.Batch, which would prevent the Concurrent GC. Finally, we have the LowLatency (and now the SustainedLowLatency) mode, that should not be used throughout the whole lifetime of the application, but only at some intervals for which we want to avoid GC pauses (as they exemplify somewhere, we are in the middle of an animation and don't want it to get paused disturbing the user). So, this mode prevents the GC from running, but we should understand that this is risky, cause if we prevent it from running for too long, we could end up with an OutOfMemoryException.

You can read more about this here and here

No comments:

Post a Comment