WCF响应时间,限制

时间:2014-02-19 12:41:21

标签: c# wcf soap throttling

我的WCF服务配置:

<system.net>
    <connectionManagement>
      <add address ="*" maxconnection="500"/>
    </connectionManagement>
</system.net>

<bindings>
  <basicHttpBinding>
     <binding name="customBasicHttpBinding" 
         maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
         transferMode="StreamedResponse">
         <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
              maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
              maxNameTableCharCount="2147483647"/>
         <security mode="None"/>
     </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="customWebBinding" maxBufferSize="2147483647" 
        maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
             maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
             maxNameTableCharCount="2147483647"/>
        <security mode="None">
        </security>
    </binding>
  </webHttpBinding>
</bindings>

<serviceBehaviors>
   <behavior name="soapBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <dataContractSerializer maxItemsInObjectGraph="6553600"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <serviceThrottling maxConcurrentCalls="100"
            maxConcurrentInstances="100" maxConcurrentSessions="100" />
   </behavior>
</serviceBehaviors>

<services>
   <service behaviorConfiguration="soapBehavior" name="Service.Service">
      <endpoint name="soap" 
          address="" 
          binding="basicHttpBinding" bindingConfiguration="customBasicHttpBinding"  
          contract="ServiceModel.IService"/>
      <endpoint 
          address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>

如您所见,我设置了throttling参数来处理100个并发实例。

出于测试目的,我在界面上创建了类似于

的虚拟方法
[OperationContract]
string Test(){
    return "test response time";
}

当我尝试调用此方法时,一旦响应时间非常糟糕,它会使用100个并行请求:

  

现在运行100个并行请求...
  响应时间:0,45205P,10,047P,0,43304P,0,86609P,1,33913P,0,91409P,1,34713P,1,75718P,1,37414P,1,80718P,1,80618P,2,22622P,2 ,64426P,2,22822P,2,62626P,2,68127P,3,0453P,3,10731P,3,47635P,3,51035P,3,91039P,3,94039P,3,9544P,4,36844P,4,34943P ,4,78748P,4,37144P,4,82248P,4,79048P,5,25052P,4,81948P,5,67657P,5,25253P,5,71657P,5,67357P,6,13761P,5,70257P,6 ,56566P,6,12361P,7,0117P,6,53065P,7,43674P,6,9517P,7,86679P,7,36974P,7,81778P,8,29483P,8,75988P,8,71587P,8,24182P ,8,70187P,9,16392P,9,12991P,9,19492P,9,57596P,9,65797P,10,08201P,10,45205P,10,52505P,10,48905P,10,9521P,10,89709P,11 ,37714P,11,81118P,11,32413P,11,76418P,11,83918P,12,18222P,12,31723P,12,60526P,12,75128P,13,0423P,13,17132P,13,48935P,13,64836P ,13,91039P,14,07141P,14,32843P,14,48945P,14,78548P,14,91149P,15,20652P,15,33153P,15,62856P,15,75558P,16,0516P,16,19262P,16 ,48265P,16,61866P,16,91169P,17,05471P,17,33773P,17,48375P,17,74677P,17,92079P,18,1 5782P,18,34183P,18,58086P,18,77388P,19,0069P,
  0请求失败。
  平均响应时间:9,20126

为什么结果如此糟糕,我试图更改AppPool工作流程计数但没有运气,任何人都可以告诉我缺少什么,设置限制是什么?

我在Windows Server 2008R2计算机上使用WCF 4.0,IIS7.5。

谢谢

2 个答案:

答案 0 :(得分:1)

如果没有有关服务,配置和环境的详细信息,很难提供有关通信性能问题的大量见解。至少,您可以提供服务绑定,ServiceBehaviorAttribute和有关客户端配置的信息。

从进行WCF性能测试和优化多年来,我们已经看到了您所描述的“类似”问题...尽管有100个并发连接,但该服务似乎没有“有效”响应,即使服务器资源似乎不忙。在我们的例子中,“延迟”与缓慢的“冷”启动以及.NET线程池分配线程所花费的时间相关联。

以下文章讨论了我们的问题:
http://blogs.msdn.com/b/dmetzgar/archive/2011/05/04/wcf-scales-up-slowly-with-bursts-of-work.aspx

祝你好运。

答案 1 :(得分:0)

我刚刚完成了一个大型的,工业规模的WCF项目,该项目使用了限制,并发现限制并不总能产生您期望的结果。我们在生产级虚拟服务器上设置了WCF Web服务,然后我们创建了一个测试工具,在多线程程序上模拟了1000多个虚拟客户端。一旦我们准备好了,我们就会使用一堆不同的限制设置(1 - 1000)来反复运行测试,但对结果感到惊讶。

例如,您认为运行具有200个最大并发连接的Web服务的速度将是100个最大连接数的两倍,但这不是我们为以下内容设置的结果:

-max并发会话

-max并发呼叫

-max并发实例

实际上,MaxConcurrentSessions = 10和MaxConcurrentSessions = 1000之间没有太大的性能(callsProcessed / second)差异。每秒处理的调用大致相同,只有内存使用量不同。与其他油门设置相同。

我们发现限制的最快设置?根本没有设置;基本上,让System.ServiceModel库处理所有事情。这是我们经过几天测试后发现的最快速度。

就你的表现而言,我要做的是试着找出瓶颈的位置。例如,如果您的WCF服务使用SQL来检索数据,请尝试删除SQL并返回静态数据集,看看您的时间是否显着改善。如果是这样,那么也许你需要在数据库方面工作。如果没有,可能是处理SOAP消息时出现问题。

相关问题