Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification on thread pool max threads

I've read here that :

In v2.0, 3.5, and 4.0, ASP.NET initializes the CLR ThreadPool with 100 threads per processor(core)

That is correct , I checked it (I have 8 core machine , so 8*100 = 800):

enter image description here

But then I saw this and this:

maxWorkerThreads — Configures the maximum number of worker threads to use for the process on a per-CPU basis.The range for this attribute is from 5 through 100. The default is 20.

Question

I don't see how the numbers fits in here :

The first paragraph states that I have max 100 threads per core ( the image prove it , I have 8 cores).

But the second paragraph states that the default maximum worker threads per core is 20. So if I have 8 cores then I must have 8*20 = 160 max threads. not 800.

Can someone please shed light?

Update:

I just found a way to get the key element value via c# code :

enter image description here

So now the number are fit in ,but still - MSDN say the default is 20 , not 100

enter image description here

And then they do mention 100 :

enter image description here

What is going on here?

like image 841
Royi Namir Avatar asked Jun 07 '14 18:06

Royi Namir


People also ask

How many threads should a thread pool have?

ThreadPool will create maximum of 10 threads to process 10 requests at a time. After process completion of any single Thread, ThreadPool will internally allocate the 11th request to this Thread and will keep on doing the same to all the remaining requests.

What happens when thread pool is full?

By default, the MaxThreads of the ThreadPool is very high. Usually you'll never get there, your app will crash first. So when all threads are busy the new tasks are queued and slowly, at most 1 per 500 ms, the TP will allocate new threads.

What is the default maximum threads is available in the thread pool to serve incoming ASP NET requests?

The default upper limit of threads that the Thread pool will create by calling ThreadPool. SetMaxThreads ; 1023 in .

What is the maximum number of threads in C#?

32767 in Framework 4.0 (64-bit environment)


1 Answers

I have looked at source code and have found that default value for MaxWorkerThreads is set to 100

private static readonly ConfigurationProperty _propMaxWorkerThreads = new ConfigurationProperty("maxWorkerThreads", typeof (int), (object) 100, (TypeConverter) null, (ConfigurationValidatorBase) new IntegerValidator(1, 2147483646), ConfigurationPropertyOptions.None);

This field is added to properties collection in static constructor

ProcessModelSection._properties.Add(ProcessModelSection._propMaxWorkerThreads);

In property definition they do set default value to 20

[IntegerValidator(MaxValue = 2147483646, MinValue = 1)]
[ConfigurationProperty("maxWorkerThreads", DefaultValue = 20)]
public int MaxWorkerThreads

But this obviously give no effect. Maybe it's some kind of legacy implementation. By the way it behaves this way only if autoConfig is set to false. When it's set to true I have 32K worker threads in my application. Probably this behavior depends on IIS version.

like image 87
Andrii Litvinov Avatar answered Sep 20 '22 21:09

Andrii Litvinov