PerformancePersist Sample: Provides Custom Performance Monitoring Data
Demonstrates how to expose performance information from an ATL Server Web application without losing that data when IIS is stopped and restarted.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To build and run this sample
Open the solution file, PerfPersist.sln, in the Visual Studio development environment.
From the Build menu, click Build Solution.
Register PerfServ by running the following command from the command line while in the directory with PerfServ's build output:
Start PerfServ by running the following command from the command line:
net start PerfServ
Register the performance monitor data in the application DLL by running the following from the virtual directory created in step 2:
This directory will probably be C:\inetpub\wwwroot\PerfPersist\bin, but may be different if the IIS root is different
From the Debug menu, click Start Without Debugging.
Run the Windows Performance Monitor and add counters for the object "Fibonacci Stats." These are the counters that are provided by the sample ATL Server application.
Submit a few requests and verify that the data is changing in the performance monitor.
Run the following command from the command line to unload the application DLL:
No performance monitoring data should be lost even though the application providing the data is no longer running. The service PerfServ is keeping this data persistent in shared memory. When the ATL Server application is started again by navigating to the original page, it will reattach to the same shared memory and continue where it left off.
How the Sample Persists the Performance Data
ATL Server request handlers are created for each request and their DLL is only loaded as long as it is needed. If an ATL Server application wants to provide custom performance data using the performance monitoring subsystem, this data must be persisted between request handler invocations. This sample shows two methods for persisting the data:
Use a COM object to maintain a global instance of a CPerfMon-derived object that manages custom performance counters.
The COM object is maintained by the ATL Server ISAPI DLL, which is loaded persistently by IIS. When a request handler starts, it requests this service from the ISAPI extension, and gets the CPerfMon object from the service. Alternately, this service could be added directly to a custom ISAPI DLL, but the method used by this sample does not require modification of the wizard-generated ISAPI DLL and is thus suitable for an environment with one generic ISAPI DLL servicing several application DLLs.
Use an external service process to maintain performance data.
The service process executable file exposes the IPerfCache interface, which the application DLL uses when it creates its CPerfMon-derived object. This ensures that if IIS is stopped or restarted for any reason that the performance data will not be lost even though the ISAPI DLL is no longer maintaining it.