【发布时间】:2011-06-22 12:29:12
【问题描述】:
当我使用以下函数创建上下文时,分析器显示比标准 EF(版本 4)上下文创建方法增加了大约 300 毫秒。还有另一种性能更好的方法吗?它违背了性能分析的目的。
public static Models.MyEntities GetContext()
{
var profiler = MiniProfiler.Current;
var sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString);
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(sqlConn, profiler);
return ObjectContextUtils.CreateObjectContext<Models.MyEntities>(profiledConnection);
}
第一个是使用上面的函数来创建上下文。第二种是使用标准的 EF 上下文创建方法。以下是使用 mvc-mini-profiler 的性能差异:
Profiler EF 上下文:89.1
部分数据库命中:317.9
普通 EF 上下文:0.1
一些数据库命中:7.4
更新 2: 我在 Visual Studio 中进行了一些分析,看起来主要耗时的操作是 MvcMiniProfiler.Helpers.StackTraceSnippet.Get(),其中调用了 System.Diagnostics.StackTrace..ctor(bool)。这需要很长时间才能完成,并且似乎是上述延迟的原因。
【问题讨论】:
-
嗯,(非迷你)分析器应该会告诉你问题出在哪里,对吧?
-
克雷格,我不确定你在说什么。探查器上下文正在减慢速度。我正在尝试确定我在上下文创建功能中是否做错了。
-
如果您认为迷你分析器让事情变慢,请使用真正的分析器(例如 VS 内置的分析器)来诊断问题。
-
正在分析多少个查询?
-
一旦我们弄清楚了......我们会很好stackoverflow.com/questions/6613180/…
标签: entity-framework asp.net-mvc-3 profiling mvc-mini-profiler