By Red Gate Software, May 1, 2013

Editorial Note

This is a sponsored article by Red Gate software. It is intended to provide you with information on products and services that we consider useful and of value to developers.

About Article

When trying to speed up a slow-running application, it helps to know where the problem is. There are many causes of performance issues, but one of the most common and difficult to diagnose issues is around the application's data access.

How to understand data access

ANTS Performance Profiler (hwww.red-gate.com/products/dotnet-development/ants-memory-profiler) lets you look at all aspects of your app's data access in one place, and understand how it relates to your .NET code.

Any queries run against SQL Server or Oracle databases are recorded, along with how many times those queries were run and how long they took. That information is shown alongside your .NET code, so you can quickly see why the code you wrote resulted in those queries being executed. This can be particularly powerful if you’re using ORMs like Entity Framework to access data, which tend to be an impenetrable black box where performance issues can arise, but where it’s difficult to understand why.

1. Database activity is visible in the application’s call tree

ANTS also let you look at any HTTP requests made by your application, so you can understand how communicating with web servers affects performance. The URL, verb, and status code are captured, along with complete request and response header information.

2. Detailed information about web requests

Just like with database profiling, this information is presented in the application’s call tree, so you can understand the true cause of any long-running, unnecessarily repeated, or failed requests.

You’re also able to look at how file system access affects performance with File I/O profiling, which shows you a complete list of any disk accesses your application made, along with how much data was read or written, and how long the I/O operation took.

The ability to see all this information about data access performance and how it relates to your code frees you from trying to manually relate separate logs back to your code, and lets you get on with writing awesome software instead.

What’s async code really doing?

If you’ve recently tried writing asynchronous code using C#5’s new Async / Await keywords (perhaps for asynchronous controllers in MVC4), you’re probably still smiling about just how much easier asynchronous programming has become. Maybe you’re still waiting for the catch?

That moment’s likely to come when you want to look at how your codeperforms. When you compile async code, behind the scenes the .NET framework splits up async methods so that the part of a method before an Await keyword is generally executed on a different thread to the part after the Await keyword (the continuation). When you come to look at that code’s performance, it isn’t possible to see how the different parts of the method are related, which makes understand poorly-performing code nightmarishly complicated. You also can’t see how time spent doing work asynchronously is related to the code which caused it to run, and method names stop resembling what you wrote as you become exposed to the async state machine’s internal renaming system.

3. Async performance is shown in the context of the code you wrote

ANTS Performance Profiler has a new async profiling mode, which joins your methods back up, so you can see continuations as part of the methods they actually belong to. ANTS can also show you how time spent on asynchronous activity like making data access requests relates back to the method which caused that activity to run, and presents method names as you wrote them. Now you can now understand how your async code performs in the context of what you wrote, and ultimately, what you need to fix to make your application run faster.

What’s next?

Learn more about ANTS Performance Profiler, and try it on you own application with a free 14-day trial.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)