繁体   English   中英

如何获取/设置WCF并行处理请求所使用的线程数?

[英]How to get/set the number of threads WCF uses to handle requests in parallel?

如何获取并设置WCF服务器线程池中允许并行处理传入请求的线程数?

我正在使用WebHttpBinding。

您可以通过ServiceThrottlingBehavior类获取它们,默认值如下

.NET 3.0 / 3.5

  • MaxConcurrentSessions:10
  • MaxConcurrentCalls:16
  • MaxConcurrentInstances:26

.NET 4.0以上

  • MaxConcurrentSessions:100 * ProcessorCount
  • MaxConcurrentCalls:16 * ProcessorCount
  • MaxConcurrentInstances:MaxConcurrentSessions + MaxConcurrentCalls

您最感兴趣的是MaxConcurrentInstances ,因为这会消耗线程。 通常,如果您在哪里配置它,可以在app.config文件中进行设置

<configuration>
  <appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddress" value="http://localhost:8080/ServiceMetadata" />
  </appSettings>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="Throttled" >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService"/>
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
         />
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange"
         />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior  name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="1" 
            maxConcurrentSessions="1" 
            maxConcurrentInstances="1"
          />
          <serviceMetadata 
            httpGetEnabled="true" 
            httpGetUrl=""
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

通过代码查找要困难得多(我不知道怎么做,我通常只使用配置文件)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM