Clarification on thread pool max threads

大憨熊 提交于 2019-12-03 05:02:55

问题


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):

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 :

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

And then they do mention 100 :

What is going on here?


回答1:


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.




回答2:


According to the MSDN,

the default maximum [number of threads in the ASP.net server pool] for .NET 4.5 is 5,000

Source



来源:https://stackoverflow.com/questions/24100277/clarification-on-thread-pool-max-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!