Twenty-eight skills to improve ASP performance and appearance

xiaoxiao2021-03-06  243

introduction

Performance 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 covers 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: Cocaine the frequently used data on the web server

Typical ASP Pages Retrieve data from backend data storage, then convert the results into hypertext tag language (HTML). 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, Extended Markup Language (XML) string, menu item, and site configuration variable (including data source name (DSN), Internet Protocol (IP) address, and web paths) are well cache 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.

Tip 2: Cocaine the frequently used data in Application or Session object

The ASP Application and Session objects provide a convenient container that provides the 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. For example: (?? EmploymentStatusList) (?? EmploymentStatusList) <% Function GetEmploymentStatusListDim dd = Application If d = ?? Then 'FetchEmploymentStatusList function (not shown)' fetches data from DB, returns an Arrayd = FetchEmploymentStatusList () Application = dEnd IfGetEmploymentStatusList = Dend function%> You can write a similar function for each data block you need. 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 generators using getRows () returns record set: 'get recordset, return as an arrayfunction fetchemploymentStatusListdim 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 Arrayrs.CloseSet rs = NothingEnd Function of The above example is further improved, and the HTML can be cached as 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 =?

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