Web. config optimizes website Performance Settings

Source: Internet
Author: User
Tags net thread website performance

ASP. net2.0 has many secrets that will greatly improve performance and scalability once you discover it. For example, in membership and profile provider, there is a secret to quickly implement authentication and authorization. In addition, the HTTP pipeline of Asp.net can avoid unnecessary code in each request. More than that, the Asp.net thread can make full use of its performance. The browser's page fragment cache mechanism (not the server cache) Can Save download time during repeated accesses. After the interface is loaded, it provides a fast and smooth experience for your website. Finally, CDN and the appropriate use of HTTP cache headers can make your website fast. In this article, you can learn some skills to improve the performance of your Asp.net website.

Questions to be discussed:
Optimal pipeline Optimization
Asp.net process best practices
Before proceeding to Asp.net
Content Transmission Network
Cache Ajax requests in the browser
Optimized Cache Mechanism
Optimize page loading speed to improve user experience
To optimize profile provider of Asp.net 2.0 as much as possible.
How to query the membership table without website layout
DoS Attacks
The above tips can be used for any Asp.net 2.0-based website, especially websites that use membership and profile provider.
1. Optimal pipeline Optimization
Some Asp.net default httpmodules manage the request pipeline and each request. For example, sessionstatemodule intercepts every request and analyzes the session cookie to load the appropriate session in httpcontext. however, not all modules are required. For example, if you do not need membership, you do not need to configure the formsauthentication module. If you do not need Windows authentication, you do not need to configure windowsauthentication, these modules are only contained in the pipeline and execute some unnecessary code for each request. The default module is defined inMachine. config ($ windows $/Microsoft. NET/framework/$ version $/config)
As follows:
<Httpmodules>
<Add name = "outputcache" type = "system. Web. caching. outputcachemodule"/>
<Add name = "session" type = "system. Web. sessionstate. sessionstatemodule"/>
<Add name = "windowsauthentication"
Type = "system. Web. Security. windowsauthenticationmodule"/>
<Add name = "formsauthentication"
Type = "system. Web. Security. formsauthenticationmodule"/>
<Add name = "passportauthentication"
Type = "system. Web. Security. passportauthenticationmodule"/>
<Add name = "urlauthorization" type = "system. Web. Security. urlauthorizationmodule"/>
<Add name = "fileauthorization" type = "system. Web. Security. fileauthorizationmodule"/>
<Add name = "errorhandlermodule" type = "system. Web. Mobile. errorhandlermodule,
System. Web. Mobile, version = 1.0.5000.0,
Culture = neutral, publickeytoken = b03f5f7f11d50a3a "/>
</Httpmodules>

If you want to remove these default settings, you only need to add the <remove> node in your web. config.
<Httpmodules>
<! -- Remove unnecessary nodes and increase the request speed -->
<Remove name = "session"/>
<Remove name = "windowsauthentication"/>
<Remove name = "passportauthentication"/>
<Remove name = "anonymousidentification"/>
<Remove name = "urlauthorization"/>
<Remove name = "fileauthorization"/>
</Httpmodules>
The above configuration applies to database-based form authentication websites that do not require any session support. Therefore, these nodes can be deleted.
2.asp.net Process configuration optimization
The Asp.net process model performs some process-level settings, such as the number of threads used by Asp.net, the timeout time, and the number of requests waiting for the completion of input and output. There are many restrictions by default. Currently, hardware is getting cheaper and G-level memory servers are widespread. Therefore, Process configuration optimization can provide more system resources and extensions.
Generally, Asp.net's mashine. config configuration is as follows:
<System. Web>
<Processmodel AutoConfig = "true"/>
</System. Web>
You should change this configuration and use some values to set different attributes to customize the working mode of the Asp.net thread. As follows:
<Processmodel
Enable = "true"
Timeout = "infinite"
Idletimeout = "infinite"
Shutdowntimeout = "00:00:05"
Requestlimit = "infinite"
Requestqueuelimit = "5000"
Restartqueuelimit = "10"
Memorylimit = "60"
Webgarden = "false"
Cpumask = "0 xffffffff"
Username = "machine"
Password = "autogenerate"
Loglevel = "errors"
Clientconnectedcheck = "00:00:05"
Comauthenticationlevel = "Connect"
Comimpersonationlevel = "Impersonate"
Responsedeadlockinterval = "00:03:00"
Responserestartdeadlockinterval = "00:03:00"
AutoConfig = "false"
Maxworker threads = "100"
Maxiothreads = "100"
Minworkerthreads = "40"
Miniothreads = "30"
Servererrormessagefile = ""
Pingfrequency = "infinite"
Pingtimeout = "infinite"
Asyncoption = "20"
Maxappdomains = "2000"
/>
Except the following values, some default values are used:
Maxworkerthreads: by default, each process has 20 threads. On a dual-core server, the system allocates 40 threads to Asp.net, which means Asp.net can process 40 concurrent requests simultaneously on the dual-core server. To add threads to each Asp.net process, I have set 100. If your application's CPU is strong and requires more requests, you can set this attribute. Especially when your network uses a large number of WebServices or uploads/downloads a large amount of data, this will not transfer the pressure to the CPU. When Asp.net runs out of all threads, it stops receiving more responses. Requests are queued until other working threads are released. This often happens when the website receives more than expected clicks. In this case, if you have a backup CPU, increase the number of threads of the process.
Maxiothreads: The default value is 20. In the dual-core server, the system will provide 40 I/O threads to Asp.net. I/O requests for reading and writing files on the website, reading databases, WebService calls, and HTTP requests. You can set it to a higher level, especially when your website performs concurrent upload/download and WebService calls.
Minworkerthreads: When the Asp.net free working thread falls below this value, Asp.net pushes some requests to the queue. Therefore, you can set a low value to increase the current number of requests. Of course, this value cannot be set too low, because the website needs to perform some background processing and parallel processing, which all require some threads to run.
Miniothreads: It is equivalent to minworkerthreads, but only for the I/O process. It can be set lower than in case of, because I/O Parallel Processing threads have no problems.
Memorylimit: specifies the maximum memory usage. It specifies the percentage of memory occupied by all systems and the maximum number of memories that can be used when the system processes. If your website is on the server and there are no other processes that use memory, you can set it to a higher level, such as 80. if your website has a memory leakage problem, you 'd better set this value a little lower, so that the leaked memory will be released soon, so that the website will run normally. Especially when you use COM components to cause memory leakage. Of course, this is only a temporary solution. In the end, you still need to solve the problem of Memory leakage.
In addition to processmodel, Asp.net can also set the maximum number of requests for a single IP Address:
<System.net>
<Connectionmanagement>
<Add address = "*" maxconnection = "100"/>
</Connectionmanagement>
</System.net>
The default value is 2, which is too low. This means that each IP Address can have at most two requests to your website, which may cause request congestion. It is set to 100. If necessary, you can set a higher value.

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.