Fully optimize ASP program performance

Source: Internet
Author: User
ASP itself is not a scripting language, it simply provides an environment for scripting programs that embed in HTML pages, and the most common scripting language in ASP is VBScript. Although the scripting language of ASP is simple, it is not easy to get an ASP program to run optimally.

Now the domestic network bandwidth is very limited, the network is very crowded, how to make their own ASP applications can run quickly become the dream of every ASP programmer. Then follow me to speed up your ASP program together!


A The optimization method of operation database

The main purpose of our use of ASP is to operate the database, how to complete these actions faster?

1. Do not use "SELECT * ..." arbitrarily.

Try to pick up the fields you need, for example, there are 10 fields in a table, but you will only use one of these fields (name) and use "SELECT name from Yourtable" instead of "select * from Yourtable". You might say, I did, but what would you do if you had 50 fields in a table and you needed 23 of them? In order to save typing and find the name of the corresponding field, you will not necessarily be honest with the "select Name,sex,age ... from yourtable"!

As a practical proof, picking up the fields you need to use the SELECT statement will be at least 5% faster for your ASP program.

2. Use system stored procedures whenever possible (for MS SQL Server)

Sometimes a read operation can be done with SQL statements and stored procedures, but using a stored procedure will greatly speed up the completion of the read operation and increase the speed at which your ASP program runs.

3. Notice how your cursor is used

If you are simply reading a table, use the forward-only,read-only cursor, because this cursor is the quickest to read the database, especially if you have a large amount of read data.

4. Do not open a useless set of independent recordsets

Perhaps you are smiling, I will open the record set that does not use? Yes, of course you will, for example, when generating a tree recordset, you have to open the parent recordset and the corresponding child Recordset, and even a grandchild recordset, in fact, you can use ADO to provide the data shaping technology to replace the open multiple independent Recordset, which will speed up the speed of the program. (for the use of data shaping can refer to ADO Help)

5. Be sure to remember to close the open Recordset object and the connection (Connection) object

Some friends always wonder why their own ASP program at the beginning of the run fast, but more than a few times to run more and more slow it? There is even a server panic situation. When this happens, it's likely that you've opened too many Recordset objects and connected (Connection) objects and ended up not shutting them down. Use the following method to close:

Yourrecordset.close

Set yourrecordset=nothing

Set yourconnection=nothing

6. Comparison of methods for obtaining database data

How did you get the data from the recordset? Is it yourrecordset (field number) or Yourrecordset ("field name")? In fact, there are other ways to use, now we compare it (100 records):



Rs ("Field name")

Rs ("field name"). Value

Rs ("Field number")

Set method

Database response Time

2. 967 seconds.

2. 936 seconds.

1. 650 seconds.

0. 586 seconds.



2. 824 seconds.

2. 914 seconds.

1. 611 seconds.

0. 602 seconds.



2. 893 seconds.

2. 943 seconds.

1. 613 seconds.

0. 594 seconds.

Average response time

2. 895 seconds.

2. 931 seconds.

1. 625 seconds.

0. 594 seconds.



You know, the first three ways you can see it, I'll tell you how to use the fourth method (set method):

Dim strSQL

Strsql= "Select Name,sex,age from Yourtable"

Dim RS

Set rs=server.createobject ("ADODB. RECORDSET ")

Rs.Open strsql,conn,1,1

Const fieldsorder=2

Dim Objorder

Set Objorder=rs (Fieldsorder)

Response.Write Objorder ' Set method



Two Optimizing methods for using ASP's built-in objects

1. Minimize the use of Session objects and application objects

Although the two objects provided in the ASP provide a great help for our programming, the two objects should be used reasonably and not abused. Because the use of these two objects will greatly increase the burden on the server, seriously consuming system resources. It will also make your ASP program run as slow as an old cow.

2. To promptly close objects that are no longer in use (especially session and application)

Shutting down the objects you use in a timely manner can cause the system to run slowly. Perhaps you will ask, the session and application can not automatically disappear? Completely correct, the system default 30 minutes users without any action will automatically trigger Session_OnEnd and Application_OnEnd events, but a large number of users frequently read the server, the server will be a long time to maintain those have no use of the session, Application objects, if not in time to close the use of the session and application consequences will be unbearable to imagine.


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.