How to enhance the ASP program performance

xiaoxiao2021-03-06  51

How to enhance the ASP program performance

--- Excerpted from the "Tianji Net"

Introduction performance is a very important feature. You need to design a performance indicator in advance, otherwise you will rewrite the program for this. That is to say: How do you optimize the ASP program? This paper proposes some techniques that optimize ASP applications and VBScript, many techniques and defects have been discussed. The recommendations listed here have been tested at http://www.microsoft.com and other sites, they have work very well. This article assumes that you have basic knowledge developed by ASP, including VBScript or JScript, ASP applications, ASP SESSION, and other ASP built-in objects (Request, Response, and Server). Usually, ASP execution performance is far more than just ASP code itself! The end of this article lists resources related to performance, which contains ASP and non-ASP portions, including ActiveX Data Objects (ADO), Component Object Model (COM), Database, and Internet Information Server (IIS) )Configuration. In addition to these, there are some very good links worth watching. Tips 1: The data typically used in the web server is typically: the ASP page retrieves the data from the background store, then forms the result in the hypercurrent markup language (HTML). Regardless of the speed of the database, retrieving data from memory is much faster than from the background storage device. Reading data from a local hard drive is usually very fast. Therefore, improve performance can be implemented by data on the cache server, whether it is cacked in memory, or in the local hard disk. The cache is a classic "spatial change time". If the cache is appropriate, you can see a significant performance improvement. In order to make the cache valid, it is necessary to ensure that cache data is often reused, and it is also cumbersome. The cache filled with old data is a waste of memory. The data that does not change often is a better object of the cache because it is not necessary to consider the synchronization operation after this data update. Combination box, reference table, DHTML code, extended tag language string, menu, and site configuration variables (including data source names DSNS, Internet protocol address IP, and web paths) are well cache objects. Note: To cache data expressions instead of the data itself. If an ASP page changes frequently and firms (such as the entire product catalog), you should consider pre-generating HTML instead of each time a request is taken. Tips 2: Application and Session objects in the data ASP that are cached in Application or Session objects are a convenient container that caches data in memory. You can assign data to Application and Session objects, which will remain in memory during HTTP calls. The data in the session is for each user, and the data in Application is shared by all users. When will I need to load data in Application and Session? Typically, the data is loaded when the application starts or when the session begins. In order to load data at this time, add the appropriate code to Application OnStart () or Session OnStart (). These functions are located in the file global.asa, and if it does not exist, add it. You can also transfer it when the data is first required, add code to the ASP page, check if the data exists, if you don't find it, you will be transferred.

Here is an example that represents a classic performance processing technology called "lazy evalution": until it is needed, then calculate. The example is as follows: <%

Function geteMPloymentStatusList

DIM D

D = Application ("EMPLOYMENTSTATUSLIST")

IF d = "" "

'FetChemploymentStatusList Function (Not Shown)

'Fetches Data from DB, Returns an Array

D = fetchemploymentstatuslist ()

Application ("EMPLOYMENTSTATUSLIST") = D

END IF

GetEmploymentStatusList = D

END FUNCTION

%>

A similar function code can be written for different data. What format should be saved in? Any variable type can be used because all script variables are different. For example, it can be saved as a string, integer or data. Typically, the contents of the ADO record set are stored in one of these variable types. In order to remove data from the ADO record, you need to copy data from the VBScript variable, each time a field. Use any ADO record set function functions getRows (), getString () or Save () (ADO 2.5) is very fast and simple, here there is a function, describing how to use getRows () Return record set data:

'Get Recordset, Return as an 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 () Return Data as an Array

Rs.close

SET RS = Nothing

END FUNCTION

A deeper tip of the above code is to cache HTML for the list. Here is a simple example:

'Get Recordset, Return AS HTML OPTION 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.080, SQL: 9