ServiceThrottlingBehavior를 사용하여 WCF 서비스 성능 제어

ServiceThrottlingBehavior 클래스는 애플리케이션 수준에서 생성되는 인스턴스 또는 세션의 수를 제한하기 위해 사용할 수 있는 속성을 노출합니다. 이 동작을 사용하여 WCF(Windows Communication Foundation) 애플리케이션의 성능을 세밀하게 조정할 수 있습니다.

서비스 인스턴스 및 동시 호출 제어

MaxConcurrentCalls 클래스를 통해 처리 중인 최대 메시지 수를 지정하려면 ServiceHost 속성을 사용하고, 서비스의 최대 MaxConcurrentInstances 개체 수를 지정하려면 InstanceContext 속성을 사용합니다.

이러한 속성에 대한 설정은 부하에 대해 애플리케이션을 실제로 실행해 본 이후에 결정하기 때문에, ServiceThrottlingBehavior 속성에 대한 설정은 일반적으로 <serviceThrottling> 요소를 사용하여 애플리케이션 구성 파일에서 지정됩니다.

다음 코드 예제에서는 애플리케이션 구성 파일에서 ServiceThrottlingBehavior 클래스를 사용하여 MaxConcurrentSessions, MaxConcurrentCallsMaxConcurrentInstances 속성을 1로 설정하는 간단한 예를 보여 줍니다. 실제 경험을 통해 특정 애플리케이션에 대한 최적의 설정을 결정합니다.

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

정확한 런타임 동작은 ConcurrencyModeInstanceContextMode 속성의 값에 따라 다르며, 이 속성은 각각 작업에서 한 번에 실행 가능한 메시지 수와 수신 채널 세션 수를 기준으로 InstanceContext 서비스의 수명을 제어합니다.

자세한 내용은 MaxConcurrentCallsMaxConcurrentInstances를 참조하세요.

참고 항목