24 optimized ASP. NET performance (3 to 10)

Source: Internet
Author: User

3. Only enable authentication for the desired application.

By default, the authentication mode is Windows, or NTLM is integrated. In most cases, it is best to disable authentication in the Machine. config file and enable authentication in the Web. config file for applications that require authentication. Configure the application based on the appropriate request and response encoding settings. ASP. NET default encoding format is UTF-8. If your application is strictly ASCII, configure the application to use ASCII for a slight performance improvement.

Disable AutoEventWireup for applications.

In the Machine. config file, set the AutoEventWireup attribute to false, which means that the page does not match the method name with the event or hook the two (for example, Page_Load ). If Page developers want to use these events, they need to override these methods in the base class (for example, they need to rewrite Page. OnLoad for Page loading events, rather than using the Page_Load method ). If AutoEventWireup is disabled, the page will be slightly improved by leaving the event connection to the page author rather than automatically executing it.

Remove unused modules from the request processing pipeline.

By default, all functions of nodes in the Machine. config file of the server computer are retained to active. Based on the features used by the application, you can remove unused modules from the request pipeline for a slight performance improvement. Check each module and its functions and customize it as needed. For example, if you do not use session Status and output cache in an application, you can remove them from the list so that requests do not perform other meaningful processing, you do not have to execute the code for entering and leaving each module.

4. 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.

5. For applications that rely heavily on external resources, consider enabling network gardening on a multi-processor computer.

ASP. NET Process Model helps enable scalability on a multi-processor computer, distribute work to multiple processes (one CPU per worker), and each process sets the processor relationship to its CPU. This technology is called Web gardening. Enable Web gardening for your application if your application uses a slow database server or calls a COM Object with external dependencies (only two possibilities are mentioned here. However, before deciding to enable Web gardening, you should test how applications are executed in the Web garden.

6. 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.

7. 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.

8. 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. For more information, see SqlDataReader class. For information about how ASP. NET accesses data, see access data through ASP. NET.

9. Use SQL Server Stored Procedures for data access

Among all data access methods provided by. NET Framework, SQL Server-based data access is a recommended choice for generating high-performance, scalable Web applications. When using a hosted SQL Server Provider, you can use compiled stored procedures instead of special queries to obtain additional performance improvements.

10. Avoid single-threaded unit (STA) COM components

By default, ASP. NET does not allow any Stas COM component to run on the page. To run them, you must include the ASPCompat = true attribute in the. aspx file in the @ Page command. In this way, the thread pool used for execution is switched to the STA thread pool, and HttpContext and other built-in objects can be used for COM objects. The former is also a kind of performance optimization, because it avoids any call to mail multi-threaded units (MTA) to the STA thread. Using the sta com component may greatly damage the performance and should be avoided as much as possible. If you must use the sta com component, such as in any interop scheme, you should make a large number of calls during execution and send as much information as possible during each call. Also, be careful not to create any sta com components during page construction. For example, in the following code, the MySTAComponent created by a thread will be instantiated during page construction, and this thread will not run the STA thread of the page. This may have a negative impact on performance, because to construct a page, you must complete the sending and receiving process between the MTA and the STA thread.

Dim myComp as new MySTAComponent () Public Sub Page_Load () myComp. Name = "Bob" End Sub

The preferred mechanism is to postpone object creation until the above code is executed in the STA thread in the future, as shown in the following example.

Dim myComp Public Sub Page_Load () myComp = new MySTAComponent () myComp. Name = "Bob" End Sub

We recommend that you construct any COM components and external resources as needed or in the Page_Load method. Never store any Stas COM component in shared resources that can be accessed by other threads other than the threads that construct it. Such resources include resources such as cache and session status. Even if the STA thread calls the sta com component, only the thread that constructs the sta com component can actually serve the call, which requires sending and processing calls to the Creator thread. This mail may cause significant performance loss and scalability problems. In this case, consider the possibility of making the COM component an mta com component, or migrate code to make the object a hosted object.

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.