2025-04-27 07:49:33 -04:00

86 lines
6.3 KiB
HTML
Raw Blame History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<TITLE>Designing High-Performance ISAPI Applications</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
TempString = navigator.appVersion
if (navigator.appName == "Microsoft Internet Explorer"){
// Check to see if browser is Microsoft
if (TempString.indexOf ("4.") >= 0){
// Check to see if it is IE 4
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else {
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
}
}
else if (navigator.appName == "Netscape") {
// Check to see if browser is Netscape
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
Dim frmContents
On Error Resume Next
If Not Parent Is Nothing Then
Set frmContents = Parent.Contents
If Not frmContents Is Nothing Then
frmContents.Window.TOCSynch_Click
End If
End If
End Sub
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="MS-IT-LOC" Content="Internet Information Services">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1><A NAME="_k2_designing_high_performance_isapi_applications"></A><SUP></SUP>Designing High-Performance ISAPI Applications</H1>
<P>ISAPI is the highest-performance interface for Web applications. If you create an ISAPI extension or filter, chances are that it can outperform scripts in ASP pages or even components performing similar tasks. However, the inherent speed of the ISAPI interface does not mean that you can ignore performance and scalability considerations.ISAPI cannot utilize much of the application support services provided by ASP and COM. If you want your ISAPI application to maintain session state, for instance, you need to implement much of that session-state functionality .</P>
<P>The following are suggestions to improve the scalability and performance of your ISAPI extensions:
<UL type=disc>
<LI><B>Avoid ISAPI filters</B><EFBFBD>Avoid<B> </B>ISAPI filters unless adding an ISAPI filter is absolutely necessary to your application architecture. You should especially avoid filters that perform processing on raw incoming or outgoing data. If you determine that a filter is absolutely necessary, be sure to carefully optimize the main code paths through the filter event notification code.</li>
<LI><B>Create your own worker thread pool</B><EFBFBD>You should create your own worker thread pool so that the main I/O threads are free to accomplish other tasks. This option is only available for ISAPI extensions. </li>
<LI><B>Consider using asynchronous operations and I/O completion ports</B><EFBFBD>IIS<B> </B>supports asynchronous reading and writing by using the I/O completion ports, available in Windows NT 4.0 and Windows 2000 or later. Depending on the type of I/O operations being performed, asynchronous operations can make better use of the CPU time available. Asynchronous operations also work particularly well when implemented using a worker thread pool. </li>
<LI><B>Use the Win32 TransmitFile function</B>--When<B> </B>sending an HTML or image file, ISAPI extensions should use the Win32 TransmitFile function, which is exposed by the HSE_REQ_TRANSMIT_FILE ServerSupportFunction. </li>
<LI><B>Use Connection: Keep-Alive headers</B><EFBFBD>In most cases keeping persistent HTTP connections provides better performance than using non-persistent connections. </li>
<LI><B>Minimize need for thread synchronization</B><EFBFBD>By maintaining session state information with the request context, you can minimize the need for thread synchronization. If thread synchronization is required, make sure that critical sections are kept short.</li>
<LI><B>Consider other heap alternatives</B><EFBFBD>If your ISAPI application uses the heap intensively, you should consider other heap alternatives. Intensive use of the Windows<sup>&reg;</sup> heap can cause resource contention. Several memory allocation alternatives are worth exploring, including:
<UL type=disc>
<LI><B>Heap Partitioning<6E></B>Create multiple custom heaps, one for each thread, in addition to the default process heap. A separate, non-global lock controls each custom heap and lock contention is reduced.</li>
<LI><B>Cached Allocation</B><EFBFBD>Use custom allocation operations that operate at a middle layer between the object users and the heap. Calls to the Win32 heap are made infrequently and only for large memory blocks. These blocks are then subdivided and managed by the custom allocator.</li>
<LI><B>Stack Allocation<6F></B>Use the C run-time function <B>_alloca</B> to allocate memory for your objects on the stack instead of the heap. This method is feasible only for relatively small objects because the space available on the stack is limited. In addition, your newly allocated object is only available within the current functions, or functions called by that function. Once the current function returns to the main calling program, the storage allocated on the stack is lost.</li>
<LI><B>Object Encapsulation</B><EFBFBD>Include a buffer as a member data structure of a class. Use this buffer for tasks that require accesses to the Win32 heap.</li>
</UL>
</li>
<LI><B>Avoid using global locks within your ISAPI</B><EFBFBD>Global locks always adversely affect scalability.</li>
</UL>
<P>For more information about ISAPI extensions and filters, please see the section called <a href="http://go.microsoft.com/fwlink/?LinkId=1698" target=_blank><b>Developing ISAPI Extensions and Filters</b></a> or the section called <a href="http://go.microsoft.com/fwlink/?LinkId=1699" target=_blank><b>ISAPI Reference</b></a> in the MSDN Online Library..</P>
<hr class="iis" size="1">
<p align="center"><em><a href="../../../common/colegal.htm">&copy; 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
</BODY>
</HTML>