Pages

Wednesday, October 23, 2013

What's new in ASP.Net 4.5 - Garbage Collector

There are a few improvements shipped with .Net Framework 4.5, but the first one that I would share some details with, is Garbage Collection. If you would like to read the basics of the Garbage Collection read this

There are some performance improvements in the Garbage Collection process, which I would like to discuss here. GC is always a process which consumes both memory and the processor a lot and it has always been a problem area for websites running under .Net because the process for ASP.Net applications is continuously running and a lot of users are requesting the content and thus creating many objects on the fly and many of those objects are supposed to be destroyed by the GC too often. 

Whenever GC is trying to clean up the memory. It consumes a lot of resources and the GC thread suspends the main website threads and thus the other resources have to wait for the cleanup process to complete before serving further requests of the users.


GC Model in .Net 4.0

Previously (in .Net 4.0), if we could simulate the GC Thread along with ASP.Net website threads. The picture should be something like this...


GC Model in .Net 4.0

As you can see in the above figure that whenever the two processes of GC run (one for each logical processor). The other threads have to wait for the cleanup process to complete before carrying on with the tasks, so user feels the processes to be less responsive while the garbage collector is running.

GC Model in .Net 4.5

Now (in .Net 4.5), the GC Thread takes less time and consumes lesser time, so that other threads are not suspended for longer periods

GC Model in .Net 4.5


Microsoft introduced new features in server GC for .Net 4.5 and as you can see in this figure, the server GC has introduced a new thread for Garbage Collector which is running in the background and is collecting objects from Generation 2, so the main application threads do not suspend much, thus increasing overall application performance. 

Enable Server GC in Config

To enable server GC in your application, you only have to add this to your configuration file.

Enable GC in Config

  

For any queries, please comment below...

References:

No comments:

Post a Comment