Asp.net program optimization selection page 1/2

Source: Internet
Author: User

1. database access performance optimization
Database Connection and Shutdown
To access database resources, you need to create a connection, open a connection, and close the connection. These processes need to exchange information with the database multiple times for authentication, which consumes server resources. ASP. NET provides a Connection Pool to improve the impact of enabling and disabling databases on performance. The system places the user's database connection in the connection pool. If necessary, the connection is taken out. When the connection is closed, the connection is withdrawn and the next connection request is waited. The size of the connection pool is limited. If you still need to create a connection after the connection pool reaches the maximum limit, the performance will be greatly affected. Therefore, after a database connection is established, the connection is enabled only when operations are required. The connection is closed immediately after use, so as to minimize the time for opening the database connection and avoid exceeding the connection limit.

Use stored procedures
Stored procedures are a set of pre-compiled SQL statements stored on the server, similar to the batch processing files in the DOS system. Stored Procedures provide the ability to access databases immediately and process information quickly. Using the stored procedure can avoid multiple compilation of commands. After one execution, the execution plan will reside in the cache. In the future, you only need to directly call the binary code in the cache. In addition, the stored procedure runs on the server and is independent from the ASP. NET program to facilitate modification. The most important thing is that it can reduce the transmission of database operation statements over the network.

Optimize Query statements
In ASP. NET, the ADO connection consumes a considerable amount of resources. The longer the SQL statement runs, the longer the system resources are occupied. Therefore, try to use optimized SQL statements to reduce execution time. For example, a query statement that does not contain a subquery statement makes full use of indexes.

2. Disable the debugging mode. 
Remember to Disable debug mode before deploying production applications or performing any performance measurements. If the debug mode is enabled, the performance of the application may be greatly affected.

3. cache data and page output whenever possible 
ASP. NET provides some simple mechanisms to cache the output or data of these pages when you do not need to request dynamic computing page output or data for each page. In addition, by designing pages and data requests to be cached (especially in areas where the site is expected to have a large amount of communication), you can optimize the performance of these pages. Compared with any Web form function of. NET Framework, using the cache appropriately can improve the performance of the website. Sometimes this increase is more than an order of magnitude. There are two points to note when using the ASP. NET cache mechanism. First, do not cache too many items. Each item in the cache has an overhead, especially for memory usage. Do not cache items that are easy to recalculate and rarely used. Second, the period of validity allocated to cached items should not be too short. Items that expire soon will result in unnecessary turnover in the cache, and often lead to more code cleanup and garbage collection work. If you are concerned about this issue, monitor the Cache Total Turnover Rate performance counters associated with ASP. NET Applications performance objects. High turnover rate may indicate problems, especially when items are removed before expiration. This is also called memory pressure.

4. Select a data view mechanism suitable for pages or applications 
There are often important trade-offs between convenience and performance based on how you choose to display data on a Web form page. For example, the DataGrid Web server control may be a convenient and quick way to display data, but its overhead is often the largest in terms of performance. In some simple cases, it may be very effective to generate an appropriate HTML to present your own data, but custom and browser targeting will quickly offset the extra benefits you get. The Repeater Web Server Control is a compromise between convenience and performance. It is efficient, customizable, and programmable.
5. Use the SqlDataReader class for fast data-only cursor 
The SqlDataReader class provides a method for reading data streams only retrieved from the SQL Server database. If you are allowed to use an ASP. NET application when creating it, The SqlDataReader class provides higher performance than the DataSet class. This is because SqlDataReader uses the Local Network Data Transmission Format of SQL Server to directly read data from the database connection. In addition, the SqlDataReader class implements the IEnumerable interface, which allows you to bind data to server controls.

6. Use HttpServerUtility. Transfer to redirect between pages of the same application  
Use the Server. Transfer syntax to avoid unnecessary client redirection by using this method on the 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.