ASP speed trick five

zhaozj2021-02-16  125

One of the techniques: Improve the efficiency of using the Request collection to access an ASP collection to extract a value of time, occupying the process of calculating the 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, the code is written into the following form to speed up the script engine processing speed: start = request.form ("title") strfirstname = request.form ("firstname") strlastname = request.form ("Lastname") if len ("lastname) IF LEN (STRTITLE) strTitle = strTitle & "" If strFirstName = "" Then strFullName = strTitle & "" & strLastName Elseif Len (strFirstName) = 1 Then strFullName = strTitle & strFirstName & "." & strLastName Else strFullName = strTitle & strFirstName & "" & strLastName END IF

Tips 2: Direct access to the appropriate collection   If there is no choice, do not use the strpage = request ("page") to get the parameters, because this will search all the collection 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.

Third: 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 operations in ASP   Usually, data constitutes the actual content of the Web site. Therefore, optimize the ADO operation to accelerate the ASP code execution, it is useful:                                                                     *). 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 object variables. 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     The following code is executed: set gcmc = rsgc ("gcmc") set gccode = RSGC ("gccode" while not qgc.eof response.write "project name:" & gcmc & "(Project code:" & gccode & gccode ")" RSGC.MOVENEXT WEND   new code establishes references 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 times in the collection is less . Tips 5: Don't mix the script engine. We know that both VBScript can be used 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-8349.html

New Post(0)