TwentyVIs Improve ASP Performance and Appearance Tips Len Cardinal, Advanced Consultant, Microsoft Consulting Services George V. REILLY Microsoft Iis Performance Lead
Adapted from Nancy Cluts Article Developer Technical Engineer Microsoft Corporation 2000 April 2000
Directory Skills 1: Cocaine the frequently used data on the web server 2: Cocaine the frequently used data in Application or Session object 3: Cocard data and HTML on disk on the web server 4: avoid non-bustling Components Cacked in Application or Session Objects Tips 5: Do not use the database connection in Application or session objects 6: Reasonably use session object skills 7: Introduction to the code package in COM object is a feature. You must pre-design performance, otherwise you have to rewrite the application later. That is to say, what good strategies can make Active Server Pages (ASP) performance best?
This article describes how to optimize ASP applications and Visual Basic? Scripting Edition (VBScript). This article discusses many traps. The recommendations listed herein have been tested in http://www.microsoft.com and other sites, and the effect is very significant. This article assumes that you have developed ASP, including VBScript, and / or JScript, ASP Application, ASP Session, and other ASP inherent objects (Request, Response, and Server) have basically understood.
Typically, ASP performance depends primarily on many factors other than ASP code itself. We are not in an article to listen out all the information, and we list the resources related to performance at the end of this article. These links cover ASP and non-ASP topics, including ActiveX® Data Objects (ADOs, Component Object Models, Database, and Internet Information Server (IIS) configuration. These are some links we like - must go see.
Tips 1: Retrieve data from the typical ASP page that is often used on the web server, and converts the results into hypertileble language (HTML) on the back-end data store. Regardless of the speed of the database, retrieving data from memory is much faster than retrieving data from backend data storage. Reading data from a local hard drive is usually faster than retrieving data from a database. Therefore, the data can be cached on the web server (stored in memory or disk) to improve performance.
The cache is a traditional way of spatial exchange time. If your cached content is correct, then you can see performance will have a significant improvement. To make the cache valid, you must save the data that are frequently used frequently, and to recalculate these data required (moderate) large overhead. If the cache is some old data, it will cause memory waste.
Data that do not change often is a good cache candidate data, because you don't have to worry about the issue of data and database synchronization over time. Combination Box List, Reference Table, DHTML Debris, Extension Markup Language (XML) string, menu item, and site configuration variable (including data source name (DSN), Internet Protocol (IP) address, and web paths) are well cached. Candidate content. Note that you can cache the "representation" of the data without causing the data itself. If the ASP page is rare, the overhead of the cache is also large (for example, the entire product catalog), you should consider generating HTML in advance instead of replaying each request. Where is the data can be slow, what caokes strategy? Typically, the data can be cached in the memory or disk of the web server. The next two techniques tell these two methods.
Tips 2: Cocaine the frequently used data in Application or session objects ASP Application and Session objects provide a convenient container that makes data cache in memory. You can assign data to the Application and Session objects, which are kept in memory between HTTP calls. The session data is stored separately according to each user, and Application data is shared between all users.
When do you load the data into the Application or Session? Typically, the data is loaded when the Application or Session is started. To load data during the Application or Session startup process, the appropriate code should be added to Application_onstart () or session_onstart (). These functions should be in Global.asa, and if not, these functions can be added. This data can also be loaded during the first time. To do this, some code is added (or writing a reusable script function) to check if the data exists, if not, load data. This is a traditional performance technology called "inert calculation" - do not calculate this value before you know that you need a value. E.g:
Similar functions can be written for each data block required.
What format should store data? Any variant type can be stored because all script variables are variable. For example, you can store strings, integers, or arrays. Typically, you will save the contents of the ADO record set in one of these variable types. To get data from the ADO recordset, you can manually copy the data to the VBScript variable, one field. Use an ADO record set for jury function GetRows (), getString () or Save () (ADO 2.5), speed and easier. The details have exceeded the scope discussed herein, but a function is given below, indicating an array of record set data using getRows ():
(?? ADODB.Recordset)?? "Get Recordset, return as an ArrayFunction FetchEmploymentStatusListDim rs Set rs = CreateObject rs.Open select StatusName, StatusID from EmployeeStatus ?, _ dsn = employees; uid = sa; pwd = ;? FetchEmploymentStatusList = rs .Getrows ()? Return Data as an arrayrs.closset = Nothingend Function
For further improvements to the above, you can cache the HTML to a list instead of an array. The following is a simple example: "Get Recordset, return as HTML Option listFunction FetchEmploymentStatusListDim rs, fldName, sSet rs = CreateObject rs.Open select StatusName, StatusID from EmployeeStatus ?, _ dsn = employees; uid (ADODB.Recordset??)?? = SA; PWD = ;? s =?? & fldName & ?? & vbcrfrs.closset = Nothing "See Release EarlyfetChemploymentStatusList = S" Return Data As a stringend function
Under the appropriate conditions, the ADO recordset itself can be cached in the Application or Session scope. There are two warnings:
ADO must be labeled as a free thread must use a disconnected recordset. If you do not guarantee these two requirements, don't cache the ADO recordset. In the following "Non-Agile Components" and "Do not cache the connection", we will discuss the risk of storing COM objects in the Application or Session scope.
When you store the data in the Application or Session scope, the data will remain there until you change it in programming, the session expired or the web application is restarted. What if the data needs to be updated? To manually enforce Application data, you can access the ASP page that only administrators to update the data. Alternatively, you can automatically refresh the data from a function. The following example stores a timestamp with cache data and refreshs data after a while.
It is a good reason to use this command that these session has a meaning problem in the frameset set. ASP guarantees that only one request is executed at all times. This ensures that if the browser requests multiple pages for a user, only one ASP requests contact SESSION, which avoids the multi-threaded problem that occurs when accessing the session object. Unfortunately, all pages in a framework will be displayed in a serial manner, one pick one, not simultaneously. Users may have to wait for a long time to see all the frameworks. The story of this story: If some framework sets do not rely on Session, you must use the @ EnableSessionState = FALSE instruction to tell ASP.
There are many ways to manage the SESSION state to replace the use of the Session object. For a small amount (less than 4 kb), we usually recommend using cookies, queryString variables and implicit variables. For greater data, such as shopping trolley, backend databases are the most suitable choices. There are many articles about status management technology in the web server group. For more information, see Session Status Reference.
Tips 7: Package the code in the COM object If you have many VBScript or JScript, you can often move the code into the compiled COM object, so that performance can be improved. Compiled code is usually run faster than the interpreted code. Compiled COM objects can access other COM objects with "early binding", "Binding" is a more efficient way to call COM objects than "evening binding" used by the script.
There are also some advantages in the COM object (except for performance):
The COM object is conducive to the separation of logic and business logic. COM objects ensure that the code is reused. Many developers have found that code written in VB, C or Visual J is more easily debugged than ASP. The COM object also has a disadvantage, including initial development time and requires different programming techniques. Note that a small amount of ASP can cause performance to decline without performance improvements. This happens when a small amount of ASP code is encapsulated into a COM object. In this case, the system overhead of creating and calling the COM object exceeds the advantage of compiled code. Tests should be repeated to determine what kind of ASP script and combination of COM object code produces the best performance. Note that in terms of Microsoft Windows NT? 4.0 / IIS 4.0, Windows 2000 / IIS 5.0 has great improvements in scripting and ADO performance. Therefore, with the introduction of IIS 5.0, compiling code is reduced than the performance advantages of ASP code. For detailed discussion on the advantages and disadvantages of using COM in ASP, see ASP Component Guidelines and Programming Distributed Applications With and Microsoft Visual Basic 6.0. If you deploy COM components, you will test them in your load. In fact, all ASP applications should be subject to load testing.