【问题标题】:WCF Message Security - PerCallWCF 消息安全 - PerCall
【发布时间】:2011-10-16 20:21:07
【问题描述】:

我们有一个跨两台服务器的网站负载平衡,这些服务器调用托管在单个 IIS7 应用程序服务器上的 WCF wsHttp 服务。

上周,该网站启动,但我们遇到了性能问题。

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

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

这种情况持续循环 - 坏消息!

第二天,离岸团队通知我,他们已通过关闭安全性解决了问题。

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

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

任何人都可以就使用的最佳性能计数器提供建议吗?

好的,再过一天,还有更多问题!

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

  1. 没有安全性
  2. 消息安全
  3. 消息安全,但在类上设置了 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

从客户端的 40 循环中,我启动一个新线程并调用该服务。调用服务 1 时,服务在 1 秒内完成所有请求。

调用服务 2 时,服务在 33 秒内完成所有请求。

在调用服务 3 时,我希望它几乎与服务 1 一样快,因为我希望该服务为 4 个调用中的每一个调用实例化一个新的服务对象。但是,似乎没有(我仍然没有任何有意义的性能计数器!)这样做,完成的总时间也是 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 上的消息安全进行多次调用总是会很慢,因为每个会话都必须实例化服务器对象,并且每个客户端只创建一个会话?

非常感谢

罗伯。

【问题讨论】:

    标签: wcf perfmon


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 嗨,我已经在 WCF 配置中启用了计数器。问题是,perfmon 中可用的计数器似乎都没有给我我需要的信息——比如创建的实例数。
    • 在 perfmon 中选择:ServiceModelService 4.0.0.0 -> 实例 -> 。单击确定。现在在“实例”列表中查找您的服务。
    • Rob - 阅读您的更新后:您应该尝试关闭establishSecurityContext="true"。如果您要进行多次调用,这很有价值,但在第一次调用时设置缓存是昂贵的。看到这个问题:stackoverflow.com/questions/1683724/…
    • Ernie,我非常感谢你 - 这正是我需要更改的设置。当然,过去 2 天我一直在盯着它看,但我想我只是在寻找更复杂的东西。
    • 服务现在运行得更好了,但是......在 perfmon 中,我添加了来自服务模型 4 的实例计数器。我注意到它永远不会创建超过 10 个实例,即使它有很多工作要做!我本可以预期这些实例等于 maxconcurrentcalls 但这设置为 30,maxconcurrentinstances 也设置为 30。知道是什么将服务实例限制为最多 10 个吗?
    猜你喜欢
    • 1970-01-01
    • 2014-07-06
    • 2012-01-02
    • 2010-09-12
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2023-03-25
    • 2012-07-15
    相关资源
    最近更新 更多