Filed under: Application Performance Management
.NET Framework 4.5 Async Feature
The asynchronous support introduced in .NET Framework Version 4.5 makes it easier for developers to write asynchronous applications. Our customers have asked for this functionality as they have increased their use of asynchronous programming to drive overall responsiveness and a way to avoid performance bottlenecks. The two keywords ‘async’ and ‘await’ were added to define asynchronous methods and have made writing asynchronous code much simpler. Asynchrony is very useful for activities such as database queries or external web requests that potentially have high latency so it is important that an APM solution can monitor these activities.
.NET 4.5 also added asynchronous methods to existing classes and in some application areas introduced new classes with asynchronous methods. These updates include adding the HttpClient API (System.Net.Http.HttpClient) which provides asynchronous methods for making HTTP calls (examples: GetAsync, SendAsync, PostAsync, PutAsync) and adding async methods such as ExecuteNonQueryAsync and ExecuteReaderAsync to the System.Data.SqlClient.SqlCommand class. The TraceView .NET Agent supports both of these additions and examples of traces where these methods are instrumented are shown below.
Thread Agility in .NET
Thread agility (or thread switching) in ASP.NET means that the thread used to process a request may change multiple times while the request is being processed. The ability for thread agility in .NET is also key to how asynchronous methods are processed in .NET. The TraceView .NET Agent is able to trace a request and report all instrumented methods even if the thread changes while a request is being processed.
TraceView Async Support
The TraceView instrumentation supports indicating methods as asynchronous as part of the reporting the trace. In the TraceView application on the Trace Details Page, asynchronous call spans are indicated by an icon.
.NET Agent Instrumentation
The sections below show screenshots of instrumented asynchronous methods that you get out of the box with the TraceView .NET Agent.
HttpClient API (System.Net.Http.HttpClient)
The HttpClient API was introduced in the .NET Framework Version 4.5 for asynchronously sending and receiving HttpRequestMessages and HttpResponseMessages.
Below is an example of a request that makes a request to an external web API using the HttpClient.GetAsync method. The .NET agent also instruments the other methods in HttpClient including DeleteAsync, PostAsync, PutAsync, SendAsync, GetByteArrayAsync and GetStreamAsync.
The details reported for the HttpWebRequest span includes the RemoteURL of the external API, the HTTPMethod of the request, the HTTPStatus response code and the BytesDownloaded.
The example below shows a request made using the HttpClient.GetAsync method to an API that is hosted on a server that also has the .NET Agent installed. The “ IIS” The API request on the second server made a database request (ado-mssql).
The example below shows the trace for an asynchronous database method (ExecuteReaderAsync). The .NET Agent instruments additional asynchronous methods including ExecuteNonQueryAsync and ExecuteXmlReaderAsnyc.
The details reported for the ado-mssql span include Database (name of the database), Flavor (type of database server), QueryArgs (the query arguments reporting can be disabled) and the Query Text.
The TraceView .NET Agent instruments several asynchronous methods that have been added to the .NET Framework. The agent also supports the core feature of thread agility that is used in the processing of asynchronous methods. It enables users to isolate external web requests or database calls that might have performance issues. TraceView users have also been able to identify areas of their application where changing to asynchronous methods would help improve application performance!
Try it out!
Need performance monitoring for your .NET app that’s powerful and flexible? Ask us for a demo, sign up for our free trial, or just visit the Install Agents page within TraceView to get started with the new updates to our .NET instrumentation!