ASP. NET thread Configuration

Source: Internet
Author: User
Tags net thread

1. (maxWorkerThreads * Number of CPU logic)-minFreeThreads

For example, if two CPUs are configured with maxWorkerThreads = 100 by default and minFreeThreads = 176, a maximum of 24 working threads can be created at the same time. (<System.net>

<ConnectionManagement>

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

</ConnectionManagement>

</System.net> the value of this configuration is tested. No matter how many maxconnections there are, it is calculated from the above formula)

 

2. maxconnection. This value is the number of threads per second. (But the actual number of threads that can run concurrently per second is (maxWorkerThreads * Number of CPU logic)-result of minFreeThreads). Generally, concurrent requests are required. When every concurrent request is time-consuming, you need to set this value to the corresponding concurrency (with such multi-thread processing), But switching when there are more threads also consumes server resources, the actual situation is often not necessarily time-consuming, therefore, it is adjusted according to the actual situation.

 

3. maxWorkerThreads is the maximum working thread. The default value is 100.

 

4. minWorkerThreads is the minimum working thread. Because it takes a lot of time to start the hosting thread, according to the experiment results: 18 threads are started in 40 seconds, which is close to nearly 2 threads per second officially mentioned. Because the thread overhead is time-consuming, the minimum number of concurrent threads can be initialized to normal conditions. For example, if the platform has at least 10 concurrent threads during the day, you can set the minimum thread to 5 (2 CPUs), or the server may encounter extremely large concurrent requests in an instant, you can set the default minimum working thread to be a little larger to quickly process requests. MinWorkerThreads only affects incremental threads, but does not affect the number of concurrent threads after stability.

 

5. For the configuration of the minFreeThreads parameter of the minimum idle thread, it is recommended to set the number of 88 * N in some official documents (if maxWorkerThreads is 100 ), it is said that in order to leave enough Idle threads for the system to use, but after testing, it is found that, under high pressure, the lack of Idle threads is really idle, it is useless, therefore, I think this value should be set to a smaller value. For example, if it is set to 80 (when maxWorkerThreads is set to 100), 100*2-80 = 120 maximum connections will be left, 120 threads can be created under high pressure, and the speed and efficiency will be fast.

 

 

Note:

1. Number of CPU logic: the number of physical CPUs. If the CPU is hyper-threading (multi-core), it is multiplied by 2.

2. processing at the same time does not mean processing per second. For example, 20 requests can be processed at the same time, and 200 requests can be processed per second, because each request takes only 0.1 seconds.

3. Pay attention to configuring maxWorkerThreads, maxIoThreads, minWorkerThreads, and minIoThreads in the processModel on the node to only specify the number of single-CPU logic values. During calculation, the number of CPU logic values is automatically multiplied.

4. Configuration nodes include:

Under the System. web node:

<ProcessModel autoConfig = "false"

Maxworker threads = "100"

MaxIoThreads = "100"

MinWorkerThreads = "20"

MinIoThreads = "20"

/>

<HttpRuntime

MinFreeThreads = "100"

MinLocalRequestFreeThreads = "100"

/>

Under System. web nodes at the same level

<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 working thread:" + maxWorkThread + ", maximum IO thread:" + maxIOThread + "\ r \ n ";

Result + = "minimum working thread:" + minWorkThread + ", minimum IO thread:" + minIOThread + "\ r \ n ";

Result + = "available working threads:" + workThread + ", available IO threads:" + completeThread + "\ r \ n ";

Result + = "\ r \ n ";

(Record the result. StringBuilder is not used for temporary use)

Reproduced: http://lawson.cnblogs.com/

Related Article

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.