ASP speed trick

xiaoxiao2021-03-05  52

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 more than access

A local variable is much slower. 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

Tips 2: Direct access to the appropriate collection If not do not choose, do not use this form of strpage = request ("page") to get the parameters, because this will search all sets in order - QueryString, Form, Cookies, ClientCertificate, ServerVarible until the name of the first match value is found. 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, using response.isclientConnected is a useful way to observe whether the user is still connected to the server and is 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. Therefore, for those web pages that require a lot of time calculations or resources, it is worth checking whether the tourists have departed in 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, data constitutes the actual content of the Web site. Therefore, optimize the ADO operation to accelerate the ASP code execution, very useful: a. Select only the required columns: When opening the ADO record set, unless you need to get all the columns, you should not automatically use the table name (ie SELECT *) . 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. For example: While Not Rsgc.eof Response.Write "Project Name:" & RSGC ("GCMC") & "(Project Code:" & RSGC ("GCCode") & ")" RSGC.MOVENEXT Wend can be rewritten as below Code to speed up: set gcmc = rsgc ("gcmc") set gccode = RSGC ("gccode") WHILE RSGC.EOF RESPONSE.WRITE "project name:" & gcmc & "(Project Code:" & gccode & ") "RSGC.MOVENEXT WEND new code establishes references for 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 script engine We know that the ASP page can be used in both VBScript, or JScript can also be used. 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.

(Source: Bette)

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

New Post(0)