WCF超过50个并发长时间运行请求

时间:2014-10-13 09:21:41

标签: wcf iis-7.5

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;
    }
}

1 个答案:

答案 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" />