Performance Optimization of ASP. NET 2.0 website applications

Source: Internet
Author: User
Tags website performance

Abstract:

Develop an application that quickly responds to user requestsProgramIs the goal and challenge of every developer! ASP. NET is designed for Speed Optimization and performance improvement. Its improvements are reflected in page compilation and automatic storage on the server. However, when your application executes a large number of requests at the same time, this improvement still cannot prevent performance degradation.

To write a high-performance application, you must balance the following four aspects that affect the performance:

Execution time: the time it takes to execute a request, from receiving the first byte to receiving the last byte.

Response time: the time taken from sending a request to receiving the first byte of the server response.

Scalability: This is mainly manifested in the resources (memory, CPU, or computer) allocated to applications by the server ).

Throughput: the number of requests that can be processed per unit of time (usually 1 second.

The following are several aspects that enable you to develop a high-performance application:

Status Management,

Data storage,

Page and server controls,

Web application,

CodePractice.

We will first explain from the first two aspects, in the next articleArticleThe content of the following three aspects and the caching technology will be described in detail in the Cache Optimization article.

Status Management:

The following are some suggestions for more effective execution status management:

Sessionstate statement:

When you do not need a session, disable the session status. Not all websites will save the session Status of each user. When you disable unnecessary session states, your website performance will be improved. Use the following code to disable the session status on the webpage:

1 <% @ Page enablesessionstate="False"  %>
2

If your page only needs to read the session value, you can set it to read-only. If you want to disable the session of the entire website, open the Web. config file and set the mode attribute of the sessionstate node to false. The Code is as follows:1 <SessionstateMode= "Off" />

Session State provider

You can set the mode you like to store session status data from the mode attribute of the sessionstate node in the web. config file. It supports the in-process mode, State server mode, SQL Server mode, and custom mode. Each mode has its own advantages in the selected environment. The in-process mode is the fastest mode to date. If you want to use session to store small and frequently changed data, this mode is your ideal choice. If you want to maintain the session status after restarting your server, the State server mode and SQL Server mode are good choices.

Data storage:

The following points describe how to store data more effectively:

ApplicationSQL Server Provider

SQL Server Provider can develop more efficient website applications and better scalability.

Apply SQL data reader

The sqldatareader class only retrieves data once during the entire running process. Therefore, when conditions permitSqldatareader class to replaceDataset, datatable, and so on, can bring higher performance to your application.

Application Stored Procedure

Use stored procedures instead of command statements as much as possible, because the stored procedures are compiled and executed, which improves the database processing speed.

Apply sqldatasource attributes

Replace the SQL condition statements that contain "where" or "sort by", and make full use of the relevant properties of sqldatasource (such as caching, filtering,AndSorting)
You can set the "enablecaching" attribute of the sqldatasource object to true to activate caching the Retrieved Data in the datasource. When you activate the cache, The sqldatasource object will perform operations such as filtering and sorting on the retrieved cache data. You can use the filterexpression and sortparametername attributes of the sqldatasource object to filter and sort data. This will certainly improve the performance of your website.

Viewstate Encryption
 
To improve security, you must encrypt and decrypt important data stored in viewstate, but this will affect the speed of your application. Encryption includes the size of an unloaded data added to the initialization of a loaded object. The larger the data size, the longer the time consumed. Therefore, viewstate data should be properly encrypted based on its importance.

Paging

As we all know, if you want to display the data of a given data source, you must use server controls such as: gridview or detailsview and set the data source. You mayOrDetailsviewTo filter records or columns of the data source and set its paging attribute to true. This paging technology is called User Interface paging ). To implement this function, the gridview control requests a special data source to obtain all the records required on the current page and ignores other data. This operation must be performed on each page, which of course results in a great waste of resources.

Another technology can implement this function. This technology is the data source paging technology. This technology will be implemented using the data source control, and performanceview is the processing class. When the gridview or detailsview is applied to this data source, the canpage attribute is set to true. In this way, the data source takes only the data on the current page. It can be seen that the data source page is more effective than the UI page. The only data source that can be paged is the objectdatasource class.

Cache

Application cache can be used by any other technology to improve the performance of your website .. Net Framework provides several channels for caching pages and methods for caching data in ASP. NET applications. You can cache important data or pages that remain unchanged in each request.

To make the cache more effective, see the following:

-Do not cache items that expire in a short period of time. cache cleaning and garbage collection are involved when each cache item expires.

-Do not cache too many cache items. This will consume more memory for each item. Some data that is easy to compute does not need to be cached.

Cache is so important that the ASP. NET Framework provides us with a variety of channels to gradually improve our website performance. These methods include caching application data, page output cache, and caching a part of a webpage and a cached part of the page.

For more information, see msdn.

The translation of this article is really tiring. Because there are some translation tasks that have been separated for several days in the middle, it has been used several times before translation. If there is a way out with English, please point out that I will go to work tomorrow, good night!

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.