嗨,我有一个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;
}
}
这是我的解决方案:
[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" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句