Forcing the garbage collector (2)

OK some updates that I have to share.

1) GC modes

If you add this setting to the app.config file and you have more that one physical CPU/core you get different GC behaviour.

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

This puts the GC on the other core, that has some interesting effects on memory and CPU. This is similar to Java VMs but I didn’t really think about it for .NET.

300000_server

you can see the CPU spikes as well as the different memory graph. Unsurprisingly this changes the throughput as well and you don’t get the “bad polls” nearly so much. Overall, thoroughput is improved as well as latency.

2) garbage collection spy class

Add this class:

    class GCNotifier
    {
        ~GCNotifier()
        {
            Console.WriteLine("**GC**");
            new GCNotifier();
        }
    }

and initialise it somewhere in main


static void Main(string[] args)
{
	new GCNotifier();
	. . .
}

then it will be touched each time a GC runs and you will see a console message although not necessarily at the same time as the GC and finalizer are on different threads. It is also a really cunning piece of code (not written by me).

Here is an excellent post on GC “secrets” from a blog I’ve not seen before, but now on my list

http://blogs.msdn.com/tess/archive/2007/04/10/net-garbage-collector-popquiz-followup.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s