我意识到已经有很多与此相关的问题,但无论我尝试什么,我的问题似乎都有一些不同之处,这使得任何其他解决方案都无法修复它。
问题是:我有一个简单的 WCF 服务。似乎只允许10个并发调用,我需要支持的不止这些。这与我maxConcurrentCalls
在配置中设置的内容无关。在这种情况下,为了简化问题,我什至没有真正的 .Net WCF 客户端调用它,我只是在几台机器上使用 fiddler 向服务发出一堆 HTTP 帖子。他们都单独工作,但我看到他们一次进来 10 个。随着#1 完成,#11 开始,依此类推。
对于这个例子,我的服务是一个简单的“睡眠 30 秒并返回一个字符串”。
下面是我的 web.config。你可以看到我已经把我的maxConcurrentCalls
和我maxConcurrentSessions
的提高到了比默认值更多的程度。这似乎根本没有影响,因为我一次仍然只能看到 10 个并发请求。
为了允许更多并发请求,我错过了哪一部分?
编辑:这是托管在 IIS 7.5 中。
网络配置:
<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;
}
}
}
测试服务:
[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
...
...
...