Asp. NET thread-related configuration _ practical tips

Source: Internet
Author: User

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

For example 2 CPU default configuration maxworkerthreads=100,minfreethreads=176, the maximum can only have 24 worker threads. (It doesn't matter <system.net>

<connectionManagement>

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

</connectionManagement>

</system.net> the value of this configuration, tested, regardless of the number of maxconnection here, is ultimately calculated from the above calculation formula.

2, maxconnection, this value is the number of threads per second that can be supported. (But the actual number of line Chengwei (maxWorkerThreads * CPU logic) that can be run in parallel per second) is generally required to support concurrent volumes, and each concurrent request is time-consuming You need to set this value for the corresponding concurrency (there are so many threads to deal with), but the thread is more switching is also very consuming server resources, the actual situation is often not necessarily request is time-consuming, so according to the actual situation adjustment.

3, maxWorkerThreads is the largest worker thread, the default 100 I think again is not high concurrent or can

4, minWorkerThreads is the smallest worker thread, because the managed thread startup is time-consuming, according to the experiment results: 40 seconds to start 18 threads, about nearly 2 per second as the official said. Because thread overhead is time-consuming, you can initialize the minimum number of concurrent support concurrency that is normally available. For example, if our platform has at least 10 concurrent days, you can set the minimum thread to 5 (2 CPUs), or the server may encounter an instantaneous, oversized concurrency request, you can set a larger default minimum worker thread to quickly process the request. minWorkerThreads only affects the increment thread and does not affect the amount of concurrency that is stable.

5, the minimum idle thread minfreethreads parameter configuration, and some official information recommended to configure the number of 88*n (if maxWorkerThreads is 100), because said to leave enough free thread to the system, but after testing, found under high pressure, Lack of free line Chengjian free up, it is no use, so I think the value should be set a little bit, for example, set to maxWorkerThreads (100), will leave the 100*2-80=120 maximum connection, under high pressure can be established 120 threads, Speed and efficiency will be quick.

Note the point:

1, the number of CPU logic: According to the number of physical CPUs, if the CPU is Hyper-threading (multi-core) will be multiplied by 2

2, the same amount of processing time can not represent the amount of processing per second, such as the same time can handle 20, may be able to handle 200 per second, because each request only 0.1 seconds.

3, note that the configuration node in the processmodel maxWorkerThreads, Maxiothreads and minWorkerThreads, Miniothreads are only configured a single CPU logical number of values, The calculation is automatically multiplied by the number of CPU logic.

4. Configuration nodes include:

Under system.web node:

<processmodel autoconfig= "false"

maxWorkerThreads = "100"

Maxiothreads = "100"

minWorkerThreads = "20"

Miniothreads = "20"

/>

minfreethreads= "100"

minlocalrequestfreethreads= "100"

/>

System.Web under sibling node

<system.net>

<connectionManagement>

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

</connectionManagement>

</system.net>

5, the use of the Get 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 of Maxworkthread, out maxiothread);

Threadpool.getminthreads (out of Minworkthread, out miniothread);

Threadpool.getavailablethreads (out of Workthread, out completethread);

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

result = "max worker thread: + Maxworkthread +", max IO thread: + maxiothread + "\ r \ n";

result = "min worker thread: + Minworkthread +", min io thread: + miniothread + "\ r \ n";

result = "Available worker threads: + Workthread +", available IO Threads: "+ Completethread + \ r \ n";

result = = "\ r \ n";

(record result, no use of StringBuilder, temporary use)

Reprint: http://lawson.cnblogs.com/

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.