Introduction
ISPAI Applications are meant to be run on Web-Servers and ISAPI developers like me often face ISAPI related performance issues. Here is the brief discussion on how to profile an ISAPI DLL and determine and solve the performance related issues.
ISAPI Applications are meant to run on High-load environment and the IIS Server has to respond to several hundred (ideally more than that) requests per second. To improve the performance of the ISAPI Applications first of all it is very important to understand how ISAPI works on IIS.
Understanding ISAPI Execution
There are two types of ISAPI programs for the web-servers – extensions and filters. These are DLL’s that run in IIS process address space thus interacting with IIS and other ISAPI DLL’s also. One thing has to be kept into mind that since web-servers (yes, ISAPI is not only for IIS but for lots of many servers-almost all server vendors provide the API’s to extend the functionality of the web servers) can handle more that one request at a time the ISAPI DLL can be called upon by more than one thread concurrently.
During the server startup (web-publishing service-w3svc) all the initialization takes place-it checks and load the ISAPI filters from the registry. Then the worker pool threads of IIS initializes. All these worker-threads accept the incoming HTTP requests and process them. If the ISAPI filters are configured to run than it loads the ISAPI Dll. ISAPI DLL is like any other regular DLL. The ISAPI Dll is then registered by calling GetExtensionVersion (which is called only once and contains registration data as name and version etc.)Then the HttpExtensionProc is called.The DLL remains in process address space until the execution is going on. During IIS Shutdown procedures all the loaded DLL are unloaded and all worker threads are stopped and IIS stopped.
Now, since ISAPI runs in the IIS process address space the chance of corrupting the memory space of IIS are high (although the thing worth noting is that IIS allows you to debug and test ISAPI Dll’s in isolation mode but that will reduce the server performance and will be an over-head). Most importantly the multithreading issues have to be taken into consideration. Since ISAPI DLLs are called upon by number of threads at a time thus our code needs to be “thread-safe”(also keep in mind not to lock resources in threads), avoid global data structures in your DLL’s unless absolutely needed otherwise use critical sections.
To determine the bottlenecks in your ISAPI application we need to do profiling the ISAPI DLL. Well, by profiling we mean examining the run-time behavior of the application to determine the performance of the various sections of the application and knowing which sections are taking how much time and thus detecting the bottlenecks of the application. Profiling an ISAPI DLL is very important part of determining and improving the performance of the DLL.
Profiling the ISAPI DLL
The steps to profile your DLL are:
- Build the DLL enabling the profiling and generation of map files in linker options see fig below

- Run this command at the command line on your ISAPI DLL. Prep /om /ft yourISAPI.dll This command will create a self-profiling DLL with _LL extension. This self-profiling file would keep the record for function-timing, function-counting, function-coverage. This would generate a file named yourISAPI._LL.
- Rename the original DLL to something else and name this DLL (with _LL extension as .DLL)
- Copy this profiled DLL and profile.dll to the web-server where you want the ISAPI to run.
- Copy the following file from yourDriveLetter:\ProgramFiles\Microsoft Visual Studion\VC98\Bin directory to the same place where you copied the DLL’s.
The files to be copied and put are – Profile.EXE , Profile.DLL, Profile.ini.
- Set the __ProfileBPI and __ProfileBPO system environment variables to the path of your PBI and PBO file that will be generated when you run the prep command.
- Stop and restart IIS so the profiled DLL is loaded.
- run the application , i.e send the request to your ISAPI so that ISAPI is executed and then stop the IIS after execution.
- run the following commands in the directory where PBI and PBO files are located.
Prep /m yourISAPI Plist yourISAPI
Note: DO NOT PUT IN EXTENSION-ONLY NAME OF THE DLL HAS TO BE GIVEN
Prep /m will merge the statistics gathered and generate .PBT file, and plist will format the .PBT file into text file. Now you can have the input of the PBT file to the text file you want.
For e.g plist yourISAPi > Profile1.txt On command line. You can easily see which section of your code is taking how much time.
And now that you have an analysis of the section based upon time(which crtical for web-applications) you can remove and take rectifications for the bottlenecks.
Hope this will help you all.