• WCF 附录 高级主题 配置服务配额设置


    微软产品自带一个“默认安全”方案。这也包括了WCF,意味着WCF中的多种配置可以设置来阻止诸如DOS(拒绝服务访问)攻击。微软为很多基于一个单一计算机的开发环境选择这样的设置。这也意味着默认设置中的一部分可能需要在生产环境中更改后才能使用。

      需要更改的默认设置之一是那些由ServiceThrottlingBehavior行为设置的配置。这个行为通过在服务端设置配额限制来限制资源使用数量。这个行为有三个设置: MaxConcurrentCalls, MaxConcurrentInstance 和 MaxConcurrentSessions. 表A.1 列出了ServiceThrottlingBehavior行为属性以及它们的默认值。

    设置 描述 默认值
    MaxConcurrentCalls 限制将要处理的同时调用总数。 16
    MaxConcurrentSessions 限制连接到一个服务的并发会话最大数量。 10
    MaxConcurrentInstances 限制一个服务并发实例的最大数量。 Int32.MaxValue

      MaxConcurrentCalls 和 MaxConcurrentSessions 都有可以在一个生产环境中潜在地限制吞吐量的默认值。如果你的服务需要接受更多吞吐而且你的服务有额外的资源去处理额外的负载的话那么你可以改这些设置。仅需要注意这些设置潜在的影响是可能导致拒绝服务访问攻击。列表A.4 显示了如何通过配置文件改这些设置。

    列表A.4 在配置文件中改ServiceThrottling

      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceThrottlingBehavior">
              <serviceThrottling maxConcurrentCalls="1000" 
                                         maxConcurrentSessions="1000"
                                         maxConcurrentInstances="1000" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

      列表A.5 显示了如何使用代码来更改这些设置。

    列表4.5 使用代码改ServiceThrottling

            public void IncreaseThrottle(ServiceHost serviceHost)
            {
                ServiceThrottlingBehavior throttleBehavior =
                    serviceHost.Description.Behaviors.Find<ServiceThrottlingBehavior>();
                if (throttleBehavior == null)
                {
                    throttleBehavior = new ServiceThrottlingBehavior();
                    serviceHost.Description.Behaviors.Add(throttleBehavior);
                }
                throttleBehavior.MaxConcurrentCalls = 4000;
                throttleBehavior.MaxConcurrentInstances = 4000;
                throttleBehavior.MaxConcurrentSessions = 4000;
            }
    

  • 相关阅读:
    prometheus之五:kube-state-metrics
    prometheus之四:node-exporter
    go语言基础
    EFK+kafka集群实战
    K8S 集群排错指南
    短信倒计时
    微信消息模板
    阿里大鱼
    mui下拉加载
    php无限极分类
  • 原文地址:https://www.cnblogs.com/danielWise/p/2078923.html
Copyright © 2020-2023  润新知