The chief difference between the CGI programming model and the ISAPI programming model is that CGI creates a unique process for every request, while ISAPI does not. With CGI, every time an HTTP server receives a request it must initiate a new process, which, along with maintaining processes, is very resource intensive. This inherent limitation in CGI has made it difficult to develop responsive applications on the Internet.
The following diagram illustrates the difference between the CGI model and the ISAPI model.
In the ISAPI model, each request received by an HTTP server initiates the creation of a ECB data structure. Creating and maintaining a data structure is much easier and faster than initiating a new process. In addition, since the ECB and the extension are usually both running in the same process as IIS, the server can process requests faster and accommodate a higher volume of requests.
Finally, rather than using process isolation, the ISAPI model uses threads to isolate processing work items. Using multiple threads to synchronize work allows IIS to make more efficient use of system resources than is possible with the CGI model, or other models based on process isolation.
IIS 4.0 supports process isolation for ISAPI DLLs and scripts. IIS uses custom high speed methods to establish communication between the server process and the surrogate process housing the ISAPI DLLs thus providing robustness with high performance. Still, the ISAPI DLLs are only loaded once per isolated process. The application namespace boundary governs how the different processes are created and used.
When IIS receives a request for a particular extension, it loads the DLL into memory where it services other requests. For example, the following HTTP request causes IIS to create an instance of MyISAPI.dll
.
http://IIS/Applications/MyISAPI.dll?paramater1,parameter2
When IIS closes the extension, it calls the extension's TerminateExtension function, if present. You are encouraged to use TerminateExtension to clean up any threads and state information that the extension may have used in processing the request.
For more information about CGI, refer to http://hoohoo.ncsa.uiuc.edu/cgi/.