WCF消息安全 - PerCall

时间:2011-10-16 20:21:07

标签: wcf perfmon

我们在两个服务器之间进行负载均衡,调用托管在单个IIS7应用服务器上的WCF wsHttp服务。

上周,该网站推出,我们遇到了性能问题。

该系统是由一支离岸团队建造的,但我被要求调查是否可以提供帮助。

我加载了perfmon并使用asp.net计数器查看当前会话。我可以看到,一旦这个增加到大约25以上,那么网站的速度会大大减慢。在接下来的10分钟内,它会继续增加到大约250,然后会降到0,并且网站的性能会很好。

这在一个循环中持续 - 坏消息!

第二天,离岸团队告诉我他们已经通过调整安全问题来解决问题。

我有一个理论认为,在禁用wsHttp绑定WCF的安全性时,从每个会话创建一个实例变为每个调用创建一个实例 - 从而允许更大的服务请求吞吐量。这是一个很好的理论吗?

我构建了一个简单的模型来测试它,IIS中托管的几个方法和生成多个请求的简单客户端。这似乎给出了我预期的结果。问题是,当我没有使用安全绑定时,我很难找到正确的perfmon计数器来证明排队的请求更少,创建的并发实例更多。

有人可以建议使用最好的perfmon计数器吗?

好的,关于这一天的另一天还有更多问题!

在我的测试应用程序中,我现在有3个服务类,包含3个不同的wsHttp绑定

  1. 没有安全保障
  2. 邮件安全
  3. 消息安全性,但在类上设置了[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  4. 在客户端的40循环内,我启动一个新线程并调用该服务。当呼叫服务1时,服务在1秒内完成所有请求。

    当呼叫服务2时,该服务在33秒内完成所有请求。

    当调用服务3时,我希望它几乎和服务1一样快,因为我希望服务为4个调用中的每个调用实例化一个新的服务对象。但是,它似乎没有(我仍然没有任何有意义的perfmon计数器!)这样做,总完成时间也是33秒。

    以下是服务的配置:

    <?xml version="1.0"?>
    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
              <add name="traceListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData="c:\WCFTrace\InstancingDemo.svclog" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SecPerCallBehaviour">
              <serviceThrottling maxConcurrentSessions="1000"
                                  maxConcurrentCalls="30"
                                  maxConcurrentInstances="30"/>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <bindings>
          <wsHttpBinding>
            <binding name="BindingNoSec">
              <security mode="None" />
            </binding>
            <binding name="BindingMessageSec">
              <security mode="Message">
                <message establishSecurityContext ="true"/>
              </security>
            </binding>
            <binding name="BindingMessageSecPerCall" >
              <security mode="Message">
                <message establishSecurityContext ="true"/>
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <services>
          <service name="ServiceInstancingDemo.Service1">
            <endpoint address="~/Service1.svc"
              binding="wsHttpBinding" bindingConfiguration="BindingNoSec"
              name="NoSecurity" contract="ServiceInstancingDemo.IService1" />
          </service>
          <service name="ServiceInstancingDemo.Service2">
            <endpoint address="~/Service2.svc"
              binding="wsHttpBinding" bindingConfiguration="BindingMessageSec"
              contract="ServiceInstancingDemo.IService2" />
          </service>
          <service name="ServiceInstancingDemo.Service3" behaviorConfiguration="SecPerCallBehaviour">
            <endpoint address="~/Service3.svc"
              binding="wsHttpBinding" bindingConfiguration="BindingMessageSecPerCall"
              contract="ServiceInstancingDemo.IService3" />
          </service>
        </services>
      </system.serviceModel>
    </configuration>
    

    这是来自客户端的配置:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IService2" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                        allowCookies="false">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="Message">
                            <transport clientCredentialType="Windows" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                                algorithmSuite="Default" establishSecurityContext="true" />
                        </security>
                    </binding>
                    <binding name="NoSecurity" closeTimeout="00:01:00" openTimeout="00:01:00"
                        receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                        transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                        allowCookies="false">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="None">
                            <transport clientCredentialType="Windows" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                        </security>
                    </binding>
                    <binding name="WSHttpBinding_IService3" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                        allowCookies="false">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="Message">
                            <transport clientCredentialType="Windows" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                                algorithmSuite="Default" />
                        </security>
                    </binding>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://rb-t510/NGCInstancing/Service2.svc/~/Service2.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService2"
                    contract="NGCWithSec.IService2" name="WSHttpBinding_IService2">
                    <identity>
                        <servicePrincipalName value="host/RB-T510" />
                    </identity>
                </endpoint>
                <endpoint address="http://rb-t510/NGCInstancing/Service1.svc/~/Service1.svc"
                    binding="wsHttpBinding" bindingConfiguration="NoSecurity"
                    contract="NGC.IService1" name="NoSecurity" />
                <endpoint address="http://localhost/NGCInstancing/Service3.svc/~/Service3.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService3"
                    contract="NGCSecPerCall.IService3" name="WSHttpBinding_IService3">
                    <identity>
                        <servicePrincipalName value="host/RB-T510" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>
    

    我猜我错过了配置设置?或者,使用wsHttp上的消息安全性进行的多次调用总是会非常慢,因为每个会话必须实例化服务器对象,并且每个客户端只创建一个会话?

    非常感谢

    罗布。

1 个答案:

答案 0 :(得分:1)

您需要的计数器必须在您的服务中明确启用:

<configuration>
    <system.serviceModel>
        <diagnostics performanceCounters="All" />
    </system.serviceModel>
</configuration>

显然它也可以更精细。这是您想要阅读的内容:WCF Performance Counters

<强>更新: 更好的链接:How to use performance counters to diagnose performance of WCF applications