Export (0) Print
Expand All

PerformancePersist Sample: Provides Custom Performance Monitoring Data 

Download sample

Demonstrates how to expose performance information from an ATL Server Web application without losing that data when IIS is stopped and restarted.

Security noteSecurity Note

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.

Requirements

  • IIS

Building and Running the Sample

To build and run this sample

  1. Open the solution file, PerfPersist.sln, in the Visual Studio development environment.

  2. From the Build menu, click Build Solution.

  3. Register PerfServ by running the following command from the command line while in the directory with PerfServ's build output:

    PerfServ /Service
    
  4. Start PerfServ by running the following command from the command line:

    net start PerfServ
    
  5. Register the performance monitor data in the application DLL by running the following from the virtual directory created in step 2:

    regsvr32 PerfPersist.dll
    

    This directory will probably be C:\inetpub\wwwroot\PerfPersist\bin, but may be different if the IIS root is different

  6. From the Debug menu, click Start Without Debugging.

  7. 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.

  8. Submit a few requests and verify that the data is changing in the performance monitor.

  9. Run the following command from the command line to unload the application DLL:

    iisreset
    

    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.

Demonstrates

See Also

Community Additions

ADD
Show:
© 2015 Microsoft