ASP. NET Website performance optimization [2]

Source: Internet
Author: User
Tags website performance
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 create an ASP. NET application Program 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 Code The mystacomponent created by a thread is instantiated during page construction, and this thread is not the sta thread that will run 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.
The preferred mechanism is to postpone object creation until it will be executed in the sta thread later.
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.
11. migrate call-intensive COM components to managed code
. NET Framework provides a simple way to interact with traditional COM components. The advantage is that the new platform can be used while the existing investment is retained. However, in some cases, retaining the performance overhead of the old component makes it worthwhile to migrate the component to the managed code. Every situation is different. The best way to determine whether to migrate components is to measure the Running Performance of web sites. We recommend that you study how to migrate any COM component that requires a large number of calls for interaction to managed code.
In many cases, it is impossible to migrate legacy components to managed code, especially when a web application is initially migrated. In this case, one of the biggest performance barriers is to mail data from an unmanaged environment to a hosted environment. Therefore, in interactive operations, perform as many tasks as possible at any end, and then make a large call instead of a series of small calls. For example, all strings in the Common Language Runtime Library are Unicode, so all strings in the component should be converted to unicode format before calling managed code.
In addition, after processing any COM objects or local resources, release them. In this way, other requests can use them and minimize the performance problems caused by later requests to the garbage collector to release them.
12. Use early binding in Visual Basic. Net or JScript code
In the past, one of the reasons why developers like to use Visual Basic, VBScript, and JScript was their so-called "non-typed" nature. Variables do not need explicit type declarations and can be created simply by using them. When the data is allocated from one type to another, the conversion is automatically executed. However, this convenience will greatly damage the performance of the application.
Visual Basic now supports type-safe programming by using the option strict compiler command. For backward compatibility, ASP. NET does not enable this option by default. However, to achieve optimal performance, we strongly recommend that you enable this option on the page. To enable option strict, include the strict attribute in the @ page command, or include this attribute in the @ control command for user controls. The following example shows how to set this attribute and calls four variables to show how this attribute causes a compiler error.
JScript. Net also supports non-type programming, but it does not provide compiler commands that force early binding. If any of the following conditions occurs, the variable is bound late:
It is explicitly declared as an object.
Is a field of the class without type declaration.
Is a special function or method member without explicit type declaration, and cannot deduce the type from its use.
The last difference is complicated, because if the JScript. Net compiler can deduce the type based on the usage of the variable, it will be optimized. In the following example, variable A is bound early, but variable B is bound late.
The following is a reference clip:
VaR;
VaR B;
A = "hello ";
B = "world ";
B = 0;
To achieve optimal performance, assign a type to the JScript. Net variable when declaring it. For example, var a: string.

[To be continued ...]

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.