我在win 8 2008服务器(4核心)和Devart for oracle 11g上使用部署在IIS 8中的WCF 4。 Multiples应用程序(70个客户端)每10秒调用一次操作(getStatusData),该操作应该返回一小部分结果(1 kb)。这是一个通过轮询来保持客户端更新的预定呼叫...
在服务器端的服务应用程序日志中,我可以看到有时服务器需要花费超过30秒的时间来回答(因为它在响应中间被阻止了......)
我所做的一项改变:
initialy我正在使用实体框架的每个请求模式:我使用相同的上下文进行调用。
现在由于一些内存泄漏我每个线程使用一个上下文。
在这个wcf调用期间,我正在查询,更新特定的表:我怀疑为了在这个表上查询或更新我的所有调用都被阻止了......但是我不确定... 你对这里发生的事情有任何想法吗?
添加了完整的理解
这是我的应用程序正在做的事情:
//Here what my service method look like :
ResultStatus GetSetInfo(Guid clientId)
{
var info = Repo.GetInfo(clientId);
info.LastPoll = DateTime.Now;
Repo.SetInfo(clientId,info);
return info;
}
//Here my repository Repo :
public class Repo
{
ObjectContext GetContext()
{
//Return ObjectContext by threadId (stored in a concurrentDictionnary)
return ArrContexteByThread[Thread.CurrentThread.ManagedThreadId];
}
InformationStatus GetResult(Guid clientId)
{
var contexte = GetContext();
IQueryable<InformationStatus> query = (contexte.InformationStatus.Where(cli=> (cli.ClientId == clientId)));
var objectQuery = (ObjectQuery) query;
objectQuery.MergeOption = MergeOption.OverwriteChanges;
var infoStatus = query.FirstOrDefault();
return infoStatus ;
}
public ResultStatus GetInfo(Guid clientId)
{
var info = GetResult(clientId);
if(info == null)
return new ResultStatus (clientId);
return GetResultFromInfosStatus(info);
}
public void SetInfo(Guid clientId, ResultStatus status)
{
var contexte = GetContext();
var info = GetResult(clientId);
if(info == null) {
info = new ResultStatus (clientId);
contexte.AddToResultStatus(info);
contexte.SaveChanges();
return;
}
ResultStatus status = GetResultFromInfosStatus(info);
var key = status.EntityKey;
object infoKey;
if (contexte.TryGetObjectByKey(key, out infoKey))
contexte.ApplyCurrentValues(key.EntitySetName, status);
contexte.SaveChanges();
}
}