C# WCF限制默认值中的ProcessorCount:Environment.ProcessorCount或处理器计数?

C# WCF限制默认值中的ProcessorCount:Environment.ProcessorCount或处理器计数?,c#,wcf,throttling,C#,Wcf,Throttling,我使用.NET4.0开发了WCF服务 在行为中,我有以下限制元素: <behavior name="Test"> <serviceThrottling maxConcurrentInstances="1000"/> </behavior> 结果是: MaxConcurrentCalls 16 MaxConcurrentSessions 100 现在我有点困惑了,什么是默认值? 可能是这张支票不对吗? 提前感谢。根据.NET 4.7.1的源代码,您看到的

我使用.NET4.0开发了WCF服务 在行为中,我有以下限制元素:

<behavior name="Test">
  <serviceThrottling maxConcurrentInstances="1000"/>
</behavior>
结果是:

MaxConcurrentCalls 16 MaxConcurrentSessions 100
现在我有点困惑了,什么是默认值? 可能是这张支票不对吗?
提前感谢。

根据.NET 4.7.1的源代码,您看到的值是正确的。这是因为您正在从配置中读取配置属性,而不是在
servicetrottle
实例中设置的属性

如果查看的代码,您将看到以下属性:

[ConfigurationProperty(ConfigurationStrings.MaxConcurrentCalls, DefaultValue = ServiceThrottle.DefaultMaxConcurrentCalls)]
[IntegerValidator(MinValue = 1)]
public int MaxConcurrentCalls
{
    get { return (int)base[ConfigurationStrings.MaxConcurrentCalls]; }
    set { base[ConfigurationStrings.MaxConcurrentCalls] = value; }
}

[ConfigurationProperty(ConfigurationStrings.MaxConcurrentSessions, DefaultValue = ServiceThrottle.DefaultMaxConcurrentSessions)]
[IntegerValidator(MinValue = 1)]
public int MaxConcurrentSessions
{
    get { return (int)base[ConfigurationStrings.MaxConcurrentSessions]; }
    set { base[ConfigurationStrings.MaxConcurrentSessions] = value; }
}
请注意,
MaxConcurrentCalls
的默认值设置为
ServiceThrottle。DefaultMaxConcurrentCalls
MaxConcurrentSession
设置为
ServiceThrottle。DefaultMaxConcurrentSessions

这些值在中定义为:

由于配置文件中没有设置任何值,因此您将收到默认值16和100

但是,如果查看
servicetrottle
的构造函数,您会看到:

internal ServiceThrottle(ServiceHostBase host)
{
    if (!((host != null)))
    {
        Fx.Assert("ServiceThrottle.ServiceThrottle: (host != null)");
        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("host");
    }
    this.host = host;
    this.MaxConcurrentCalls = ServiceThrottle.DefaultMaxConcurrentCallsCpuCount;
    this.MaxConcurrentSessions = ServiceThrottle.DefaultMaxConcurrentSessionsCpuCount;
    this.isActive = true;
}
DefaultMaxConcurrentCallsCpuCount
DefaultMaxConcurrentSessionsCpuCount
定义如下:

internal static int DefaultMaxConcurrentCallsCpuCount = DefaultMaxConcurrentCalls * OSEnvironmentHelper.ProcessorCount;
internal static int DefaultMaxConcurrentSessionsCpuCount = DefaultMaxConcurrentSessions * OSEnvironmentHelper.ProcessorCount;
因此,创建新实例时,默认值实际上是100*处理器计数和16*处理器计数

internal ServiceThrottle(ServiceHostBase host)
{
    if (!((host != null)))
    {
        Fx.Assert("ServiceThrottle.ServiceThrottle: (host != null)");
        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("host");
    }
    this.host = host;
    this.MaxConcurrentCalls = ServiceThrottle.DefaultMaxConcurrentCallsCpuCount;
    this.MaxConcurrentSessions = ServiceThrottle.DefaultMaxConcurrentSessionsCpuCount;
    this.isActive = true;
}
internal static int DefaultMaxConcurrentCallsCpuCount = DefaultMaxConcurrentCalls * OSEnvironmentHelper.ProcessorCount;
internal static int DefaultMaxConcurrentSessionsCpuCount = DefaultMaxConcurrentSessions * OSEnvironmentHelper.ProcessorCount;