When a website has a large volume of traffic, in addition to more reasonable implementation of functions and logic, you also need to pay attention to the server load and handle and configure the number of requests, I have not found many clear materials in this regard. Based on my understanding and network information, I have sorted out some theoretical knowledge and made specific settings and configurations for myself or everyone in the future, hope to make some help. The following are my own understandings, theories, and specific configurations. In order not to mislead me and more people, please criticize and testify if you find anything wrong.
Asp.net has many conditions that affect the number of concurrent requests, regardless of the program execution time and whether the program is blocked. It will be restricted by the number of TCP connections and the number of IIS connections on the server (which does not seem to be limited in Windows, limits on the CLR thread pool.
Server TCP restrictions: [HKLM \ System \ CurrentControlSet \ Services \ Tcpip \ Parameters] "enableconnectionratelimiting" = DWORD: 00000000. Change the registry key value to "0, for example, Windows 2003 Server does not have this restriction, for example, my own does not.
IIS connection limit: IIS6 and below, and metabase under % SystemRoot % \ system32 \ inetsrv. direct modification in XML files. For example, to modify the default asprequestqueuemax = "3000", you can set a larger queue for requests. Modify the default aspprocessorthreadmax = "25 ", set the concurrent request thread to a greater value. For details, refer to the relevant materials. Too many processes will take time to set the CPU switching thread. According to the online statement, the larger the number, the better, however, it can be set based on the concurrency and system performance. The iis7 configuration is different, and % SystemRoot % \ system32 \ inetsrv \ config \ applicationhost. in the config file, modify <serverruntime appconcurrentrequestlimit = "5000"/> and limit the number of concurrent requests,
IIS Manager> applicationpools> advanced settings, queue length: 1000 modify the queue length. HKLM \ System \ CurrentControlSet \ Services \ HTTP \ Parameters maxconnections to make greater changes.
. NET Framework restrictions
I think that after an Asp.net program runs, it does not care about different IIS versions. They have different lifecycles and IIS6 has different processes, however, I think the process should be managed by at least three thread pools. One CLR is responsible for the working thread pool of different request requests and one Io processing thread, there is also an unmanaged thread pool for the process. The initialization and maximum number of thread pools hosted can be configured and set by the program, the unmanaged thread pool is used to send requests to CLR for processing. When there are Io or other asynchronous operations, it processes unmanaged threads. Of course, we can control the managed thread pool.. Net version, which is different from the number of system CPUs and the number of initialization thread pools. For example, I currently use a single-CPU dual-core system, in. run the following code in the next MVC request of net4:
Int workthread = 0;
Int iothread = 0;
Threadpool. getmaxthreads (Out workthread, out iothread );
The maximum worker thread pool and I/O thread pool obtained are both 200. However, based on relevant information, this value is 100 x number of CPUs (multiple CPUs in dual-core mode ), the value obtained in the Windows program is larger, indicating that the number of threads given by the default system is different.
In different. in the. NET version, machine. <processmodel AutoConfig = "true"/> in config uses the default configuration.. Net in different versions, the default number of threads and other information are directly written. You can modify the machine by modifying it. some values of the node in config for different purposes. The following parameters are configured by default:
- Set maxworkerthreaders and maxiothreads to 100
- Set maxconnection to 12 * Number of CPUs
- Set minfreethreads to 88 * CPU usage
- Set minworkerthreads to 50
Maximum number of threads = (maximum worker threads * Number of CPUs)-minimum number of Idle threads. Of course, there are other important parameters.
These are all changes to the configuration files in IIS6 and iis7 classic modes. The ii7 integration mode is a little different. The maximum number of requests is determined by the following: maxconcurrentrequestspercpu: Limit the number of requests executed by each CPU, even if more threads are available. In. Net 3.5 and earlier versions, the default value is 12, and in. Net 4 is 5000. If it is set to 0, there is no limit; maxconcurrentthreadspercpu: Limit the number of threads that each CPU can process requests. The default value is 0. This is basically equivalent to no limit on the number of requests, and the <processmodel
Requestqueuelimit = "10000"/> added
The request queue is 10000, at % SystemRoot % \ system32 \ inetsrv \ config \ applicationhost. in config, <serverruntime appconcurrentrequestlimit = "10000"/> adds parallel request restrictions. For details, see relevant information.
This article also refers to other people's blogs and their own summaries. Some of them also need to be verified. As a reference data record for future testing, if you are not clear about it, Please treat it with a skeptical attitude, if something is wrong, correct it.