Comprehensively optimize the performance of ASP applications (reproduced)

xiaoxiao2021-03-06  46

The ASP itself is not a scripting language, which only provides an environment that makes the script program in an HTML page to run, and the most common scripting language in the ASP is VBScript. Although the Script language of the ASP is simple, it is not a simple matter that an ASP program is optimized. Nowadays, the domestic network bandwidth is very limited, the network is crowded, how to make your ASP application can run quickly into every ASP programmer's dream. Then follow me to speed up your ASP program! One. Optimization of the operational database We use ASP's most important use to operate the database, how to complete these actions faster? 1. Don't use "SELECT * ..." to use "Select * ...", please pick it up, for example, there are 10 fields in a table, but you will only use one of the fields (name). "SELECT NAME", instead of using "select * from your yurtable". You may say, I am doing this, but if there is 50 fields in a table, what do you do when you need to use 23 fields? In order to save typing and find the trouble of finding the name of the field, you will not necessarily use "SELECT NAME, SEX, AGE ... from YourTable"! Actual proven, try to pick up the fields you need to use the SELECT statement will be at least 5% of your ASP program. 2. When using the system stored procedure (for MS SQL Server), complete a reading operation, using the SQL statement and the stored procedure can also be completed, but the use of the stored procedure will greatly speed up the speed of the read operation, which is improved. The speed of your ASP program runs. 3. Note Your cursor usage If you just read a table, please use the Forward-Only, Read-Only cursor, because this cursor read the database is the fastest, especially your read data. Under the case of large amount. 4. Don't open the useless independent record, maybe you are laughing, will I open the unused record set? Yes, you will of course, for example, when you generate a tree-type recordset, you have to open the father record set and the corresponding sub-record set, and even the granules of the granule, in fact, you can use the Data Shaping technology provided by ADO. Alternatively opens multiple independent records, the running speed of the program will be accelerated. (For Data Shaping, you can refer to ADO Help) 5. Be sure to close the open record set object and connection (Connection) Object Some friends are always strange why their own ASP program is running quickly, but how many times is more and more slower? There is even a server crash. This happens, it is likely that you open too many records objects and connections, but it is not caused by it.

Use the following method to close: YourRecordset.close set YourRecordset = Nothing set youConnection = Nothing 6. How do you get the data of the record set? Isn't it use YourRecordset (field number) or YourRecordset ("Field Name")? In fact, there are other ways, now we will 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.624 seconds 2.611 seconds 0.602 seconds 2.613 seconds 2.613 seconds 0.594 second average response time 2 .895 seconds 2.931 seconds 1.625 seconds 0.594 seconds, this way, everyone can see, I will talk about how 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. Optimization method for the use of ASP built-in objects 1. Try to minimize the use of the session object and Application object Although the two objects provided in the ASP provide a lot of help, it is reasonable for both objects, do not abuse. Because of a large number of use of these two objects will greatly increase the burden on the server, severely consume system resources. It will also make your ASP program run as older. 2. It is necessary to close the object that is no longer used (especially session and Application). It does not timely shut down the object you use can cause the system running slowly. Maybe you will ask, is SESSION and Application not automatically disappear? It is completely correct, the system automatically triggered session_onend and application_onend events without any operation, but a large number of users frequently read the server, the server will keep the SESSION, Application objects that have not been used for a long time. If you don't close your use, the consequences of the application and Application will be unimaginable. The method of closing is: SET object = Nothing three. Rational use of include files, let's include the files that come in here, and the file content is all ASP programs, that is, let's put some public functions. In a file, and other pages that are likely to call the functions are included.

转载请注明原文地址:https://www.9cbs.com/read-80333.html

New Post(0)