【问题标题】:Very bad performance using WSFederationHttpBinding使用 WSFederationHttpBinding 的性能非常差
【发布时间】:2012-06-28 14:41:21
【问题描述】:

我使用 WSFederationHttpBinding 的性能很差 - iis 每秒只处理 250 个请求。

绑定:

public class CustomFactoryActive : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ServiceHost host = new ServiceHost(serviceType, baseAddresses);
            CommonConf.ConfigureServiceHost(host);


            string issuerAddress = ConfigManager.ActiveSTS;
            string issuerMexAddress = issuerAddress + "/mex";

            WSFederationHttpBinding wsFedBinding = new WSFederationHttpBinding();
            wsFedBinding.Security.Mode = WSFederationHttpSecurityMode.Message;
            wsFedBinding.ReliableSession.Enabled = false;

            wsFedBinding.MaxReceivedMessageSize = wsFedBinding.MaxBufferPoolSize = Constants.MaxFileSize;

            XmlDictionaryReaderQuotas quotas = wsFedBinding.ReaderQuotas;
            quotas.MaxArrayLength = quotas.MaxBytesPerRead = quotas.MaxStringContentLength =
                quotas.MaxNameTableCharCount = quotas.MaxDepth = (int)Constants.MaxFileSize;

            var messageSecurity = wsFedBinding.Security.Message;

            messageSecurity.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
            messageSecurity.IssuedKeyType = SecurityKeyType.SymmetricKey;
            messageSecurity.EstablishSecurityContext = false;
            messageSecurity.NegotiateServiceCredential = false;

            messageSecurity.IssuerAddress = new EndpointAddress(new Uri(issuerAddress));
            messageSecurity.IssuerMetadataAddress = new EndpointAddress(new Uri(issuerMexAddress));


            WS2007HttpBinding ws2007HttpBinding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential);
            var wsHttpSecurity = ws2007HttpBinding.Security;
            wsHttpSecurity.Message.ClientCredentialType = MessageCredentialType.UserName;//авторизация по логину и паролю
            wsHttpSecurity.Message.NegotiateServiceCredential = true;
            wsHttpSecurity.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;

            messageSecurity.IssuerBinding = ws2007HttpBinding;

            ContractDescription contractDescription = ContractDescription.GetContract(typeof(ISignService));

            EndpointAddress endpointAddress = new EndpointAddress(baseAddresses[0]);
            ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription, wsFedBinding, endpointAddress);
            host.Description.Endpoints.Add(endpoint);

            return host;
        }
    }

我的 wcf 测试方法什么都不做 - 它只返回 1 个字节。

但是当我在没有任何 WIF saml 令牌的情况下使用具有消息安全性的简单 WSHttpBinding 时,我得到了大约。每秒 4000 个请求

我不明白为什么

【问题讨论】:

    标签: c# wcf wif ws-federation


    【解决方案1】:

    您应该设置和配置 WCF 跟踪以查看在 WCF 架构中花费的时间的概要,请参阅http://msdn.microsoft.com/en-us/library/ms733025.aspx 了解更多详细信息。

    当您启用跟踪并查看请求时,您可能看到(在单个调用者多次调用同一服务的测试环境中)STS 仅被调用一次并且随后的调用包含一个缓存的令牌。但是,所有调用仍将建立安全连接,从而为每次调用验证令牌(这将花费一些 CPU 时间)。或者,您可以/可以通过方法级别分析服务主机来验证所有这些,这将更清楚地显示时间究竟花在了哪里。

    【讨论】:

      【解决方案2】:

      模拟安全令牌(不要使用实际的 STS),看看你的表现如何。我认为那部分是你的瓶颈。

      【讨论】:

      • STS 仅请求一次令牌(由 iis 日志证明),因此 STS 不是瓶颈
      【解决方案3】:

      我看到NegotiateServiceCredential = true在打开频道时添加了多个网络往返的案例。尝试将wsHttpSecurity.Message.NegotiateServiceCredential 更改为false 并在客户端指定服务证书。

      【讨论】:

        【解决方案4】:

        证书的验证也可能需要很长时间。您可以尝试更改客户端的行为,从而跳过证书验证和吊销。

        //Client
        var clientCredentialsBehavoir = behaviors.Find<FederatedClientCredentials>();
        clientCredentialsBehavoir.ServiceCertificate.Authentication.CertificateValidationMode =                     X509CertificateValidationMode.None;
        clientCredentialsBehavoir.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
        
        //The same can be done on the server
        var serviceConfiguration = new ServiceConfiguration();
        serviceConfiguration.CertificateValidationMode =   X509CertificateValidationMode.None;
        

        这不应该在生产环境中完成!

        您也可以通过 appconfig 执行此操作。

        【讨论】:

          【解决方案5】:

          SAML 令牌已加密 - 如何加密取决于您的配置。在您的情况下,您似乎使用的是SecurityAlgorithmSuite.Default,我认为是AES256

          任何时候发生解密/加密,CPU 都需要时间来进行数字运算。所花费的时间/精力取决于多种因素,但我认为您看到的请求处理能力的差异并不完全是

          正如其他响应所提到的,即使令牌被缓存,令牌仍然必须经过验证和解密,其中每个都涉及通过一种或多种算法运行令牌的内容。

          我的建议:使用不同的SecurityAlgorithmSuite 常量执行一些分析,然后比较结果。

          可以将SecurityAlgorithmSuite.Basic128.Basic256 进行比较。 256 常量相当于默认选项。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2010-11-18
            • 1970-01-01
            • 1970-01-01
            • 2023-03-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多