ou always want the software you write to have great performance. The reason isn't shockingusers look to software to quickly and efficiently handle their workload. Often times, meeting this performance requirement (whether it is explicit or implied), can be a difficult, even daunting task. Tuning an application to perform at its peak level involves a thorough understanding of the architecture and environment into which you will deploy your application. However, you can't truly begin to optimize an application's performance if you don't understand how to empirically measure that performance. From this perspective, your application must emit enough data to enable real time performance monitoring.
Imagine for a moment that a new client has commissioned you to develop a .NET component. Your client gives you fairly simple specifications for the component. Your application must process comma-separated data contained within flat-files, and insert this content into a SQL Server database. The application itself does not even need to expose a graphical user interfacea simple console application will suffice. Beyond these very basic instructions, the client also imparts this golden nugget of information: Your component must process over 1,000 transactions per second.
How would you go about proactively publishing enough empirical data from your component so that, at the end of the day, you can accurately address the question of application performance? The answeruse custom performance counters.
What Are Performance Counters?
|Figure 1: The Windows Performance Monitor application allows you to select and view the current data associated with any registered performance counters.|
Performance counters are discrete sets of data published by an executing application, service, or operating system process. Windows 2000, Windows XP, and Windows Server 2003 intrinsically support counters. They exist for the express purpose of diagnosing and analyzing throughput, bottlenecks, and so on.
Performance data is organized according to objects, counters, and instances. Objects represent the application or process that publishes the performance data. A counter is the actual measurement point. You use an instance to further delineate processes. Instances are optional.
Data is exposed for inspection via the Windows Performance Monitor console (see Figure 1). This interface allows you to select specific counter instances to view graphically or log to a file.
You can see that all of the plumbing is in place to monitor and view performance counters. Now let's discuss how to publish performance data from within your application.