Reducing memory used by the .NET garbage collector
Recently I’ve been analyzing memory usage of one of our ASP.Net applications and discovered a configuration setting that greatly reduces an application’s memory footprint.
Since .Net 2.0 there are two main kinds of garbage collectors used by the CLR:
1) Server – Optimized for long running applications that will be the primary software on a system. Memory is allocated more aggressively to the .NET memory heaps causing more memory is used overall by the application but with the hope of faster performance. Recommended by Microsoft to be used on multi-processor systems and it appears to be on by default on those systems.
2) Workstation – Optimized for applications that will be running alongside many other processes. Memory is allocated more conservatively at the possible expense of more time being spent in the GC.
Btw, you can determine which GC is being used by checking the GCSettings.IsServerGC property.
The GC can be changed via the aspnet.config file under C:\Windows\Microsoft.NET. Note that this setting affects ALL ASP.Net applications on the server:
<configuration>
<runtime>
<gcServer enabled="false" />
</runtime>
</configuration>
While testing this setting the effect of the different GC’s under ASP.Net I’ve noticed that the Workstation GC requires around 65-75% of the memory required for the Server GC. This is very good news for those of us trying to have an economical shared hosted environment (ie, trying to host as many application instances on a single server as possible).
Here is the specific data collected from the test for the two different garbage collectors showing the difference before and after the aspnet.config change:
| Memory Usage (megabytes) | |||
| Idle after GC.Collect() and app caches filled | Avg under test | Max under test | |
| Workstation GC | 329 | 555 | 660 |
| Server GC | 415 | 920 | 1002 |
About this entry
You’re currently reading “Reducing memory used by the .NET garbage collector,” an entry on Matt Hooper
- Published:
- March 23, 2011 / 11:48 am
- Category:
- Uncategorized
- Tags:
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]