Program | performance | Optimizing database access
Accessing the database will slow down the program quickly, but there are no databases and many sites are not. Do not use the embedded SQL statements to access the database, you can use stored procedures to access the database, which will win a lot of program performance, but also very flexible. By using stored procedures and with ActiveX Data Objects (ADO), you can control how the stored procedures are exported to the maximum extent possible.
Verify that the database is indexed because it directly affects the overall performance of the application. At the same time, pay attention to running the UPDATE STATISTICS program on the database to better track the data distribution. Note that some databases, such as Ms Access, are not suitable for enterprise applications, and SQL Server 7.0 or Oracle is better suited to do this.
Let SQL do the design work, including computing, adding, sorting, and grouping data. Do not write these features in other languages, you can write a query to complete.
Any field you want to evaluate is the simple syntax shown below:
SELECT Count (*) from Publishers WHERE state= ' NY '
If you want to calculate a special field, you must group by that field, otherwise, you will not work:
SELECT count (city), publishers GROUP by city
Then determine the sorting method:
SELECT * FROM tablename WHERE FieldName >50 OR fieldname< to by FieldName2, FieldName3
You still use an ODBC system or file DSN to connect to the database, or you can connect using a quick OLE DB technology. Using the latter, when you move a Web file, you no longer need to modify the configuration.
OLE DB is located between the application and the ODBC layer. In an ASP page, ADO is a program located on top of OLE DB. When ADO is invoked, it is first sent to OLE DB, which is then sent to the ODBC layer. You can connect directly to the OLE DB layer, and when you do this, you will improve server-side performance. How do you connect directly to OLE DB?
If you use SQL Server 7, use the following code as the connection string:
strconnstring = "dsn= ';D river={sql SERVER};" & _
"UID=MYUID; Pwd=mypwd; "& _
"DATABASE=MYDB; Server=myserver; "
The most important parameter is the "driver=" section. If you want to bypass ODBC and use OLE DB to access SQL Server, use the following syntax:
strconnstring = "Provider=SQLOLEDB.1; Password=mypassword; "& _
"Persist security info=true; User Id=myuid; "& _
"Initial catalog=mydbname;" & _
"Data Source=myserver; Connect timeout=15 "
Why is this important?
Now you may wonder why learning this new connection method is critical? Why not use a standard DSN or System DSN method? Well, according to the tests that Wrox in their ADO 2.0 Programmer's Reference books, if you use OLE DB connectivity, you have the following performance improvements than using DSN or Dsn-less connections:
Performance comparison
SQL Access
OLE DB DSN OLE DB DSN
Connection time: 18 82 Connection Time: 62 99
Repeat 1,000 time: 2900 5400 Repeat 1,000 record time: 100 950
This conclusion is published in Wrox's ADO 2.0 Programmer's Reference. The time is in milliseconds, and the time to repeat the 1,000 records is computed in the form of the server oil standard.
If possible, the user input is validated using client script to minimize the circular operation of the HTTP request.
If your browser has the ability to execute JavaScript or other scripts, be fully used to liberate server-side resources.
The following VBScript script runs on the user's browser side, checks the user information, and then submits it to the server:
< SCRIPT language= "VBScript" >
<!--
Sub Btnenter_onclick
Dim theform
Set theform = Document.myform
If IsNumeric (TheForm.Age.Value) Then
Theform.submit
Else
Msgbox "Please enter a numerical age."
End If
End Sub
-->
</script >
< FORM method= "POST" Name=myform action= "myfile.asp" >
Name: < INPUT typr= "text" name= "name" >
Age: < INPUT type= "text" name= "age" >
< INPUT type= "button" Name= "Btnenter" value= "Enter" >
</form >
Use local variables instead of global variables
Because local variables can be accessed quickly by the ASP script engine, the entire namespace does not have to be searched. Avoiding the redefinition of an array and allocating enough dimensions when the array is initialized can greatly improve efficiency. Doing so may waste some memory, but it does win speed, especially if the server has a lot of load.
Creating objects with < OBJECT > tags
If you need to refer to an object that might not actually be used, use the < OBJECT > tag to sample them instead of Server.CreateObject. The latter causes the object to be created immediately, while < object > is created when the object is first referenced.
For example, the following code demonstrates using the < OBJECT > tag to create an application-scoped Ad Rotator Object instance:
< OBJECT runat=server scope=application id=myads progid= "MSWC. AdRotator ">
</object >
You can then refer to it on another page:
Open "Option Explicit"
In VB and VBScript, you can use variables without explicitly defining them. However, opening the "Define variables explicitly" option will help improve program performance. Undefined local variables are slow because the entire namespace is searched before the variable is created to see if the variable already exists. So, please open "Option Explicit", which is a good programming habit.
Careful with Server.MapPath
Do not use server.mappath! unless you have to. Conversely, if you know the path, you use an explicit literal path to represent it. Using MapPath, IIS is required to retrieve the current server path, which means a special request for IIS, which reduces program performance. Another way to do this is to save the path information in a local variable, and when you need to use it, the server will not have to be overly requested.
Check How to Do
You can use the following tools to measure server performance: Task Manager,netmon and PerfMon. Measure the capacity of the server with WCAT (WEB Capacity analysis Tool). You can use WCAT to check how Internet Information services and network configurations respond to different client requests for content, data, and HTML pages. The results of the tests can be used to determine how to optimize the server and network configuration.
By optimizing the performance of ASP applications, Web site applications will become very fast and ultimately: when not needed, there is no need to do performance-impacting clicks.
Summarize
When it comes to ASP performance, there are a number of aspects that have been discussed in this article. However, for each specific