ASP speed trick five

zhaozj2021-02-16  79

One of the skills: improve the efficiency of using the Request collection

Access an ASP collection to extract a value of time, occupying the process of computing resources. Because this operation contains a series of searches for related collections, this is much slower than accessing a local variable. Therefore, if you intend to use a value in the Request collection multiple times in the page, you should consider storing it into a partial variable. For example, write code into the following form to speed up the script engine processing speed:

Strtitle = Request.form ("Title")

StrfirstName = Request.form ("firstname")

StrlastName = Request.form ("Lastname")

If len (strtitle) kil = strtitle & "

If strfirstname = "" "" "" & strlastname

Elseif len (strfirstname) = 1 THEN

Strfullname = startle & strfirstname & "." & strlastname

Else

Strfullname = starte & strfirstname & "& strlastname

END IF

Second: Direct access to the appropriate collection

If you don't have no choice, don't use strpage = request ("page") to get parameters because it searches all sets in order - QueryString, Form, Cookies, ClientCertificate, ServerVarible until the first match is found. The name of the value. This is lower than that of directly accessing appropriate collection efficiency, and is unsafe, unless it is absolutely guaranteed that this value does not appear in another collection.

For example, it may be desirable to search for the web server name that meets the customer request, which is implemented in the Request.ServerVarables collection in each query. However, if other collections also include values ​​called "server_name" (key names are not case sensitive), when using Request ("Server_Name", the error result is obtained. All in all, the appropriate collection should be accessed directly as much as possible.

Tips 3: Use the response.isclientConnected property before the time of operation

Use response.isclientConnected is a useful way to observe whether users are still connected to the server and being loaded into the ASP creation. If the user disconnects or stops downloading, we don't have to waste the server's resource to create a web page, because the buffer content will be discarded by IIS. So, for those web pages that require a lot of time calculations or resources, it is worth checking if the tourists are offline at each stage:

... code to create first part of the page

If response.isclientconnected the

Response.flush

Else

Response.end

END IF

... Code to create Next Part of Page

Tips 4: Optimize ADO operation in ASP

Usually, the data constitutes the actual content of the web site. So, optimize the ADO operation to accelerate the ASP code execution, it is useful:

a. Only the required columns: When all the ADO record sets are turned on, the table name (ie, select *) should not be automatically used unless you need to get all columns. Use separate columns to make reduces the amount of data that is sent to the server or from the server. Even if you need to use all columns, naming each column alone will also get the best performance because the server does not have to explain the names of these columns. b. Use the stored procedure as much as possible. The stored procedure is a pre-compiled program that contains a ready-made execution plan, so performing faster than the SQL statement.

c. Use the appropriate cursor and lock mode. If all the jobs are only read from the record set, and display it on the screen, then use the default only forward, read-only record set. The less work is used to maintain the details of the record and lock, the higher the performance.

d. Use the object variable. When traversing a record set, a method that can improve performance is to use object variables to point to members in the collection. E.g:

While Not Rsgc.eof

Response.Write "Project Name:" & RSGC ("GCMC") & "(Project Code:" & RSGC ("GCCode") & ")

"

RSGC.MOVENEXT

Wend

You can use the code to be rewritten to speed up:

SET GCMC = RSGC ("GCMC")

Set gccode = rsgc ("gccode")

WHILE NOT RSGC.EOF Response.Write "project name:" & gcmc & "(Project Code:" & gccode & ")

RSGC.MOVENEXT

Wend

The new code establishes a reference to object variables, so you can use object variables instead of actual variables, which means that the work of the script is reduced because the number of indexes in the collection is less.

Skill 5: Don't mix the scripting engine

We know that you can use VBScript in the ASP page or JScript. But use JScript and VBScript simultaneously on the same page, it is not desirable. Because the server must instantiate and try cache two (rather than one) script engine, this increases the system burden to some extent. Therefore, from performance consideration, multiple script engines should not be mixed in the same page.

转载请注明原文地址:https://www.9cbs.com/read-14879.html

New Post(0)