How to use performance counters to diagnose performance of WCF applications

There are many ways to diagnose the performance of WCF applications. Here is a simple one that uses performance counters to get some rough ideas. There are two categories of performance counters that you can use:

·         ASP.NET counters:

·         WCF counters:

ASP.NET Counters

For web-hosted applications, you can use ASP.NET counters to monitor the overall request processing status. They are enabled by default and they are of type PerformanceCounterInstanceLifetime.Global. So you can open the PerfMon tool to monitor the counters without doing any extra work. Here are the two interesting counters that I want to mention here:

·         Requests/sec

·         Request Execution Time

The first one tells the throughput of the whole web server for ASP.NET requests (including WCF ones). You may have many clients hitting the same server and thus you will see the overall throughput.

The second counter tells you how long (in milliseconds) it takes for the server to process each request. It measures the latency of the request processing. If the requests are processed sequentially, the value (converted into seconds) of this counter is the inverse of the first one. In general when the requests are processed concurrently, this is not true.

Performance counters are a mechanism for monitoring services that you can get without

WCF Counters

WCF performance counters are quite different. Here are major ones:

·         These counters are not enabled by default in V1. You have to do that through the config file.

·         All counters are of type PerformanceCounterInstanceLifetime.Process. All of the three different categories (Service, Endpoint, and Operation) are of this type which is also called “instanced based”. This means that in order to monitor the counters from PerfMon, you have to start the WCF application with the counters enabled. When the application exits, you cannot monitor the counter anymore.

·         The WCF counters are more finer grained than ASP.NET ones. You can monitor the performance of different service instances at different levels. To recap, the counter instance names have the following pattern:

(ServiceName).(ContractName).(OperationName)@(first endpoint listener address)

Here is the way of how to enable WCF performance counters through configuration:

   <diagnostics performanceCounters="All" />

The possible settings for the scope of service counters are Off, ServiceOnly, and All for WCF V1.

Here are the two interesting performance counters that we can use for performance analysis:

·         Calls Per Second

·         Calls Duration

These counters have similar properties as those for ASP.NET. But they are scoped to WCF service (endpoint or operation) level. The value of the second counter is a floating number in seconds. The accuracy is 0.001 second. So if your service is faster than 1000 requests/second in sequential processing, you would always see 0.000.

How to Use the Values of the Counters

Once you have the data captured in PerfMon, you will be able to tell which WCF service is the performance bottleneck. This is useful when you have very slow service operations. If you want advanced performance analysis, you would need more granular tools such as ETW tracing, performance profiles, custom tracing, and debuggers.

Lastly, before adding the performance counters to PerfMon, make sure that 1) you have them enabled from the configuration file, and 2) you have started the WCF application. For web-hosted service, you can ping the service from the browser first to make sure the service has been started.


Comments (5)

  1. natewhit says:

    Are you referring to IIS 7 which allows hosting of WCF Services for ASP.NET Including these counters?  My understanding in pre-iis7 you can host a WCF Service as a Windows Service–would ASP.NET requests/sec still include the WCF Service in this scenario?

  2. finnlake says:

    Hi Wenlong!

    As you probably know the performance counter names are limited to 128 characters. If they are longer the names are hashed by wcf to a not very user friendly name. Is there no way in wcf to override the names that are generated?

  3. thank you,

    is it possible to use the trace.axd to trace WCF performance ?

Skip to main content