asp.net program Optimization selection 1th/2 page _ Practical Tips

Source: Internet
Author: User
Tags garbage collection memory usage
1, Database access performance optimization
connection and shutdown of the database
Accessing a database resource requires creating a connection, opening a connection, and closing a connection several operations. These processes need to exchange information with the database more than once to authenticate and consume server resources. Asp. NET provides a connection pool (Connection pool) to improve the performance impact of opening and shutting down the database. The system places the user's database connection in the connection pool, takes out when needed, recovers the connection when it is closed, and waits for the next connection request. The size of the connection pool is limited, and if the connection pool is maximized to create a connection, it will have a significant impact on performance. Therefore, after the database connection is established, the connection is opened only when the operation is really needed, closed immediately after use, so as to minimize the time to open the database connection, and avoid the occurrence of exceeding the connection limit.

Using Stored Procedures
A stored procedure is a set of precompiled SQL statements stored on a server, similar to a batch file in a DOS system. The stored procedure has the function of immediate access to the database, and the information processing is very rapid. By using stored procedures, you can avoid multiple compilations of commands, which reside in the cache after a single execution, and need to call only the binary code in the cache at a later time. In addition, the stored procedure runs on the server side, independent of the ASP.net program, easy to modify, and most importantly, it can reduce the transmission of database operation statements in the network.

Optimizing query Statements
Asp. NET, the ADO connection consumes a large amount of resources, the longer the SQL statement runs, the longer it takes to occupy the system resources. Therefore, try to use optimized SQL statements to reduce execution time. For example, do not include subqueries in query statements, make full use of indexes, and so on.

2. Be sure to disable debug mode
Always remember to disable debug mode before you deploy a production application or perform any performance measurement. If debug mode is enabled, the performance of your application can be significantly affected.

3. Cache data and page output whenever possible
ASP.net provides simple mechanisms that cache the page output or data when you do not need to dynamically compute page output or data for each page request. In addition, you can optimize the performance of these pages by designing the page and data requests that you want to cache, especially in areas where there is a large amount of traffic expected in the site. Using caching appropriately, compared to any WEB forms functionality of the. NET Framework, can improve the performance of your site, sometimes at a very high order of magnitude. There are two points to be aware of using the ASP.net caching mechanism. First, do not cache too many items. Caching each item has overhead, especially in terms of memory usage. Do not cache items that are easy to recalculate and rarely use. Second, the expiration of the cached items is not too short. Items that expire quickly can cause unnecessary turnover in the cache and often result in more code cleanup and garbage collection work. If you care about this issue, monitor the Cache total turnover Rate performance counters associated with the ASP.net applications performance object. High turnover may indicate a problem, especially if the item is removed before it expires. This is also called memory pressure.

4, select the data viewing mechanism for the page or application  
        Depending on how you choose to display data on a WEB forms page, there is often an important trade-off between convenience and performance. For example, a DataGrid Web server control might be a quick and easy way to display data, but its overhead is often the largest in terms of performance. In some simple cases, you might be able to render data yourself by generating the appropriate HTML, but customization and browser orientation can quickly offset the extra benefits you get. Repeater Web server controls are a trade-off between convenience and performance. It is efficient, customizable and programmable.
5, using the SqlDataReader class for fast forward-only data cursors  
       The  sqldatareader class provides a way to read a data-only stream retrieved from a SQL Server database. If you are creating a asp.net application that allows you to use it, the SqlDataReader class provides a higher performance than the DataSet class. This is because SqlDataReader uses SQL Server's native network data transfer format to read data directly from a database connection. In addition, the SqlDataReader class implements the IEnumerable interface, which also allows you to bind data to a server control.

6, using the HttpServerUtility.Transfer method to redirect between pages of the same application
using the Server.Transfer syntax , this method is used in the page to avoid unnecessary client redirection.
current 1/2 page   1 2 Next read the full 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.