简体   繁体   English

WCF并行和异步调用?

[英]Wcf parallel and async call?

I have a wcf service (parser service, byte[]=>string) 我有一个wcf服务(解析器服务,byte [] => string)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]

hosted on iis (nettcpbinding) On my client side i have one million+ byte[] like this List(1000000) and i should call wcf service's method as parallel for parsing this list. 托管在iis(nettcpbinding)上在我的客户端上,我有100万个字节[],如此List(1000000),我应该将wcf服务的方法作为并行方法来解析此列表。

I used like this but i have a bottleneck (wcf service not response to me) after the 500000-700000 message parsing. 我曾经这样使用,但是在解析500000-700000消息后出现了瓶颈(wcf服务未响应我)。 Where i do make wrong implemantation? 我在哪里犯错呢? Does it solve my problem if i implement this http://blogs.msdn.com/b/rjacobs/archive/2011/06/30/how-to-implement-a-wcf-asynchronous-service-operation-with-task-lt-t-gt.aspx method (client side in Parallel.Foreach same below line ) 如果我实施此http://blogs.msdn.com/b/rjacobs/archive/2011/06/30/how-to-implement-a-wcf-asynchronous-service-operation-with-task,是否可以解决我的问题? -lt-t-gt.aspx方法(Parallel.Foreach中的客户端在行下方相同)

Service1 client =new Service1();
Parallel.Foeach(list,byteArray=>{
  var result = client.Parse(byteArray);
  string keyHash = string.combine(byteArray[0],byteArray[1],byteArray[3])
  WriteDiffFile(keyHash,result); // maybe call in different task 
  WriteSameFile(result); // need lock for write to same file
});

my wcf host configuration: 我的wcf主机配置:

<system.serviceModel>
    <diagnostics etwProviderId="9a712944-02ea-425a-bbd3-567a943b85df">
      <endToEndTracing propagateActivity="false" messageFlowTracing="false" />
    </diagnostics>
    <services>
      <service name="Pln3G.Services.EventParserService" behaviorConfiguration="Pln3G.WebServices.EventParserServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8001/pln3g/EventParserService/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcp_Unsecured" contract="Pln3G.Domain.Contracts.Service.IEventParserService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="tcp_Unsecured" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2147483647" maxReceivedMessageSize="2147483647" portSharingEnabled="false" transactionFlow="false" listenBacklog="2147483647" closeTimeout="00:01:00" openTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:10:00">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="Pln3G.WebServices.EventParserServiceBehavior">
          <etwTracking profileName="ErrorsOnly Tracking Profile" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!--1. MaxConcurrentSessions: default is 100 * ProcessorCount
                2. MaxConcurrentCalls: default is 16 * ProcessorCount
                3. MaxConcurrentInstances: default is the total of MaxConcurrentSessions and MaxConcurrentCalls -->
          <serviceThrottling maxConcurrentCalls="32" maxConcurrentSessions="200" maxConcurrentInstances="232" />
          <serviceMetadata httpGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
        <behavior name="">
          <etwTracking profileName="HealthMonitoring Tracking Profile" />
          <serviceThrottling maxConcurrentCalls="32" maxConcurrentSessions="200" maxConcurrentInstances="232" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

my wcf client configuration: 我的wcf客户端配置:

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IEventParserService" closeTimeout="00:01:00" openTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <!--<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />-->
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://192.168.1.66:8001/pln3g/EventParserService.svc" behaviorConfiguration="ServiceViewEventBehavior"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IEventParserService"
          contract="EventParserServiceReference.IEventParserService" name="NetTcpBinding_IEventParserService" />
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceViewEventBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

I suggest that you use PerCall InstanceContextMode, in this mode, it creates different instance for different calls, and they are invoked in different threads; 我建议您使用PerCall InstanceContextMode,在这种模式下,它将为不同的调用创建不同的实例,并在不同的线程中调用它们。 if you use PerSession, it creates only one instance for you session, according to your client side code, it creates only instance and serves your requests. 如果您使用PerSession,它将为您的会话仅创建一个实例,根据您的客户端代码,它将仅创建一个实例并处理您的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM