How to optimize the performance of ASP applications-application techniques

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 the 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):
Program code
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. Maybe you would ask,
can session and application not disappear automatically? Completely correct, the system default 30 minutes users without any action will automatically trigger the Session_OnEnd and Application_OnEnd events, but a large number of users frequently read the server, the server will be a long time to keep those who have no use
Session,application objects, if not in time to close the use of the session and application consequences will be unbearable to imagine.
The Shutdown method is:
Set Object =nothing
Three Reasonable use of Include files
What we are talking about here is a file contained in the form of <!--#include file= "xxx"-->, and the contents of the file are all ASP programs, which means that you put some common functions into a file and include them in other pages that might call the function.
It is recommended that you do not place all functions in a single containing file. Because when you include this file on other pages, the server side is precompiled, it's possible to have hundreds of functions in a containing file, and you just want to use one of these functions, which is worth the candle. So, as much as possible to split your include file into multiple small inclusion files. This also can improve the running speed of the program OH.
Four Optimization methods for VBScript language
1. Use system functions as much as possible instead of the functions you write
For example, if you want to split a regular string ("Sss,ddd,fff,ggg"), you do not have to use what mid (), InStr, etc. functions to analyze, in fact, VBScript provides a function of split (), so that both save time, and improve the speed, why not?
2. Reduce the use of dynamic arrays
3. Develop the habit of declaring variables in advance as much as possible
Don't underestimate this, declaring a variable in advance will speed up the interpretation execution time of the program. On the contrary, never declare variables, not only the program is difficult to read, the entire program in the execution efficiency of the server will be greatly reduced.
Five Other aspects of the optimization method
1. Use <%%> embed into HTML tags as much as possible in an ASP file, rather than using a Response.Write approach, such as:
Program code
<body>
<%if OK =1 then%>
Hello! world!
<%end if%>
</body>
is far more than:
<%
Response.Write "Response.Write "<body>"
If OK =1 Then
Response.Write "Hello! world! "
End If
Response.Write "</body>"
Response.Write "%>
Run faster, especially if your ASP file is larger. Because, the second way increases the server-side interpretation time, thus reducing the performance of the ASP program.
2. Try to do an action with an ASP file
Many people like to do in an ASP program at the same time, such as add, delete, search, and so on multiple actions, do not think that this is effective use of the file, on the contrary, the result is that the application is slow to run a lot of speed.
The addition, deletion, lookup, etc. should be split into a single stand-alone ASP file to complete. This makes the file not too large, reduces the burden of server-side interpretation execution, and is quick to read.
Well, after our overall optimization, is your ASP application running more stable and faster?

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.