24 ASP skills for improvement performance and style

xiaoxiao2021-03-06  39

Introduction

Skill 1: Cache common data on the web server

Tip 2: Cache Common Data in Application or Session Objects

Tips 3: Cache data and HTML on web server disk

Tips 4: Avoid cache non-flexible components in Application or Session objects

Tips 5: Do not cache database connections in Application or Session objects

Skills 6: Wonderful session object

Tips 7: Package code in COM object

Tips 8: Late to get resources, release resources earlier

Skills 9: Execution outside the process will sacrifice reliability

Tips 10: Explicit use options

Tips 11: Use local variables in subroutines and functions

Tips 12: Copy common data to script variables

Tips 13: Avoid redefining arrays

Tips 14: Use response buffer

Tips 15: Batch in-embedded script and response.write statement

Tips 16: Use response.isclientConnected before starting a long time

Tips 17: Instantialective Objects using tag

Tips 18: Typelib binding using ADO objects and other components

Tips 19: Using the browser's verification capabilities

Tips 20: Avoid strings in the cycle

Tips 21: Enable browser and agent cache

Tips 22: Use Server.Transfer as much as possible to replace Response.Redirect

Tips 23: Directory URL tail plus slope

Tips 24: Avoid using server variables

-------------------------------------------------- ------------------------------

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

Testing on http://www.microsoft.com and other sites, and work is working. 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.

Skill 1: Cache common data on the web server

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.

Tip 2: Cache Common Data in Application or Session Objects

The ASP Application and 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 data at the Application or Session startup, add the corresponding code in the 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 demo function uses getRows ()

To return to the array of record set data:

'Take a record set, return to the 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 to 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.073, SQL: 9