Several common methods for improving ASP. NET performance and scalability

Source: Internet
Author: User

Several common methods for improving ASP. NET performance and scalability

In ASP. NET, there are many ways to improve performance and scalability. In this article, I will introduce seven of my friends who can apply them to projects.

The topics in this article are as follows:

ASP. NETMPs queue Optimization

ASP. NETProcess configuration optimization

 

/Files/yanyangtian/upgrading asp.netsome common profiling features of scalability

ASP. NETMPs queue Optimization

 

We know that the ASP. NET processing mechanism is designed based on the pipeline model. There are many httpmodules in the ASP. NET pipeline. Each request to be processed is intercepted by the httpmodule when it passes through the ASP. NET pipeline. After processing, the request is sent to the next httpmodule. For example, sessionstatemodule intercepts the request, parses the session cookie in the request, and loads the appropriate session to httpcontext (you must know that each session has a session key saved in the cookie ).

 

At the same time, not all httpmodules in the pipeline are required. For example, if we do not use membership and Profiler provider in the project, we do not need to use the formsauthenticate module unless we do, another example is that if we do not use Windows authentication, we can remove the windowsauthenticate module.

 

By default, each time ASP. NET is started, the corresponding httpmodule is loaded according to the configuration file. The configuration files to be viewed vary according to the version of IIS.

 

For IIS 6, the default definition of the file for loading httpmodule is machine. config (located:

$ Windows $ \ Microsoft. NET \ framework \ $ version $ \ config).

 

For IIS 7 (and later versions), the default configuration file is applicationhost. config (Location: % SystemRoot % \ system32 \ inetsrv).

 

Here we use IIS 6 as an example. The machine. config configuration is as follows:

 

 

We can remove unnecessary modules from the Web. config of our site, as shown below:

 

 

 

ASP. NETProcess configuration optimization

 

ASP. net Processing Model configuration defines some asp. net, such as how many threads are enabled for request processing and how long each request processing thread expires.

 

Most of the time, we need to modify the default configuration according to the actual situation, especially as the current hardware becomes cheaper and more powerful, the configuration is modified accordingly, it can greatly improve the performance of the site.

 

In IIS 6, the configuration file for processing the model by default is still in machine. config, as shown below:

 

 

For IIS 7, it is configured in applicationhost. config, where the node name is the same as that of IIS 6.

Here, we still useIIS 6For example:

 

First, don't be alarmed when you see so many configuration items, because each item is very useful. Next, let's take a look at some of the most common ones.

Maxworkerthreads: This is the number of processing threads that can be started by the thread pool of each site. In IIS 6, the maximum number of threads that can be enabled for each logic is 20, and the dual-core CPU is 40.

 

If the server configuration is good, we can increase the number, such as 100. It should be noted that we need to configure this number according to the actual situation, but we have some general guidelines: the opening of each thread requires about 4 MB of memory, if the physical memory of our server is 2 GB, theoretically, we can run 500 processing threads at the same time.

 

However, in many cases, the memory of our servers cannot all be used here. Because the memory on the server is used in kernel mode and user mode. The so-called kernel mode is the core operation in windows, such as the Management thread, process, and driver for managing I/O devices. User mode is an operation other than kernel mode, for example, a bit from a user applicationProgramTo provide services, including IIS and SQL Server. All user-mode applications access resources through the execution layer running in kernel mode. For example, if the application wants to perform disk I/O, then the request is submitted to the kernel-mode execution layer to execute the request and return the result to the user-mode process that sends the request.

 

There are a lot of things here, so we will not go far. Let's get down to the truth.

 

If an ASP. Net Site application is not a CPU-consuming application, we can add more processing threads as appropriate. For example, if our applications provide external web services or upload and download files, and these operations do not put much pressure on the CPU, we can configure more processing threads.

 

Note that: Even though we have configured 100 or more threads, we don't know how to use these 100 threads. In addition, the more threads, the more complicated CPU scheduling. Here I think of a friend who asked me a question: the maximum processing thread we have configured is 1000. Why does our site's concurrent processing capability not reach 1000? I should give this one of the simplest replies: If you have 10 million yuan in your hand, will you spend all of your money at once? The same is true for the CPU. By configuring maxworkerthreads, we tell the server that a certain number can be reached to the maximum extent, but the server will definitely follow this limit, because there are many things that need to be considered and computed by the server, such as memory problems.

 

In addition, if there is no thread in the ASP. NET thread pool that can be used to process requests, the requests sent to the site will be added to the waiting queue.

You need to perform a lot of tests after configuration.

In addition, the following table lists the number of processing threads for reference:

 

Maxiothreads: By default, each logical processing has 20 threads. I/O processing threads are used to process I/O requests, such as read and write operations on files, database operations, and Web service calls. When setting this configuration, you need to consider the upload and download of files on the site. For details, refer to maxworkderthreads, uploading and downloading files is a memory-and disk-consuming operation. If the website has many files to upload, write, and download, we recommend that you use another server to process them again, and cache the relevant files in the memory, that is, build a File Cache Server.

 

Memorylimit: W3pw.exe is configured in IIS 6.ProcessThe maximum memory capacity available, which is a percentage value. If the memory used by the processing process of the site exceeds the capacity limit, IIS will restart a process and send the request to the new process, the old process was killed.Process). If only one ASP.. Net site, and there are no other memory-consuming applications, so we can try to change this configuration to 80 (that is, 80% of the server RAM ).

 

If an application on our server that may cause memory leakage is running, such as a COM component in the application, you can set this configuration value to a smaller value, in this way, after a memory leak occurs on the site, our processing process can be quickly killed to recycle some memory resources. Of course, this method of setting the minimum value is only a temporary solution. In the end, we need to completely solve the memory leakage problem.

 

In addition to processmodel, we can also set other configurations, such as system.net node. We can set the maximum number of requests for an IP address (2 by default), as shown below: 

This is now today!

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.