本文介绍了澄清线程池最大线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读和





然后他们确实提到100:





这里发生了什么

解决方案方案

我查看了源代码,发现 MaxWorkerThreads 的默认值设置为100

 私人状态ic只读ConfigurationProperty _propMaxWorkerThreads = new ConfigurationProperty( maxWorkerThreads,typeof(int),(object)100,(TypeConverter)null,(ConfigurationValidatorBase)new IntegerValidator(1,2147483646),ConfigurationPropertyOptions.None); 

此字段已添加到静态构造函数的属性集合中

  ProcessModelSection._properties.Add(ProcessModelSection._propMaxWorkerThreads); 

在属性定义中,他们的确将默认值设置为20

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

但这显然无效。也许这是某种传统的实现方式。顺便说一下,只有在 autoConfig 设置为false时,它的行为方式才如此。设置为true时,我的应用程序中有32K个工作线程。这种行为可能取决于IIS版本。


I've read here that :

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

But then I saw this and this:

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?

解决方案

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.

这篇关于澄清线程池最大线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:45