WCF 并发?

发布于 2025-01-02 23:24:04 字数 2509 浏览 0 评论 0原文

我有一个 WCF 服务部署到 IIS 7 和客户端。我认为该服务被配置为处理并发。当我对两个客户端进行测试时,花费了双倍的时间。我花了几个小时,但还没弄清楚我错过了什么。任何帮助/建议将不胜感激。 Service1.svc.cs 如下所示:

[ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
[CallbackBehavior(UseSynchronizationContext=false)]
public class Service1 : IService1
{        
    public byte[] DownloadFile()
    {
        byte[] byt = File.ReadAllBytes(@"C:\Temp\TestFile.pdf");
        System.Threading.Thread.Sleep(1000);
        return byt;
     }
}

配置:

    <system.net>
    <connectionManagement>
      <add address="*" maxconnection="100"/>
    </connectionManagement>
  </system.net>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <processModel autoConfig="false" maxWorkerThreads="1400" maxIoThreads="1400" minWorkerThreads="2"/>
    <httpRuntime minFreeThreads="1000" minLocalRequestFreeThreads="1000"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Binding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="DocService.Service1">        
        <endpoint address="http://localhost/DocService/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="" name="Service1Binding" bindingName="Service1Binding"
          contract="DocService.IService1" />
        <endpoint address="http://localhost/DocService/mex" binding="mexHttpBinding"
          name="mexpoint" contract="IMetadataExchange" />
      </service>
    </services>    
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceMetadata httpGetEnabled="true"/>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

Transfer TimeLine in Fiddler

I have a WCF service deployed to IIS 7 and the client. I thought the service is configured to handle concurrency. When I tested with two client, it took double the amount of time. I have spent hours and not yet able to figure out where I missed it. Any help/suggestions would be appreciated. Service1.svc.cs looks like this:

[ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
[CallbackBehavior(UseSynchronizationContext=false)]
public class Service1 : IService1
{        
    public byte[] DownloadFile()
    {
        byte[] byt = File.ReadAllBytes(@"C:\Temp\TestFile.pdf");
        System.Threading.Thread.Sleep(1000);
        return byt;
     }
}

Configuration:

    <system.net>
    <connectionManagement>
      <add address="*" maxconnection="100"/>
    </connectionManagement>
  </system.net>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <processModel autoConfig="false" maxWorkerThreads="1400" maxIoThreads="1400" minWorkerThreads="2"/>
    <httpRuntime minFreeThreads="1000" minLocalRequestFreeThreads="1000"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Binding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="DocService.Service1">        
        <endpoint address="http://localhost/DocService/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="" name="Service1Binding" bindingName="Service1Binding"
          contract="DocService.IService1" />
        <endpoint address="http://localhost/DocService/mex" binding="mexHttpBinding"
          name="mexpoint" contract="IMetadataExchange" />
      </service>
    </services>    
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceMetadata httpGetEnabled="true"/>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

Transfer TimeLine in Fiddler

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2025-01-09 23:24:04

这些请求所花费的时间远远超过 1 秒的睡眠时间和 10mb 文件的读取时间。他们应该会在 1.1-2 秒内完成 这里有一些可疑的地方。

注释掉读取并返回一个新的字节[0]。现在需要1.0s吗?现在有并发吗?

编辑:您使用什么客户端?

编辑2:响应您的评论,文件传输不会以某种方式限制并发性。 WCF 并不关心您在服务方法内做了什么。它对文件一无所知。问题是你的磁盘太慢并且序列化 36mb 也可能很慢!你的服务器太慢了!您可以通过用新字节[1024*1024*36]替换IO来查明是否是磁盘或序列化问题。

The requests are taking much longer than 1s sleep time and the read time of, say, 10mb file. They should complete in maybe 1.1-2s There is something fishy here.

Comment out the read and return a new byte[0]. Does it take 1.0s now? Do you have concurrency now?

Edit: What client are you using?

Edit 2: Responding to your comment, the file transfer is not limiting concurrency in some way. WCF does not care what you do inside your service method. It knows nothing about files. The problem is that your disk is too slow and that serializing 36mb is probably slow too! You server is just too slow! You can find out, if the disk or the serializing is the problem by replacing the IO with new byte[1024*1024*36].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文