ASP.NET thread related configuration

  • 2020-05-19 04:30:09
  • OfStack

1, (maxWorkerThreads * CPU logical quantity) -minFreeThreads

For example, two CPU default configurations, maxWorkerThreads=100 and minFreeThreads=176, can only have a maximum of 24 worker threads at the same time. No matter here < system.net >

< connectionManagement >

< add address="*" maxconnection="8" / >

< /connectionManagement >

< /system.net > The value of this configuration, after testing, no matter what maxconnection is here, is finally calculated from the above calculation formula.

2. maxconnection, this value is the number of threads per second that can be supported. (but the actual threads can run in parallel for a second (maxWorkerThreads * CPU logical number) - minFreeThreads results), 1 requires support for concurrency, under the condition of each concurrent requests can be time consuming, it need to set the value of the corresponding concurrency value (so multithreaded processing), but more thread switching is server resources consumption, actual situation not 1 requests are often very time consuming, so the adjustment according to actual situation.

3. maxWorkerThreads is the maximum worker thread. The default is 100

4. minWorkerThreads is the minimum worker thread, because it takes a long time to start the managed thread. According to the experimental results, it starts 18 threads in 40 seconds, which is approximately close to the official saying of 2 threads per second. Because thread overhead is time consuming, it is possible to initialize to the normal minimum number of supported concurrences. For example, if our platform has at least 10 concurrent threads during the day, the minimum thread can be set to 5 (2 CPU), or the server may encounter the request of an instantaneous large amount of concurrency, and the default minimum worker thread can be set to be 1 point larger, so that the request can be processed quickly. minWorkerThreads only affects the incrementing thread and does not affect the amount of concurrency after stabilization.

5, minimum idle thread minFreeThreads parameter configuration, some official data suggest the number of configured to 88 * N (if maxWorkerThreads for 100), because said in order to save enough free thread for system use, but after test, found that under high pressure, lack of the idle thread really idle, useless, so I think we should set the value of 1 point, such as setting up to 80 (maxWorkerThreads 100), will leave 100 * 2-80 = 120 largest connection, can build 120 threads at high pressure, speed and efficiency will be soon.

Note:

1. Logical amount of CPU: according to the physical amount of CPU, if CPU is hyper-threaded (multi-core), it will be multiplied by 2

2, the amount of processing time at the same time does not mean the amount of processing per second, for example, the same time can process 20, may be able to process 200 per second, because each request only 0.1 seconds.

3. Note that the maxWorkerThreads, maxIoThreads, minWorkerThreads and minIoThreads in processModel in the configuration node only have the values of the CPU logical quantity in the configuration node, which will be automatically multiplied by the CPU logical quantity in the calculation.

4. Configuration nodes include:

System.web node:

< processModel autoConfig="false"

maxWorkerThreads = "100"

maxIoThreads = "100"

minWorkerThreads = "20"

minIoThreads = "20"

/ >

< httpRuntime

minFreeThreads="100"

minLocalRequestFreeThreads="100"

/ >

System.web peer nodes

< system.net >

< connectionManagement >

< add address="*" maxconnection="8" / >

< /connectionManagement >

< /system.net >

5. The obtained parameter code:

string result = string.Empty;

int maxWorkThread = 0;

int maxIOThread = 0;

int minWorkThread = 0;

int minIOThread = 0;

int workThread = 0;

int completeThread = 0;

ThreadPool.GetMaxThreads(out maxWorkThread, out maxIOThread);

ThreadPool.GetMinThreads(out minWorkThread, out minIOThread);

ThreadPool.GetAvailableThreads(out workThread, out completeThread);

result = DateTime.Now.ToString () + ":" + "\r\n";

result += "maximum worker thread:" + maxWorkThread + ", maximum IO thread: "+ maxIOThread + "\r\n";

result += "minimum worker thread:" + minWorkThread + ", minimum IO thread: "+ minIOThread + "\r\n";

result += "available worker threads:" + workThread + ", IO threads: "+ completeThread + "\r\n";

result += "\r\n";

(record result, not StringBuilder, temporary)

Transfer: http: / / lawson. cnblogs. com /


Related articles: