25+ ASP Tips (reproduced) Redhawk for improved performance and style

xiaoxiao2021-03-06  67

25 ASP Tips for Improved Performance and Style

Len Cardinal - Microsoft Consulting Services senior adviser George V. Reilly - Microsoft IIS Performance director Updated: April 2000 rewrite Nancy Cluts according to Nancy Cluts article (English) - Developer Technology Engineer Microsoft Corporation Abstract: This paper provides an optimized ASP application Techniques for programs and VBScript.

Introduction performance is a feature. You need to pre-design performance or rewrite the application in the future. In other words, what is a good policy for optimizing the Active Server Pages (ASP) application performance? This article provides many techniques for optimizing the ASP application and the "Visual Basic (R) script editor (VBScript)". Discuss many traps and defects. The recommendations listed herein are tested on http://www.microsoft.com and other sites, and work is normal. This article assumes that you have basic understandings for ASP development, including VBScript and / or JScript, ASP Application, ASP Session, and other ASP internal objects (requests, responses, and servers). The performance of ASP, usually more than just depends on the ASP code itself. We don't want to cover all the names in an article, only listing resources related to performance. These links include ASP and non-ASP topics, including an "ActiveX (R) Data Object (ADO)," Part Object Model (COM) ", database, and Internet Information Server (IIS)" configuration. These are the links we like - please pay attention to them. Tips 1: Cache Cache Common Data Typical ASP Pages Retrieve data from the backend database, and then convert the results to Hypertext Markup Language (HTML). Regardless of the speed of the database, it is much more fast from the memory retrieval data to retrieve data from the backend database. Reading data from local hard drives is usually more than retrieving data from a database. Therefore, performance can be improved by cache data on a web server (in memory or disk). The cache is a trade-off of typical space and time. If you just caching data, you will see performance will have an amazing improvement. To make the cache effect, it must maintain frequently reused data, and the cost of recalculating these data is expensive or expensive. If the cache is full of spam, it is a waste of memory. Data that do not change often is also a cached candidate data because you don't have to worry about data and database synchronization issues. Combination box, reference table, DHTML debris, scalable markup language (XML) string, menu item, and site configuration variable (including data source name (DSN), Internet Protocol (IP) address, and web paths) are candidate data. . Note that you can cache data indicating instead of the data itself. If the ASP page does not change frequently, and the cost of the cache is also very high (for example, the entire product catalog), consider the first HTML, rather than re-drawing each time. Where should data should have, what caching strategies? Data often buys on the web server memory or web server disk. The following two techniques discuss these options. Tips 2: Cache Common Data ASP Application and Session objects in Application or Session objects provide a convenient container for cache data in memory. You can give the Application object or give the data object to the SESSION object, which will remain in the memory in the HTTP call. The session data is stored by user, and the Application data is shared between all users. When will I load the data into the Application or Session? Typically, load data when the Application or Session starts. To load the data at the Application or Session startup, add the corresponding code in the following two functions: Application_onstart () or session_onstart (). These two functions should be in Global.asa; if not, these functions can be added. You can also load data when data is required for the first time.

To make the above, add some code (or write a reusable scripting function), which checks the data in the data and loads data when the data does not exist. This is an example called a classic performance technology called slow-calculated - not calculated before you need it. Please see example: <% Function geteMPloymentStatusList

DIM D

D = Application ("EMPLOYMENTSTATUSLIST")

IF d = "" "

'Fetchemploymentstatuslist function (not displayed)

'Take data from DB, return array

D = fetchemploymentstatuslist ()

Application ("EMPLOYMENTSTATUSLIST") = D

END IF

GetEmploymentStatusList = D

END FUNCTION

%>

Similar functions can be written for each piece of data required. What format should be stored in any format? Any variable type can be stored because all script variables are different. For example, you can store strings, integer or arrays. Typically, you will save the contents of the ADO record set in one of these variable types. To get the data derived by the ADO recordset, you can manually copy the data into the VBScript variable, each time a field. Use an ADO recordset reserved function getRows (), getString () or Save () (ADO 2.5), which will be faster. Complete and detailed content has exceeded the scope of this article. The following demonstration function uses getRows () to return an array of recordset data: 'Take a record set, return in array

Function FetChemploymentStatusList

DIM RS

SET RS = CreateObject ("AdoDb.Recordset")

Rs.open "Select StatusName, Statusid from Employeestatus", _

"DSN = Employees; UID = SA; PWD =;"

FetChemploymentStatusList = rs.getrows () 'Returns data in an array

Rs.close

SET RS = Nothing

END FUNCTION

Further improvements to the above example should be HTML of the list instead of cache an array. Here is a simple example: 'Take a record set, return with the "HTML Options" list

Function FetChemploymentStatusList

DIM RS, FLDNAME, S

SET RS = CreateObject ("AdoDb.Recordset")

Rs.open "Select StatusName, Statusid from Employeestatus", _

"DSN = Employees; UID = SA; PWD =;"

S = "

CopyRight © 2020 All Rights Reserved
Processed: 0.038, SQL: 9