使用MS Sync Framework和IIS托管WCF服务将表与2mb条目同步需要10分钟

时间:2011-12-08 14:41:42

标签: c# sql wcf microsoft-sync-framework

我在一台服务器上运行IIS托管的WCF服务,在另一台服务器上运行Windows服务。 Windows服务充当从属服务器,并通过使用MS Sync Framework连接到IIS托管的WCF服务来同步每个服务器上的数据库。

我将文件内容存储在其中一个正在同步的表中,并且条目可能会变得有点大(每个条目大约10mb)。我的问题是,当我尝试同步这些条目时,需要很长时间才能同步。

正在同步的表:

[Id] [int] IDENTITY(1,1) NOT NULL,
[Client] [uniqueidentifier] NOT NULL,
[Date] [datetime] NOT NULL,
[Content] [nvarchar](max) NOT NULL,

我将与1个具有不同内容大小的条目同步到以下内容;

  • 500kb - 1min 20sec
  • 1mb - 3min
  • 1,5mb - 6min 30sec
  • 2mb - 9min 50sec

(在Visual Studio中使用本地服务和两个数据库进行调试时的时序大致相同)

有没有人解释为什么这么长时间?

WCF服务配置:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="2147483647" />
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Windows服务配置:

<configuration>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISyncServiceContract" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
             allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <client>
      <endpoint address="http://localhost:60000/SyncService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISyncServiceContract" contract="SyncServiceReference.ISyncServiceContract" name="BasicHttpBinding_ISyncServiceContract"/>
    </client>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

</configuration>

2 个答案:

答案 0 :(得分:1)

当它包含太多数据时,问题似乎是nvarchar(max)字段。我将字段更改为varbinary(max),现在相同数据的同步已经过去了一段时间。

答案 1 :(得分:0)

如果您正在使用客户端/服务器库,则通信最终基本上是一个序列化为XML的数据集(从技术上讲,它不是“序列化”,但最终大致相似)。因此,您要从具有臃肿声誉的数据集开始。此外,数据集将存储每个更改行的数据之前和之后 - 将数据量加倍。然后将序列化添加到XML,这会增加更多开销。然后,该有效负载包含在Web服务调用中 - 这会增加一些开销。总而言之,您正在考虑通过网络传输大量数据。您看到的时间间隔就是传输所有数据所花费的时间。

这超出了您的问题,但解决此问题的一些建议是:

  • 查看在数据传输过程中压缩数据。那里有一些wcf + gzip项目。
  • 您可能需要考虑将文件从数据库中移出到文件系统中,并使用单独的WCF服务来处理传输文件。
相关问题