TechBubbles Microsoft Technology BLOG

Performance tuning For .NET Applications

Performance tuning is one of the daunting task for making your applications run faster. There are several factors that can cause your application run slow. One of the factor is memory which can directly impact on your program execution. This post discusses the basics of memory optimization for .NET programs. If we outline the cases where memory access is bottleneck then it is easier for tune them. I also discuss the tools and strategies to determine the bottlenecks of memory in .NET Applications.

dot_net_memory_profiler_graph

Bottlenecks

Memory Usage and Speed

Case1:

Memory consumption is matter when your application manipulates the large amount of data. The speed is limited by how long it takes for CPU to bring the instructions from memory. More data then more time……

Case2:

Memory consumption also matter is during an application startup. Hard disk access is much slower than main memory access. When the application launched second time then it will be faster.

Case3:

Memory consumption matter is during application switching. When your application switches to the other applications , there is a chance of stealing the physical memory of your applications. When user returns to your application, these stolen pages needs to be fetched back from the desk, which makes your application very slow.

Solution

A feasible solution could be minimizing the amount of memory used. This reduces the load on the fast cache and makes program execution faster.

You can execute less code while program startup. Efficiently using the data structures. These things needs to be done in the early stages of the development.

Task Manager

You can use Task Manager to know how much of memory your application currently used. You can invoke it by (Winkey + R). If the columns don’t include PID, Memory-Working Set, use the View->Select Columns menu option to add them to the display.

Working Set is the physical memory currently being used by the process.

Application Size

Depending on memory usage application can be categorized small, medium or large. A simple and quick way to monitor memory usage and check for leaks is by running a test on your application. Run the application and monitor its working set usage; if the working set grows unbounded then it can mean a memory leak.

VADump: A More Detailed View

Task Manager just provides the summary of the memory usage of an application. To get more detail you need a tool called VADump. This can be invoked by typing VADump –sop processID in the command prompt under the directory in which it is installed. It prints a breakdown of memory within a single process down to DLL level. You can download the tool from here.

The .NET Garbage Collector

The .NET runtime supports automatic memory management. Garbage Collector in runtime finds memory that is no longer in use and reuses it for new allocations. Garbage Collector partitions the heap into three generations(0,1, and 2).

PerfMon

VADump gives the first level of breakdown of memory usage in the process. It does not tell you how much GC memory we are using and also whether we are having a healthy ration of GC generations. You can invoke it by typing PerfMon in run command. After PerfMon comes up, we need to configure it to display information about the GC. A healthy number for GC is less than 10 percent of total application time.

Source: MSDN magazine

Conclusion 

Memory issues are difficult to debug. If your application is large enough to care about memory, the key is to control memory usage in early stages of the development.

Share this post :

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud