ASP. NET Website performance optimization [3]

Source: Internet
Author: User
13. Make all modules in the request pipeline as efficient as possible
All modules in the request pipeline have the opportunity to be run in each request. Therefore, requests are quickly triggered when they enter and exit the module. Code It is critical, especially in code paths that do not use module functions. The throughput test is executed when modules and configuration files are used and not used separately, which is very useful for determining the execution speed of these methods.
14. Use the httpserverutility. Transfer Method in the same applicationProgramPage redirection
Use the server. transfer syntax to avoid unnecessary client redirection by using this method on the page.
15. Adjust the number of threads for each auxiliary process of the application if necessary
The request structure of ASP. net tries to strike a balance between the number of threads executing the request and the available resources. An application that uses sufficient CPU power is known. This structure determines the number of requests that can be executed simultaneously based on the CPU power available for requests. This technology is called thread-control. But under some conditions Algorithm Not very effective. By using the pipeline instance count performance counter associated with the performance object of ASP. NET applications, You can monitor thread-control in perfmon.
When a page calls external resources, such as database access or XML Web Services requests, the page requests usually stop and release the CPU. If a request is waiting for processing and a thread in the thread pool is free, the waiting request will start to be processed. Unfortunately, sometimes this may lead to a large number of concurrent requests and many waiting threads on the Web server, which have adverse effects on server performance. Generally, if the gate factor is the response time of external resources, too many requests are waiting for resources, which is not helpful for the Web server throughput.
To alleviate this problem, you can manually set the number of threads in the process by changing the maxworkerthreads and maxiothreads attributes of the machine. config configuration file node.
Note that the auxiliary thread is used to process ASP. NET requests, while the IO thread is used to provide services for data from files, databases, or XML Web Services.
The value assigned to these attributes is the maximum number of threads in each CPU type in the process. For dual-processor computers, the maximum number is twice the set value. For a four-processor computer, the maximum value is four times the set value. In any case, it is best to change the default value for computers with four or eight CPUs. The default value can be used for computers with one or two processors. However, for computers with more processors, one hundred or two hundred threads in a process may cause more disadvantages.
Note that too many threads in the process will often reduce the server speed, because the operating system will spend the CPU cycle on the maintenance thread rather than processing the request due to extra context switching.
16. Use the Garbage Collector and Automatic Memory Management of the Common Language Runtime Library as appropriate
Be careful not to allocate too much memory to each request, because the Garbage Collector must do more work more frequently. In addition, do not point unnecessary pointers to objects because they will keep objects active and avoid objects containing the Finalize method as much as possible, because they will lead to more work in the future. In particular, do not release resources in finalize calls, because resources may always consume memory before they are recycled by the garbage collector. At last, this problem often causes a devastating impact on the performance of the Web server environment, because it is easy to exhaust a specific resource while waiting for finalize to run.
17. If there is a large web application, consider executing pre-Batch compilation.
Each time a first request to a directory is sent, a batch compilation is performed. If pages in the directory are not analyzed and compiled, this function analyzes and compiles all pages in the directory in batches to make better use of disks and memory. If this takes a long time, a single page is quickly analyzed and compiled so that the request can be processed. This feature brings ASP. NET performance benefits because it compiles many pages into a single assembly. Accessing a page from a loaded assembly is faster than loading a new assembly on each page.
The disadvantage of batch compilation is that if the server receives many requests for pages that have not yet been compiled, the performance may be poor when the web server analyzes and compiles them. To solve this problem, you can execute pre-Batch compilation. Therefore, you only need to request a page from the application before it is activated, regardless of the page. Then, when the user visits your site for the first time, the page and its assembly will have been compiled.
There is no simple mechanism to know when batch compilation will take place. Wait until the CPU is idle or no more compiler processes (such as csc.exe (C # compiler) or vbc.exe (Visual Basic compiler) Start.
Avoid changing the assembly in the \ bin directory of the application. Changing the page will cause re-analysis and compilation of the page, and replacing the assembly in the \ bin directory will cause full re-Compilation of the directory.
On a large site that contains many pages, a better way is to design different directory structures based on the frequency of page replacement or Assembly planned. Pages that do not often change can be stored in the same directory and pre-compiled at a specific time. Frequently changed pages should be in their own directories (each directory can contain hundreds of pages at most) for quick compilation.
Web applications can contain many subdirectories. Batch compilation occurs at the directory level, not the application level.
18. Do not rely on exceptions in the code
Exceptions greatly reduce performance, so you should not use them as a way to control normal program processes. If the code may cause exceptions, perform this operation. Do not capture exceptions before processing the status. Common solutions include checking null, assigning a value to a string that is analyzed as a numeric value, or checking a specific value before applying a mathematical operation. The following example shows the code that may cause exceptions and test whether code in a certain status exists. The two generate the same results.
The following is a reference clip:
Try
{
Result = 100/num;
}
Catch (exception E)
{
Result = 0;
}
//... To this.
If (num! = 0)
Result = 100/num;
Else
Result = 0;
19. Use httpresponse. Write to concatenate strings
This method provides very effective buffering and connection services. However, if you are executing extensive connections, use multiple response. Write calls. The technology shown in the following example is faster than the connection string using a single call to the response. Write method.
The following is a reference clip:
Response. Write ("");
Response. Write (mystring );
Response. Write ("B ");
Response. Write (myobj. tostring ());
Response. Write ("C ");
Response. Write (mystring2 );
Response. Write ("D ");
20. Keep the buffer closed for special reasons.
Disabling web form page buffering can cause a large amount of performance overhead.
[To be continued ...]

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.