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: https://msdn2.microsoft.com/en-us/library/fxk122b4(vs.71).aspx
· WCF counters: https://msdn2.microsoft.com/en-us/library/ms735098.aspx.
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:
<system.serviceModel>
<diagnostics performanceCounters="All" />
</system.serviceModel>
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
Anonymous
September 06, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/09/07/how-to-use-performance-counters-to-diagnose-performance-of-wcf-applications/Anonymous
September 19, 2007
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?Anonymous
October 30, 2007
Found these articles on WCF performance: http://blogs.msdn.com/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspxAnonymous
January 26, 2010
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?Anonymous
January 28, 2013
thank you, is it possible to use the trace.axd to trace WCF performance ?