【问题标题】:WCF Performance on Windows 7Windows 7 上的 WCF 性能
【发布时间】:2009-11-11 23:20:06
【问题描述】:

我在 Windows 7 环境中遇到了一个有趣的 WCF 问题……它太慢了。

该服务是自托管的,在控制台应用程序中运行。

在 Vista 环境中运行的相同代码大约需要 1/3 的时间。

服务器配置:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Logging.Services.LoggerServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceThrottling maxConcurrentCalls="10000" maxConcurrentSessions="1000" maxConcurrentInstances="1000" />
                <serviceDebug includeExceptionDetailInFaults="true" />
                <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <netTcpBinding>
            <binding name="nettcp" maxBufferSize="524288" maxConnections="1000" maxReceivedMessageSize="524288">
                <security mode="None">
                    <transport clientCredentialType="None" protectionLevel="None" />
                    <message clientCredentialType="None" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="Logging.Services.LoggerServiceBehavior" name="Logging.Services.LoggerService">
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="nettcp"
             name="tcp" contract="Logging.Services.Contracts.ILogger" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://localhost:8001/LoggerService" />
                    <add baseAddress="http://localhost:8002/LoggerService" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

客户端配置:

        <netTcpBinding>
            <binding name="tcp" closeTimeout="00:01:00" openTimeout="00:01:00"
             receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
             transferMode="Buffered" transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
             maxBufferSize="524288" maxConnections="10" maxReceivedMessageSize="524288">
                <readerQuotas maxDepth="32" maxStringContentLength="524288" maxArrayLength="16384"
                 maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                 enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>                 
            </binding>              
        </netTcpBinding>

        <endpoint address="net.tcp://localhost:8001/LoggerService" binding="netTcpBinding"
         bindingConfiguration="tcp" contract="LoggerLogService.ILogger"
         name="tcp" />

我在某处读到有类似问题的人在运行 NOD32 时不得不关闭 HTTP 检查,但我没有这样做。没有运气,我完全禁用了 NOD。

有什么想法吗?

提前致谢!

【问题讨论】:

    标签: windows-7 performance


    【解决方案1】:

    查看WCF Performance Counters 以追踪可能发生瓶颈的位置。

    【讨论】:

    • 嗨,迈克,我每秒只接到 2 个呼叫,还有大量未完成的呼叫积压。这是针对“单向”服务调用的。奇怪...
    • 听起来好像有什么东西让它们在上游进一步放慢了速度。
    【解决方案2】:

    来自this post 尝试将以下条目添加到绑定配置中:

    useDefaultWebProxy="false"

    编辑: 由于您使用的是 netTCP,请尝试增加您的 maxConnections 和 maxmessagesize

    【讨论】:

    • 嗨 Russ,useDefaultWebProxy 属性仅适用于基于 HTTP 的绑定。
    • 啊,我想我应该仔细观察
    【解决方案3】:

    服务上设置的并发模式是什么?我不确定如何通过配置文件执行此操作,但在我的 WCF 服务之一上,我将此 ServiceBehaviorAttribute 添加到我的服务类中:

    [ServiceBehavior(
        Namespace="http://blah.com/",
        InstanceContextMode = InstanceContextMode.Single, 
        ConcurrencyMode=ConcurrencyMode.Multiple)]
    public class MyService : IMyServiceInterface
    {
        // ...
    }
    

    如果您的服务已经在并发运行并且速度仍然很慢,则可能是由于服务代码本身存在问题。尽管 Vista 快了 3 倍,但听起来仍然非常慢,具体取决于服务的用途。

    【讨论】:

    • 感谢 Jacob,我的服务也是 Singleton 并且具有 Multiple 的 ConcurrencyMode。我确实发现了我的问题,见上文。
    【解决方案4】:

    嗯...抱歉伙计们,我在工作中将我的存储库指向我的 SQL 服务器...如果我一直注意到 7MB 的错误日志可用,那会有所帮助。我认为睡眠剥夺终于开始了。

    还是谢谢!

    【讨论】:

    • 考虑将您的原始帖子标记为删除,也许。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2010-12-30
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    相关资源
    最近更新 更多