Hy,我有一个WCF测试服务,它什么都不做thread.sleep(10000),我从200个客户端调用它。 问题是响应时间越来越大,超过40秒后10分钟...... 我也厌倦了改变web.config和machine.config。 我们有Windows 2008 r2和IIS 7.5
在我的web.config
中<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="400" maxConcurrentInstances="2000" />
在我的macine.config
中<processModel autoConfig="false" logLevel="None" maxIoThreads="1000" maxWorkerThreads="1000" minIoThreads="100" minWorkerThreads="100" />
在我的Aspnet.config
中<applicationPool maxConcurrentRequestsPerCPU="5000" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000" />
WCF服务:
public interface ISampleService
{
[OperationContractAttribute]
string SampleMethod(string msg);
}
public class SampleService : ISampleService
{
public string SampleMethod(string msg)
{
Thread.Sleep(10000);
return msg;
}
}
答案 0 :(得分:0)
这是我的解决方案:
[ServiceContract(Namespace = "http://microsoft.wcf.documentation")]
public interface ISampleService
{
[OperationContract]
Task<string> SampleMethod(string msg);
}
public class SampleService : ISampleService
{
async Task<string> ISampleService.SampleMethod(string msg)
{
var task = Task.Factory.StartNew((param) =>
{
return "Return from Server : " + msg;
}, TaskContinuationOptions.LongRunning);
await Task.Delay(10000);
return await task.ConfigureAwait(false);
}
}
我只需要改变web.config:
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="1000" maxConcurrentInstances="2000" />