无论我做什么,WCF服务只处理10个并发调用

时间:2013-04-13 14:20:26

标签: wcf concurrency

我意识到已经有很多与此相关的问题,但无论我尝试什么,似乎有一些与我的问题有所不同,使任何其他解决方案无法修复它。

问题在于:我有一个简单的WCF服务。它似乎只允许10个并发呼叫,我需要支持更多。这与我在配置中设置maxConcurrentCalls的内容无关。在这种情况下,为了简化问题,我甚至没有真正的.Net WCF客户端调用它,我只是在几台机器上使用fiddler向服务发出一堆HTTP帖子。它们都是单独工作的,但我看到它们一次只有10个。当#1结束时,#11开始,依此类推。

对于此示例,我的服务是一个简单的“休眠30秒并返回一个字符串”。

下面是我的web.config。您可以看到我已将我的maxConcurrentCalls和我的maxConcurrentSessions提升到超过默认值。这似乎完全没有影响,因为我一次只能看到10个并发请求。

我错过了哪些部分来支持更多的并发请求?

编辑:这是在IIS 7.5中托管的。

的Web.config:     

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

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <security>
        <authentication>
            <anonymousAuthentication enabled="true" />
        </authentication>
    </security>
</system.webServer>
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <serviceThrottling 
                    maxConcurrentCalls="32" 
                    maxConcurrentInstances="2147483647" 
                    maxConcurrentSessions="20"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>

服务:

using System;
using System.ServiceModel;

namespace WCFTestService
{
    using System.Diagnostics;
    using System.Threading;

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
    public class TestService : ITestService
    {

        public string RequestIdentifier { get; set; }

        public int i;

        public string DoWork(string id)
        {
            var secondsBeforeResponding = 20;

            i++;

            this.RequestIdentifier = id;

            Debug.WriteLine("Request: " + id + " Instance:" + i.ToString() + " Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + " Time:" + DateTime.Now.ToString());

            Thread.Sleep(secondsBeforeResponding * 1000);

            Debug.WriteLine("                                                          Done with request: " + this.RequestIdentifier);

            return "Done with request: " + this.RequestIdentifier;
        }
    }
}

ITestService:

[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface ITestService
{
    [OperationContract]
    string DoWork(string requestIdentifier);
}

输出:

Request: b3 Instance:1 Thread:54 Time:4/13/2013 1:50:31 PM <!--- this is the first 10, they all start at pretty much the same time
Request: b4 Instance:1 Thread:47 Time:4/13/2013 1:50:31 PM
Request: b1 Instance:1 Thread:48 Time:4/13/2013 1:50:31 PM
Request: b2 Instance:1 Thread:45 Time:4/13/2013 1:50:31 PM
Request: b5 Instance:1 Thread:44 Time:4/13/2013 1:50:31 PM
Request: b6 Instance:1 Thread:42 Time:4/13/2013 1:50:31 PM
Request: b7 Instance:1 Thread:41 Time:4/13/2013 1:50:32 PM
Request: b8 Instance:1 Thread:39 Time:4/13/2013 1:50:32 PM
Request: b9 Instance:1 Thread:40 Time:4/13/2013 1:50:33 PM
Request: b10 Instance:1 Thread:38 Time:4/13/2013 1:50:34 PM
                                                          Done with request: b3
                                                          Done with request: b4
                                                          Done with request: b1
                                                          Done with request: b2
Request: b11 Instance:1 Thread:35 Time:4/13/2013 1:50:51 PM  <--- this request only starts after the first one finishes
Request: b13 Instance:1 Thread:45 Time:4/13/2013 1:50:51 PM
Request: b14 Instance:1 Thread:54 Time:4/13/2013 1:50:51 PM
Request: b12 Instance:1 Thread:37 Time:4/13/2013 1:50:51 PM
                                                          Done with request: b5
Request: b15 Instance:1 Thread:44 Time:4/13/2013 1:50:51 PM
                                                          Done with request: b6
Request: b16 Instance:1 Thread:42 Time:4/13/2013 1:50:51 PM
                                                          Done with request: b7
Request: b17 Instance:1 Thread:41 Time:4/13/2013 1:50:52 PM
                                                          Done with request: b8
Request: b18 Instance:1 Thread:39 Time:4/13/2013 1:50:52 PM
                                                          Done with request: b9
Request: b19 Instance:1 Thread:40 Time:4/13/2013 1:50:53 PM
                                                          Done with request: b10
Request: b20 Instance:1 Thread:38 Time:4/13/2013 1:50:54 PM
...
...
...

1 个答案:

答案 0 :(得分:5)

您可能会遇到操作系统限制。尝试将服务部署到服务器并从那里重现行为。