Notes for ASP Acceleration

Source: Internet
Author: User

I. Improve the efficiency of using the request set

Accessing an ASP set to extract a value is a time-consuming and computing resource-consuming process. This operation contains a series of searches for related sets, which is much slower than accessing a local variable. Therefore, if you want to use a value in the request set multiple times on the page, you should consider storing it as a local variable. For example, you can write the code below to speed up the processing of the script engine:

Strtitle = request. Form ("title ")
Strfirstname = request. Form ("firstname ")
Strlastname = request. Form ("lastname ")
If Len (strtitle) Then strtitle = strtitle &""
If strfirstname = "" Then strfullname = strtitle & "" & strlastname
Elseif Len (strfirstname) = 1 then
Strfullname = strtitle & strfirstname & "." & strlastname
Else
Strfullname = strtitle & strfirstname & "" & strlastname
End if

2. directly access the appropriate set

If there is no choice, otherwise do not use strpage = request ("page") to obtain parameters, because this will search all the sets in order-querystring, form, cookies, clientcertificate, and servervarible until the name of the first matching value is found. This is less efficient and insecure than directly accessing an appropriate set, unless it is absolutely guaranteed that this value will not appear in another set.
For example, you may want to search for the name of the web server that meets the customer's request, which is achieved by searching for "SERVER_NAME" in the request. servervarables set in each query. However, if other sets also contain values named "SERVER_NAME" (key names are case-insensitive), an error is returned when request ("SERVER_NAME") is used. All in all, access the appropriate set as directly as possible.

3. Use the response. isclientconnected Attribute before time-consuming operations

Using response. isclientconnected is a useful way to check whether the user is still connected to the server and loading the web page created by ASP. If you disconnect or stop downloading, you do not need to waste resources on the server to create a webpage, because the buffer content is discarded by IIS. Therefore, for web pages that require a large amount of time computing or resource usage, it is worth checking whether the viewers are offline at each stage:

...... Code to create first part of the page
If response. isclientconnected then
Response. Flush
Else
Response. End
End if
...... Code to create next part of page

4. Optimize ADO operations in ASP

Generally, data constitutes the actual content of a web site. Therefore, it is very useful to optimize ADO operations to accelerate ASP code execution:
A. select only the required columns: When opening the ADO record set, the table name (select *) should not be used automatically unless all columns are obtained *). Using a separate column means reducing the amount of data sent to or from the server. Even if you need to use all columns, naming each column independently will achieve the best performance, because the server no longer needs to explain the names of these columns.

B. Use stored procedures as much as possible. Stored procedures are pre-compiled programs that contain a prepared execution plan, so they are faster than SQL statements.

C. Use the appropriate cursor and lock mode. If all the work is to read data from the record set and display it on the screen, the default record set can only be moved forward and read-only. The less detailed ADO is to maintain records and locks, the higher the execution performance.

D. Use object variables. When traversing a record set, one way to improve performance is to use object variables to point to Members in the set. For example:

While not rsgc. EOF
Response. Write "Project name:" & rsgc ("GCMC") & "(project code:" & rsgc ("gccode ")&")"
Rsgc. movenext
Wend

You can rewrite the following code to speed up execution:

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 creates an object variable reference, so you can use the object variable instead of the actual variable, which means that the script engine is less effort, because the number of indexes in the set is reduced.

V. Do not mix script Engines

We know that you can use VBscript or JScript on the ASP page. However, JScript and VBScript cannot be used on the same page at the same time. Because the server must instantiate and try to cache two (rather than one) script engines, which increases the burden on the system to a certain extent. Therefore, in terms of performance, you should not mix multiple script engines on the same page.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.