EF6/Code First:在第一次查询期间超级慢,但仅在调试中 [英] EF6/Code First: Super slow during the 1st query, but only in Debug

查看:28
本文介绍了EF6/Code First:在第一次查询期间超级慢,但仅在调试中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 EF6 rc1 和 Code First 策略,没有预编译视图,问题是:如果我编译并运行 exe 应用程序,运行第一个查询大约需要 15 秒(没关系,因为我仍在处理预生成的视图).但是,如果我使用 Visual Studio 2013 Preview 来调试完全相同的应用程序,则在运行第一个查询之前需要将近 2 分钟:

I'm using EF6 rc1 with Code First strategy, without precompiled views and the problem is: If I compile and run the exe application it takes like 15 seconds to run the first query (that's okay, since I'm still working on the pre-generated views). But if I use Visual Studio 2013 Preview to Debug the exact same application it takes almost 2 minutes BEFORE running the first query:

Dim Context = New MyEntities()
Dim Query = From I in Context.Itens '' <--- The debug takes 2 minutes in here
Dim Item = Query.FirstOrDefault()

有没有办法消除这个额外的时间?我在这里做错了吗?

Is there a way to remove this extra time? Am I doing something wrong here?

Ps.:上下文本身并不复杂,只是充满了 200 多个表.

Ps.: The context itself is not complicated, its just full with 200+ tables.

发现问题在于,在调试期间,EF 似乎正在生成视图而忽略了预先生成的视图.使用 EF 的源代码,我发现该属性:

Found out that the problem is that during debug time the EF appears to be generating the Views ignoring the pre-generated ones. Using the source code from EF I discovered that the property:

IQueryProvider IQueryable.Provider
    {
        get
        {
            return _provider ?? (_provider = new DbQueryProvider(
                                                 GetInternalQueryWithCheck("IQueryable.Provider").InternalContext,
                                                 GetInternalQueryWithCheck("IQueryable.Provider").ObjectQueryProvider));
        }
    }

是消耗时间的地方.但这很奇怪,因为调试只需要时间.我在这里遗漏了什么吗?

is where the time is being consumed. But this is strange since it only takes time in debug. Am I missing something here?

找到与该问题相关的更多信息:使用进程监视器(由 Sysinternals 提供)我发现它的desenv.exe"进程正在消耗大量时间.更具体地说,它消耗线程退出"的时间.它重复线程退出堆栈 36 次.我不知道这个信息是否很有用,但是我在堆栈中保存了一个.cvs",这是他的正文:[...](删除了.cvs"正文,我可以再次发布如果有人真的认为它会很有用,请通过评论,但它令人困惑且太大.)

Found more info related to the question: Using the Process Monitor (by Sysinternals) I found out that there its the 'desenv.exe' process that is consuming tons of time. To be more specific its consuming time with an 'Thread Exit'. It repeats the Thread Exit stack 36 times. I don't know if this info is very useful, but I saved a '.cvs' with the stack, here is his body: [...] (edit: removed the '.cvs' body, I can post it again by the comments if someone really think its going to be useful, but it was confusing and too big.)

安装了 VS2013 Ultimate 和 Entity Framework 6 RTM.安装了 Entity Framework Power Tools Beta 4 并使用它来生成视图.没有任何改变...如果我运行 exe 需要 20 秒,如果我开始"调试需要 120 秒.

Installed VS2013 Ultimate and Entity Framework 6 RTM. Installed the Entity Framework Power Tools Beta 4 and used it to generate the Views. Nothing changed... If I run the exe it takes 20 seconds, if I 'Start' debugging it takes 120 seconds.

创建了一个小项目来模拟错误:http://sdrv.ms/16pH9Vm只需在环境中运行项目,直接通过.exe,点击按钮,比较加载时间.

Created a small project to simulate the error: http://sdrv.ms/16pH9Vm Just run the project inside the environment and directly through the .exe, click the button and compare the loading time.

推荐答案

这是附加调试器时 Lazy(EF 正在使用)中的一个已知性能问题.我们目前正在修复(我们正在研究的当前方法是删除 Lazy 的使用).我们希望尽快在补丁版本中发布此修复程序.您可以在我们的 CodePlex 网站 - http://entityframework.codeplex.com/workitem/1778 上跟踪此问题的进展.

This is a known performance issue in Lazy (which EF is using) when the debugger is attached. We are currently working on a fix (the current approach we are looking at is removing the use of Lazy). We hope to ship this fix in a patch release soon. You can track progress of this issue on our CodePlex site - http://entityframework.codeplex.com/workitem/1778.

关于即将发布的包含修复的 6.0.2 补丁版本的更多详细信息在这里 - http://blogs.msdn.com/b/adonet/archive/2013/10/31/ef6-performance-issues.aspx

More details on the coming 6.0.2 patch release that will include a fix are here - http://blogs.msdn.com/b/adonet/archive/2013/10/31/ef6-performance-issues.aspx

这篇关于EF6/Code First:在第一次查询期间超级慢,但仅在调试中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆